Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SFI-415] setPaymentTransactionType not working for giftcards #1014

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading