feat: update cancelTopup API call to use PATCH method and enhance success message with topup details

This commit is contained in:
2025-07-06 19:59:27 +05:00
parent d4993530f7
commit b9d8e56c3c
3 changed files with 20 additions and 24 deletions

View File

@ -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<Topup>(response, "cancelTopup");
}
export async function cancelPayment({ id }: { id: string }) {