mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
feat: Stripe payment integration
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import HasTenancyService from '../Tenancy/TenancyService';
|
||||
import { GetPaymentMethodsPOJO } from './types';
|
||||
import config from '@/config';
|
||||
|
||||
@Service()
|
||||
export class GetPaymentMethodsStateService {
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
* Retrieves the payment state provising state.
|
||||
* @param {number} tenantId
|
||||
* @returns {Promise<GetPaymentMethodsPOJO>}
|
||||
*/
|
||||
public async getPaymentMethodsState(
|
||||
tenantId: number
|
||||
): Promise<GetPaymentMethodsPOJO> {
|
||||
const { PaymentIntegration } = this.tenancy.models(tenantId);
|
||||
|
||||
const stripePayment = await PaymentIntegration.query()
|
||||
.orderBy('createdAt', 'ASC')
|
||||
.findOne({
|
||||
service: 'Stripe',
|
||||
});
|
||||
const isStripeAccountCreated = !!stripePayment;
|
||||
const isStripePaymentActive = !!(stripePayment?.active || null);
|
||||
|
||||
const stripeAccountId = stripePayment?.accountId || null;
|
||||
const stripePublishableKey = config.stripePayment.publishableKey;
|
||||
const stripeCurrencies = ['USD', 'EUR'];
|
||||
const stripeRedirectUrl = 'https://your-stripe-redirect-url.com';
|
||||
|
||||
const paymentMethodPOJO: GetPaymentMethodsPOJO = {
|
||||
stripe: {
|
||||
isStripeAccountCreated,
|
||||
isStripePaymentActive,
|
||||
stripeAccountId,
|
||||
stripePublishableKey,
|
||||
stripeCurrencies,
|
||||
stripeRedirectUrl,
|
||||
},
|
||||
};
|
||||
return paymentMethodPOJO;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user