Skip to content

Commit 74f0e0c

Browse files
authored
feat: added event publishing after successful stripe payment (#41)
* feat: added event publishing after successful stripe payment
1 parent c089ab1 commit 74f0e0c

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

microservices/payment-stripe/package-lock.json

Lines changed: 11 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

microservices/payment-stripe/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
},
4141
"dependencies": {
4242
"@lomray/microservice-helpers": "^2.5.6",
43+
"@lomray/microservices-client-api": "^2.15.4",
4344
"class-transformer": "^0.5.1",
4445
"class-validator": "^0.14.0",
4546
"class-validator-jsonschema": "^5.0.0",

microservices/payment-stripe/src/services/payment-gateway/stripe.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
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';
34
import StripeSdk from 'stripe';
45
import remoteConfig from '@config/remote';
56
import StripeAccountTypes from '@constants/stripe-account-types';
@@ -917,20 +918,29 @@ class Stripe extends Abstract {
917918
* Handles completing of transaction inside stripe payment process
918919
*/
919920
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+
}
922928

923929
await this.transactionRepository.update(
924930
{ transactionId: id },
925931
{
926-
status: this.getStatus(payment_status as StripeTransactionStatus),
932+
status: this.getStatus(paymentStatus as StripeTransactionStatus),
927933
params: {
928934
checkoutStatus: status as StripeCheckoutStatus,
929-
paymentStatus: payment_status as StripeTransactionStatus,
935+
paymentStatus: paymentStatus as StripeTransactionStatus,
930936
},
931937
},
932938
);
933-
/* eslint-enable camelcase */
939+
940+
void Microservice.eventPublish(Event.EntityPaid, {
941+
entityId: transaction?.entityId,
942+
userId: transaction?.userId,
943+
});
934944
}
935945

936946
/**

0 commit comments

Comments
 (0)