continue: made a payments method list

This commit is contained in:
smanylov
2026-04-03 14:52:31 +07:00
parent e75fcd7bff
commit 6cf7bd766d
8 changed files with 376 additions and 31 deletions
+31 -2
View File
@@ -5,7 +5,6 @@ import { getSessionData } from '@/app/actions/session';
export async function getPaymentsMethods() {
const token = await getSessionData('token');
console.log('getPaymentsMethods');
try {
const response = await fetch(`${API_BASE_URL}/api/payments/methods`, {
@@ -19,7 +18,7 @@ export async function getPaymentsMethods() {
if (response.ok) {
const parsed = await response.json();
console.log(parsed);
return parsed;
} else {
return null
@@ -27,4 +26,34 @@ export async function getPaymentsMethods() {
} catch (error) {
return null
}
}
export async function deletePaymentsMethods(cardId: string): Promise<boolean | undefined> {
if (!cardId) {
return
}
const token = await getSessionData('token');
try {
const response = await fetch(`${API_BASE_URL}/api/payments/methods/${cardId}`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${token}`,
}
});
if (response.ok) {
const parsed = await response.json();
if (parsed.message === 'Payment method deleted') {
return true;
}
} else {
return false
}
} catch (error) {
return false
}
}