mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
feat: Link transations with payment methods
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { StripePaymentService } from './StripePaymentService';
|
||||
import HasTenancyService from '../Tenancy/TenancyService';
|
||||
import { snakeCase } from 'lodash';
|
||||
|
||||
interface CreateStripeAccountDTO {
|
||||
name: string;
|
||||
}
|
||||
|
||||
@Service()
|
||||
export class CreateStripeAccountService {
|
||||
@Inject()
|
||||
private stripePaymentService: StripePaymentService;
|
||||
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
* Creates a new Stripe account for Bigcapital.
|
||||
* @param {number} tenantId
|
||||
* @param {number} createStripeAccountDTO
|
||||
*/
|
||||
async createAccount(
|
||||
tenantId: number,
|
||||
createStripeAccountDTO: CreateStripeAccountDTO
|
||||
) {
|
||||
const { PaymentIntegration } = this.tenancy.models(tenantId);
|
||||
|
||||
// Creates a new Stripe account.
|
||||
const account = await this.stripePaymentService.createAccount();
|
||||
|
||||
const slug = snakeCase(createStripeAccountDTO.name);
|
||||
|
||||
// Store the Stripe account on tenant store.
|
||||
await PaymentIntegration.query().insert({
|
||||
service: 'stripe',
|
||||
name: createStripeAccountDTO.name,
|
||||
slug,
|
||||
enable: true,
|
||||
accountId: account.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -33,11 +33,15 @@ export class StripePaymentService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
public async createAccount(): Promise<string> {
|
||||
try {
|
||||
const account = await this.stripe.accounts.create({});
|
||||
|
||||
return account.id;
|
||||
return account;
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
'An error occurred when calling the Stripe API to create an account'
|
||||
|
||||
Reference in New Issue
Block a user