build: 91279040-7fca-48e0-9d50-5ce29aae63f6
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { supabase } from '../supabase';
|
||||
|
||||
export async function createCheckout(amount: number, tier: 'premium') {
|
||||
const { data, error } = await supabase.functions.invoke('create-payment', {
|
||||
body: {
|
||||
amount,
|
||||
currency: 'USD',
|
||||
tier,
|
||||
description: `InSpot ${tier} Subscription`,
|
||||
},
|
||||
});
|
||||
|
||||
if (error) throw error;
|
||||
return data as { checkoutUrl: string; paymentId: string };
|
||||
}
|
||||
|
||||
export async function pollPaymentStatus(paymentId: string, maxAttempts = 20) {
|
||||
for (let i = 0; i < maxAttempts; i++) {
|
||||
const { data, error } = await supabase
|
||||
.from('payments')
|
||||
.select('status')
|
||||
.eq('id', paymentId)
|
||||
.single();
|
||||
|
||||
if (error) throw error;
|
||||
if (data.status === 'paid' || data.status === 'failed') return data.status;
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 3000));
|
||||
}
|
||||
return 'pending';
|
||||
}
|
||||
Reference in New Issue
Block a user