feat: Onboard accounts to Stripe Connect

This commit is contained in:
Ahmed Bouhuolia
2024-09-08 11:42:26 +02:00
parent 6d24474162
commit a183666df6
14 changed files with 360 additions and 3 deletions

View File

@@ -0,0 +1,42 @@
import { Service } from 'typedi';
import stripe from 'stripe';
import config from '@/config';
@Service()
export class StripePaymentService {
private stripe;
constructor() {
this.stripe = new stripe(config.stripePayment.secretKey, {
apiVersion: '2023-10-16',
});
}
public async createAccountSession(accountId: string) {
try {
const accountSession = await this.stripe.accountSessions.create({
account: accountId,
components: {
account_onboarding: { enabled: true },
},
});
return accountSession.client_secret;
} catch (error) {
throw new Error(
'An error occurred when calling the Stripe API to create an account session'
);
}
}
public async createAccount() {
try {
const account = await this.stripe.accounts.create({});
return account.id;
} catch (error) {
throw new Error(
'An error occurred when calling the Stripe API to create an account'
);
}
}
}