mirror of
				https://github.com/i701/sarlink-portal.git
				synced 2025-11-04 00:16:59 +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 }) {
 | 
			
		||||
	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<Payment>(response, "cancelPayment");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type UpdatePayment = {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user