refactor: update cancelPayment function to use PATCH method and new endpoint 🔨

This commit is contained in:
2025-07-06 22:38:55 +05:00
parent 4797ee8dde
commit e984705849

View File

@ -179,24 +179,16 @@ export async function cancelTopup({ id }: { id: string }) {
export async function cancelPayment({ id }: { id: string }) { export async function cancelPayment({ id }: { id: string }) {
const session = await getServerSession(authOptions); const session = await getServerSession(authOptions);
const response = await fetch( 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: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Token ${session?.apiToken}`, Authorization: `Token ${session?.apiToken}`,
}, },
}, },
); );
if (!response.ok) { return handleApiResponse<Payment>(response, "cancelPayment");
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." };
} }
type UpdatePayment = { type UpdatePayment = {