diff --git a/actions/payment.ts b/actions/payment.ts index 6098869..9b0eef9 100644 --- a/actions/payment.ts +++ b/actions/payment.ts @@ -164,24 +164,16 @@ export async function getTopup({ id }: { id: string }) { export async function cancelTopup({ id }: { id: string }) { const session = await getServerSession(authOptions); const response = await fetch( - `${process.env.SARLINK_API_BASE_URL}/api/billing/topup/${id}/delete/`, + `${process.env.SARLINK_API_BASE_URL}/api/billing/topup/${id}/cancel/`, { - method: "DELETE", + method: "PATCH", headers: { "Content-Type": "application/json", Authorization: `Token ${session?.apiToken}`, }, }, ); - if (!response.ok) { - const errorData = (await response.json()) as ApiError; - const errorMessage = - errorData.message || errorData.detail || "An error occurred."; - const error = new Error(errorMessage); - (error as ApiError & { details?: ApiError }).details = errorData; // Attach the errorData to the error object - throw error; - } - return { message: "Topup successfully canceled." }; + return handleApiResponse(response, "cancelTopup"); } export async function cancelPayment({ id }: { id: string }) { diff --git a/components/billing/cancel-topup-button.tsx b/components/billing/cancel-topup-button.tsx index a6ca438..21f71b2 100644 --- a/components/billing/cancel-topup-button.tsx +++ b/components/billing/cancel-topup-button.tsx @@ -17,13 +17,15 @@ export default function CancelTopupButton({ - - {topup.paid ? "Paid" : "Unpaid"} - + {topup.status !== "CANCELLED" && ( + + {topup.paid ? "Paid" : "Unpaid"} + + )}