mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
feat: Stripe payment integration
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import { StripePaymentService } from './StripePaymentService';
|
||||
|
||||
@Service()
|
||||
export class CreateStripeAccountLinkService {
|
||||
@Inject()
|
||||
private stripePaymentService: StripePaymentService;
|
||||
|
||||
/**
|
||||
* Creates a new Stripe account id.
|
||||
* @param {number} tenantId
|
||||
*/
|
||||
public createAccountLink(tenantId: number, stripeAccountId: string) {
|
||||
return this.stripePaymentService.createAccountLink(stripeAccountId);
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ export class CreateStripeAccountService {
|
||||
await PaymentIntegration.query().insert({
|
||||
name: parsedStripeAccountDTO.name,
|
||||
accountId: stripeAccountId,
|
||||
enable: false,
|
||||
active: false, // Active will turn true after onboarding.
|
||||
service: 'Stripe',
|
||||
});
|
||||
// Triggers `onStripeIntegrationAccountCreated` event.
|
||||
|
||||
@@ -2,12 +2,16 @@ import { Inject } from 'typedi';
|
||||
import { CreateInvoiceCheckoutSession } from './CreateInvoiceCheckoutSession';
|
||||
import { StripeInvoiceCheckoutSessionPOJO } from '@/interfaces/StripePayment';
|
||||
import { CreateStripeAccountService } from './CreateStripeAccountService';
|
||||
import { CreateStripeAccountLinkService } from './CreateStripeAccountLink';
|
||||
import { CreateStripeAccountDTO } from './types';
|
||||
|
||||
export class StripePaymentApplication {
|
||||
@Inject()
|
||||
private createStripeAccountService: CreateStripeAccountService;
|
||||
|
||||
@Inject()
|
||||
private createStripeAccountLinkService: CreateStripeAccountLinkService;
|
||||
|
||||
@Inject()
|
||||
private createInvoiceCheckoutSessionService: CreateInvoiceCheckoutSession;
|
||||
|
||||
@@ -26,6 +30,19 @@ export class StripePaymentApplication {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Stripe account link of the given Stripe accoun..
|
||||
* @param {number} tenantId
|
||||
* @param {string} stripeAccountId
|
||||
* @returns {}
|
||||
*/
|
||||
public createAccountLink(tenantId: number, stripeAccountId: string) {
|
||||
return this.createStripeAccountLinkService.createAccountLink(
|
||||
tenantId,
|
||||
stripeAccountId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the Stripe checkout session from the given sale invoice.
|
||||
* @param {number} tenantId
|
||||
|
||||
@@ -2,6 +2,8 @@ import { Service } from 'typedi';
|
||||
import stripe from 'stripe';
|
||||
import config from '@/config';
|
||||
|
||||
const origin = 'http://localhost:4000';
|
||||
|
||||
@Service()
|
||||
export class StripePaymentService {
|
||||
public stripe;
|
||||
@@ -13,8 +15,8 @@ export class StripePaymentService {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {number} accountId
|
||||
*
|
||||
* @param {number} accountId
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
public async createAccountSession(accountId: string): Promise<string> {
|
||||
@@ -35,6 +37,27 @@ export class StripePaymentService {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {number} accountId
|
||||
* @returns
|
||||
*/
|
||||
public async createAccountLink(accountId: string) {
|
||||
try {
|
||||
const accountLink = await this.stripe.accountLinks.create({
|
||||
account: accountId,
|
||||
return_url: `${origin}/return/${accountId}`,
|
||||
refresh_url: `${origin}/refresh/${accountId}`,
|
||||
type: 'account_onboarding',
|
||||
});
|
||||
return accountLink;
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
'An error occurred when calling the Stripe API to create an account link:'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
public async createAccount(): Promise<string> {
|
||||
|
||||
Reference in New Issue
Block a user