feat: clean up the stripe payment integration

This commit is contained in:
Ahmed Bouhuolia
2024-09-21 09:18:39 +02:00
parent f5a1d68c52
commit 11c56c75a4
18 changed files with 3144 additions and 484 deletions

View File

@@ -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;
}
}

View File

@@ -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
);
}
}

View File

@@ -1,6 +0,0 @@
export interface CreateStripeAccountDTO {
name: string;
}