Skip to content

Commit

Permalink
feat(payments): fix converting result bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dasanorct committed Mar 11, 2024
1 parent 1a2cdc7 commit e3a312b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion processor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "payment-integration-adyen",
"version": "0.0.5",
"version": "1.0.1",
"description": "Payment integration with Adyen",
"main": "dist/server.js",
"scripts": {
Expand Down
36 changes: 22 additions & 14 deletions processor/src/services/adyen-payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,10 @@ export class AdyenPaymentService extends AbstractPaymentService {
type: 'Authorization', //TODO: review
amount: ctPayment.amountPlanned,
interactionId: res.pspReference,
state: this.convertAdyenResultCode(res.resultCode as PaymentResponse.ResultCodeEnum),
state: this.convertAdyenResultCode(
res.resultCode as PaymentResponse.ResultCodeEnum,
this.isActionRequired(res),
),
},
});

Expand Down Expand Up @@ -281,7 +284,7 @@ export class AdyenPaymentService extends AbstractPaymentService {
type: 'Authorization',
amount: ctPayment.amountPlanned,
interactionId: res.pspReference,
state: this.convertAdyenResultCode(res.resultCode as PaymentResponse.ResultCodeEnum),
state: this.convertAdyenResultCode(res.resultCode as PaymentResponse.ResultCodeEnum, false),
},
});
return {
Expand Down Expand Up @@ -335,18 +338,23 @@ export class AdyenPaymentService extends AbstractPaymentService {
}
}

private convertAdyenResultCode(resultCode: PaymentResponse.ResultCodeEnum): string {
switch (resultCode) {
case PaymentResponse.ResultCodeEnum.Authorised:
return 'Success';
case PaymentResponse.ResultCodeEnum.Pending:
return 'Pending';
case PaymentResponse.ResultCodeEnum.Refused:
case PaymentResponse.ResultCodeEnum.Error:
case PaymentResponse.ResultCodeEnum.Cancelled:
return 'Failure';
default:
return 'Initial';
private convertAdyenResultCode(resultCode: PaymentResponse.ResultCodeEnum, isActionRequired: boolean): string {
if (resultCode === PaymentResponse.ResultCodeEnum.Authorised) {
return 'Success';
} else if (resultCode === PaymentResponse.ResultCodeEnum.Pending && !isActionRequired) {
return 'Pending';
} else if (
resultCode === PaymentResponse.ResultCodeEnum.Refused ||
resultCode === PaymentResponse.ResultCodeEnum.Error ||
resultCode === PaymentResponse.ResultCodeEnum.Cancelled
) {
return 'Failure';
} else {
return 'Initial';
}
}

private isActionRequired(data: PaymentResponse): boolean {
return data.action?.type !== undefined;
}
}

0 comments on commit e3a312b

Please sign in to comment.