mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40:31 +00:00
Merge pull request #679 from bigcapitalhq/fix-listen-to-stripe-session-completed
fix: Listen to Stripe session completed event
This commit is contained in:
@@ -20,7 +20,7 @@ export class CreatePaymentReceiveStripePayment {
|
|||||||
private uow: UnitOfWork;
|
private uow: UnitOfWork;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
* @param {number} saleInvoiceId
|
* @param {number} saleInvoiceId
|
||||||
* @param {number} paidAmount
|
* @param {number} paidAmount
|
||||||
@@ -36,26 +36,27 @@ export class CreatePaymentReceiveStripePayment {
|
|||||||
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
|
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
|
||||||
// Finds or creates a new stripe payment clearing account (current asset).
|
// Finds or creates a new stripe payment clearing account (current asset).
|
||||||
const stripeClearingAccount =
|
const stripeClearingAccount =
|
||||||
accountRepository.findOrCreateStripeClearing({}, trx);
|
await accountRepository.findOrCreateStripeClearing({}, trx);
|
||||||
|
|
||||||
// Retrieves the given invoice to create payment transaction associated to it.
|
// Retrieves the given invoice to create payment transaction associated to it.
|
||||||
const invoice = await this.getSaleInvoiceService.getSaleInvoice(
|
const invoice = await this.getSaleInvoiceService.getSaleInvoice(
|
||||||
tenantId,
|
tenantId,
|
||||||
saleInvoiceId
|
saleInvoiceId
|
||||||
);
|
);
|
||||||
|
const paymentReceivedDTO = {
|
||||||
|
customerId: invoice.customerId,
|
||||||
|
paymentDate: new Date(),
|
||||||
|
amount: paidAmount,
|
||||||
|
exchangeRate: 1,
|
||||||
|
referenceNo: '',
|
||||||
|
statement: '',
|
||||||
|
depositAccountId: stripeClearingAccount.id,
|
||||||
|
entries: [{ invoiceId: saleInvoiceId, paymentAmount: paidAmount }],
|
||||||
|
};
|
||||||
// Create a payment received transaction associated to the given invoice.
|
// Create a payment received transaction associated to the given invoice.
|
||||||
await this.createPaymentReceivedService.createPaymentReceived(
|
await this.createPaymentReceivedService.createPaymentReceived(
|
||||||
tenantId,
|
tenantId,
|
||||||
{
|
paymentReceivedDTO,
|
||||||
customerId: invoice.customerId,
|
|
||||||
paymentDate: new Date(),
|
|
||||||
amount: paidAmount,
|
|
||||||
exchangeRate: 1,
|
|
||||||
referenceNo: '',
|
|
||||||
statement: '',
|
|
||||||
depositAccountId: stripeClearingAccount.id,
|
|
||||||
entries: [{ invoiceId: saleInvoiceId, paymentAmount: paidAmount }],
|
|
||||||
},
|
|
||||||
{},
|
{},
|
||||||
trx
|
trx
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||||
import { Tenant } from '@/system/models';
|
import { Tenant } from '@/system/models';
|
||||||
import { initalizeTenantServices } from '@/api/middleware/TenantDependencyInjection';
|
import { initalizeTenantServices } from '@/api/middleware/TenantDependencyInjection';
|
||||||
|
import { initializeTenantSettings } from '@/api/middleware/SettingsMiddleware';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class StripeWebhooksSubscriber {
|
export class StripeWebhooksSubscriber {
|
||||||
@@ -43,6 +44,7 @@ export class StripeWebhooksSubscriber {
|
|||||||
const saleInvoiceId = parseInt(metadata.saleInvoiceId, 10);
|
const saleInvoiceId = parseInt(metadata.saleInvoiceId, 10);
|
||||||
|
|
||||||
await initalizeTenantServices(tenantId);
|
await initalizeTenantServices(tenantId);
|
||||||
|
await initializeTenantSettings(tenantId);
|
||||||
|
|
||||||
// Get the amount from the event
|
// Get the amount from the event
|
||||||
const amount = event.data.object.amount_total;
|
const amount = event.data.object.amount_total;
|
||||||
|
|||||||
Reference in New Issue
Block a user