Skip to content

Commit

Permalink
fix: check for adyen credit card payment method (#894)
Browse files Browse the repository at this point in the history
  • Loading branch information
amihajlovski committed Mar 27, 2023
1 parent c8ccb8d commit 7459739
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ module.exports = {
METHOD_ADYEN_POS: 'AdyenPOS',
METHOD_ADYEN_COMPONENT: 'AdyenComponent',
METHOD_CREDIT_CARD: 'CREDIT_CARD',

PAYMENT_INSTRUMENT_ADYEN_CREDIT: 'ADYEN_CREDIT',
PAYMENT_INSTRUMENT_ADYEN_POS: 'Adyen_POS',
PAYMENT_INSTRUMENT_ADYEN_COMPONENT: 'Adyen_Component',

// Possible checkout result codes
RESULTCODES: {
AUTHORISED: 'Authorised',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,27 +102,34 @@ function handle(customObj) {
if (orderCreateDateDelay < currentDate) {
switch (customObj.custom.eventCode) {
case 'AUTHORISATION':
// Check if one of the adyen payment methods was used during payment
// Or if the payment method belongs to adyen payment processors
const paymentInstruments = order.getPaymentInstruments();
let adyenPaymentInstrument = null;
// Move adyen log request to order payment transaction
for (const pi in paymentInstruments) {
if (
[
constants.METHOD_ADYEN,
constants.METHOD_ADYEN_POS,
constants.METHOD_ADYEN_COMPONENT,
constants.METHOD_CREDIT_CARD,
].indexOf(paymentInstruments[pi].paymentMethod) !== -1 ||
PaymentMgr.getPaymentMethod(
[
constants.PAYMENT_INSTRUMENT_ADYEN_CREDIT,
constants.PAYMENT_INSTRUMENT_ADYEN_POS,
constants.PAYMENT_INSTRUMENT_ADYEN_COMPONENT,
].indexOf(PaymentMgr.getPaymentMethod(
paymentInstruments[pi].getPaymentMethod(),
).getPaymentProcessor().ID === 'ADYEN_CREDIT'
).getPaymentProcessor().ID) !== -1
) {
isAdyen = true;
// Move adyen log request to order payment transaction
paymentInstruments[pi].paymentTransaction.custom.Adyen_log =
customObj.custom.Adyen_log;
adyenPaymentInstrument = paymentInstruments[pi];
}
}
if (customObj.custom.success === 'true') {
if (customObj.custom.success === 'true' && adyenPaymentInstrument) {
const amountPaid = parseFloat(order.custom.Adyen_value) + parseFloat(customObj.custom.value);
const totalAmount = adyenHelper.getCurrencyValueForApi(adyenPaymentInstrument.getPaymentTransaction().getAmount()).value;
if (order.paymentStatus.value === Order.PAYMENT_STATUS_PAID) {
Expand Down Expand Up @@ -287,8 +294,7 @@ function handle(customObj) {
}

function setProcessedCOInfo(customObj) {
const now = new Date();
customObj.custom.processedDate = now;
customObj.custom.processedDate = new Date();
customObj.custom.updateStatus = 'SUCCESS';
customObj.custom.processedStatus = 'SUCCESS';
}
Expand Down

0 comments on commit 7459739

Please sign in to comment.