This commit is contained in:
Emily
2024-06-04 15:36:57 +02:00
parent 0427827858
commit c151d558f4
6 changed files with 101 additions and 25 deletions

View File

@@ -22,16 +22,20 @@ class StripeService {
return this.stripe.webhooks.constructEvent(body, sig, this.webhookSecret);
}
async cretePayment(price: string, success_url: string, customer?: string) {
async cretePayment(price: string, success_url: string, pid: string, customer?: string) {
if (!this.stripe) {
console.error('Stripe not initialized')
return;
}
const checkout = await this.stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [
{ price, quantity: 1 }
],
subscription_data: {
metadata: { pid },
},
customer,
success_url,
mode: 'subscription'
@@ -48,6 +52,11 @@ class StripeService {
const subscription = await this.stripe.subscriptions.retrieve(subscriptionId);
return subscription;
}
async getInvoices(customer_id: string) {
const invoices = await this.stripe?.invoices.list({ customer: customer_id });
return invoices;
}
}
const instance = new StripeService();