From e9847058493f4f1c3e3db20000b28c6b791c9173 Mon Sep 17 00:00:00 2001 From: i701 Date: Sun, 6 Jul 2025 22:38:55 +0500 Subject: [PATCH] =?UTF-8?q?refactor:=20update=20cancelPayment=20function?= =?UTF-8?q?=20to=20use=20PATCH=20method=20and=20new=20endpoint=20?= =?UTF-8?q?=F0=9F=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- actions/payment.ts | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/actions/payment.ts b/actions/payment.ts index 9b0eef9..82f97df 100644 --- a/actions/payment.ts +++ b/actions/payment.ts @@ -179,24 +179,16 @@ export async function cancelTopup({ id }: { id: string }) { export async function cancelPayment({ id }: { id: string }) { const session = await getServerSession(authOptions); const response = await fetch( - `${process.env.SARLINK_API_BASE_URL}/api/billing/payment/${id}/delete/`, + `${process.env.SARLINK_API_BASE_URL}/api/billing/payment/${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: "Payment successfully canceled." }; + return handleApiResponse(response, "cancelPayment"); } type UpdatePayment = {