Skip to content

Commit

Permalink
[SFI-415] setPaymentTransactionType not working for giftcards (#1014)
Browse files Browse the repository at this point in the history
  • Loading branch information
zenit2001 committed Nov 27, 2023
1 parent 3c5e50b commit 9aadc50
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
1 change: 1 addition & 0 deletions jest/sfccCartridgeMocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ jest.mock('*/cartridge/scripts/util/adyenHelper', () => ({
return request
}),
getAdyenComponentType : jest.fn(() => {}),
setPaymentTransactionType : jest.fn(() => {}),
getOrderMainPaymentInstrumentType: jest.fn(() => {}),
getPaymentInstrumentType: jest.fn((isCreditCard) => isCreditCard ? 'CREDIT_CARD' : 'AdyenComponent'),
}), {virtual: true});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@ const adyenLevelTwoThreeData = require('*/cartridge/scripts/adyenLevelTwoThreeDa
const constants = require('*/cartridge/adyenConstants/constants');
const AdyenLogs = require('*/cartridge/scripts/adyenCustomLogs');

//SALE payment methods require payment transaction type to be Capture
function setPaymentTransactionType(paymentInstrument, paymentMethod) {
const salePaymentMethods = AdyenConfigs.getAdyenSalePaymentMethods();
if (salePaymentMethods.indexOf(paymentMethod.type) > -1) {
Transaction.wrap(function () {
paymentInstrument
.getPaymentTransaction()
.setType(dw.order.PaymentTransaction.TYPE_CAPTURE);
});
}
}

function createPaymentRequest(args) {
try {
const order = args.Order;
Expand Down Expand Up @@ -160,8 +148,7 @@ function createPaymentRequest(args) {
paymentRequest.storePaymentMethod = true;
paymentRequest.recurringProcessingModel = constants.RECURRING_PROCESSING_MODEL.CARD_ON_FILE;
}
setPaymentTransactionType(paymentInstrument, paymentRequest.paymentMethod);

AdyenHelper.setPaymentTransactionType(paymentInstrument, paymentRequest.paymentMethod);
// make API call
return doPaymentsCall(order, paymentInstrument, paymentRequest);
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ const adyenConfigsObj = {
return getCustomPreference('AdyenTokenisationEnabled');
},

getAdyenSalePaymentMethods: function () {
return getCustomPreference('AdyenSalePaymentMethods') ? getCustomPreference('AdyenSalePaymentMethods').toString().split(',') : '';
},

getAdyenBasketFieldsEnabled() {
return getCustomPreference('AdyenBasketFieldsEnabled');
},
Expand All @@ -127,7 +123,7 @@ const adyenConfigsObj = {

getAdyenSalePaymentMethods: function () {
return getCustomPreference('AdyenSalePaymentMethods')
? getCustomPreference('AdyenSalePaymentMethods').toString().split(',')
? getCustomPreference('AdyenSalePaymentMethods').replace(/\s/g, '').toString().split(',')
: [];
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,23 @@ var adyenHelperObj = {
};
},

getPaymentMethodType(paymentMethod){
return paymentMethod.type === constants.ACTIONTYPES.GIFTCARD ? paymentMethod.brand : paymentMethod.type;
},

//SALE payment methods require payment transaction type to be Capture
setPaymentTransactionType(paymentInstrument, paymentMethod) {
const salePaymentMethods = AdyenConfigs.getAdyenSalePaymentMethods();
const paymentMethodType = this.getPaymentMethodType(paymentMethod);
if (salePaymentMethods.indexOf(paymentMethodType) > -1) {
Transaction.wrap(function () {
paymentInstrument
.getPaymentTransaction()
.setType(dw.order.PaymentTransaction.TYPE_CAPTURE);
});
}
},

executeCall(serviceType, requestObject) {
const service = this.getService(serviceType);
if (service === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* See the LICENSE file for more info.
*/
const constants = require('*/cartridge/adyenConstants/constants');
const AdyenHelper = require('*/cartridge/scripts/util/adyenHelper');
const Transaction = require('dw/system/Transaction');
//script includes
const PaymentMgr = require('dw/order/PaymentMgr');
Expand Down Expand Up @@ -49,6 +50,7 @@ let giftCardsHelper = {
paymentInstrument.paymentTransaction.custom.Adyen_log = JSON.stringify(parsedGiftCardObj);
paymentInstrument.paymentTransaction.custom.Adyen_pspReference = parsedGiftCardObj.giftCard.pspReference;
})
AdyenHelper.setPaymentTransactionType(paymentInstrument, parsedGiftCardObj.giftCard);
}
};

Expand Down

0 comments on commit 9aadc50

Please sign in to comment.