mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
feat: clean up the stripe payment integration
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
import { StripePaymentService } from '@/services/StripePayment/StripePaymentService';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { CreateStripeAccountDTO } from './types';
|
||||
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
||||
import events from '@/subscribers/events';
|
||||
|
||||
@Service()
|
||||
export class CreateStripeAccountService {
|
||||
@Inject()
|
||||
private stripePaymentService: StripePaymentService;
|
||||
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
@Inject()
|
||||
private eventPublisher: EventPublisher;
|
||||
|
||||
/**
|
||||
* Creates a new Stripe account.
|
||||
* @param {number} tenantId
|
||||
* @param {CreateStripeAccountDTO} stripeAccountDTO
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async createStripeAccount(
|
||||
tenantId: number,
|
||||
stripeAccountDTO?: CreateStripeAccountDTO
|
||||
): Promise<string> {
|
||||
const { PaymentIntegration } = this.tenancy.models(tenantId);
|
||||
const stripeAccount = await this.stripePaymentService.createAccount();
|
||||
const stripeAccountId = stripeAccount.id;
|
||||
|
||||
const parsedStripeAccountDTO = {
|
||||
...stripeAccountDTO,
|
||||
name: 'Stripe',
|
||||
};
|
||||
// Stores the details of the Stripe account.
|
||||
await PaymentIntegration.query().insert({
|
||||
name: parsedStripeAccountDTO.name,
|
||||
accountId: stripeAccountId,
|
||||
enable: false,
|
||||
service: 'Stripe',
|
||||
});
|
||||
// Triggers `onStripeIntegrationAccountCreated` event.
|
||||
await this.eventPublisher.emitAsync(
|
||||
events.stripeIntegration.onAccountCreated,
|
||||
{
|
||||
tenantId,
|
||||
stripeAccountDTO,
|
||||
stripeAccountId,
|
||||
}
|
||||
);
|
||||
return stripeAccountId;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import { CreateStripeAccountService } from './CreateStripeAccountService';
|
||||
import { CreateStripeAccountDTO } from './types';
|
||||
@Service()
|
||||
export class StripeIntegrationApplication {
|
||||
@Inject()
|
||||
private createStripeAccountService: CreateStripeAccountService;
|
||||
|
||||
/**
|
||||
* Creates a new Stripe account for the tenant.
|
||||
* @param {TenantContext} tenantContext - The tenant context.
|
||||
* @param {string} label - The label for the Stripe account.
|
||||
* @returns {Promise<string>} The ID of the created Stripe account.
|
||||
*/
|
||||
public async createStripeAccount(
|
||||
tenantId: number,
|
||||
stripeAccountDTO?: CreateStripeAccountDTO
|
||||
): Promise<string> {
|
||||
return this.createStripeAccountService.createStripeAccount(
|
||||
tenantId,
|
||||
stripeAccountDTO
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
|
||||
|
||||
|
||||
export interface CreateStripeAccountDTO {
|
||||
name: string;
|
||||
}
|
||||
Reference in New Issue
Block a user