mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-08 01:06:31 +00:00
refactor: update cancelPayment function to use PATCH method and new endpoint 🔨
This commit is contained in:
@ -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 = {
|
||||||
|
Reference in New Issue
Block a user