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 = {