Skip to content

Commit 5796387

Browse files
Add stripe-payment-methods to config
1 parent 0b314df commit 5796387

2 files changed

Lines changed: 25 additions & 43 deletions

File tree

src/services/paymentMethodService.ts

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,50 +20,28 @@ export const paymentMethodService = {
2020
body: {} // POST vide pour déclencher handleGetPaymentMethods
2121
});
2222

23-
if (!error && data?.paymentMethods) {
24-
console.log('✅ SUPABASE: Cartes bancaires chargées:', data?.paymentMethods?.length || 0);
25-
26-
// Mapper les données pour correspondre à l'interface PaymentMethod
27-
const paymentMethods = data?.paymentMethods?.map((pm: any) => ({
28-
id: pm.id,
29-
type: pm.type,
30-
last4: pm.card?.last4 || '',
31-
brand: pm.card?.brand || '',
32-
exp_month: pm.card?.exp_month || 0,
33-
exp_year: pm.card?.exp_year || 0,
34-
isDefault: pm.isDefault || false
35-
})) || [];
36-
37-
return paymentMethods;
38-
} else {
39-
console.warn('⚠️ SUPABASE Edge Function failed, trying fallback API');
40-
}
41-
} catch (supabaseError) {
42-
console.warn('⚠️ SUPABASE Edge Function error, trying fallback API:', supabaseError);
43-
}
44-
45-
// Fallback to old API endpoint if Supabase fails
46-
try {
47-
console.log('🔄 FALLBACK: Utilisation API de secours pour les cartes');
48-
const response = await fetch('/api/stripe-payment-methods', {
49-
method: 'POST',
50-
headers: {
51-
'Content-Type': 'application/json',
52-
},
53-
body: JSON.stringify({ userEmail }),
54-
});
55-
56-
if (!response.ok) {
57-
throw new Error(`HTTP error! status: ${response.status}`);
23+
if (error) {
24+
console.error('❌ SUPABASE: Erreur récupération méthodes de paiement:', error);
25+
return [];
5826
}
59-
60-
const data = await response.json();
61-
console.log('✅ FALLBACK: Cartes bancaires chargées:', data?.paymentMethods?.length || 0);
62-
63-
return data?.paymentMethods || [];
64-
} catch (fallbackError) {
65-
console.error('❌ FALLBACK: Erreur API de secours:', fallbackError);
66-
return []; // Return empty array instead of throwing
27+
28+
console.log('✅ SUPABASE: Cartes bancaires chargées:', data?.paymentMethods?.length || 0);
29+
30+
// Mapper les données pour correspondre à l'interface PaymentMethod
31+
const paymentMethods = data?.paymentMethods?.map((pm: any) => ({
32+
id: pm.id,
33+
type: pm.type,
34+
last4: pm.card?.last4 || '',
35+
brand: pm.card?.brand || '',
36+
exp_month: pm.card?.exp_month || 0,
37+
exp_year: pm.card?.exp_year || 0,
38+
isDefault: pm.isDefault || false
39+
})) || [];
40+
41+
return paymentMethods;
42+
} catch (error) {
43+
console.error('❌ SUPABASE: Erreur chargement cartes:', error);
44+
return [];
6745
}
6846
},
6947

supabase/config.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
project_id = "wsvhmozduyiftmuuynpi"
22

3+
# Stripe functions (authenticated)
4+
[functions.stripe-payment-methods]
5+
verify_jwt = true
6+
37
# Shopify functions (public)
48
[functions.shopify-auth]
59
verify_jwt = false

0 commit comments

Comments
 (0)