|
1 | 1 | import { Log } from '@lomray/microservice-helpers';
|
2 |
| -import { BaseException } from '@lomray/microservice-nodejs-lib'; |
| 2 | +import { BaseException, Microservice } from '@lomray/microservice-nodejs-lib'; |
| 3 | +import Event from '@lomray/microservices-client-api/constants/events/payment-stripe'; |
3 | 4 | import StripeSdk from 'stripe';
|
4 | 5 | import remoteConfig from '@config/remote';
|
5 | 6 | import StripeAccountTypes from '@constants/stripe-account-types';
|
@@ -917,20 +918,29 @@ class Stripe extends Abstract {
|
917 | 918 | * Handles completing of transaction inside stripe payment process
|
918 | 919 | */
|
919 | 920 | public async handleTransactionCompleted(event: StripeSdk.Event): Promise<Transaction | void> {
|
920 |
| - /* eslint-disable camelcase */ |
921 |
| - const { id, payment_status, status } = event.data.object as ICheckoutEvent; |
| 921 | + const { id, payment_status: paymentStatus, status } = event.data.object as ICheckoutEvent; |
| 922 | + |
| 923 | + const transaction = await this.transactionRepository.findOne(id); |
| 924 | + |
| 925 | + if (!transaction) { |
| 926 | + Log.error(`There is no actual transfer for entity with following transaction id: ${id}`); |
| 927 | + } |
922 | 928 |
|
923 | 929 | await this.transactionRepository.update(
|
924 | 930 | { transactionId: id },
|
925 | 931 | {
|
926 |
| - status: this.getStatus(payment_status as StripeTransactionStatus), |
| 932 | + status: this.getStatus(paymentStatus as StripeTransactionStatus), |
927 | 933 | params: {
|
928 | 934 | checkoutStatus: status as StripeCheckoutStatus,
|
929 |
| - paymentStatus: payment_status as StripeTransactionStatus, |
| 935 | + paymentStatus: paymentStatus as StripeTransactionStatus, |
930 | 936 | },
|
931 | 937 | },
|
932 | 938 | );
|
933 |
| - /* eslint-enable camelcase */ |
| 939 | + |
| 940 | + void Microservice.eventPublish(Event.EntityPaid, { |
| 941 | + entityId: transaction?.entityId, |
| 942 | + userId: transaction?.userId, |
| 943 | + }); |
934 | 944 | }
|
935 | 945 |
|
936 | 946 | /**
|
|
0 commit comments