-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create payment instruments for each giftcard (#857)
* fix: parsing giftcards to reduce complexity * fix: remove unused imports; use basket giftcards check * fix: added new file path in jest config * fix: removed unused imports * fix: helpers jest path
- Loading branch information
1 parent
20d1149
commit 3028364
Showing
4 changed files
with
95 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/cartridges/int_adyen_overlay/cartridge/scripts/util/giftCardsHelper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* ###### | ||
* ###### | ||
* ############ ####( ###### #####. ###### ############ ############ | ||
* ############# #####( ###### #####. ###### ############# ############# | ||
* ###### #####( ###### #####. ###### ##### ###### ##### ###### | ||
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ###### | ||
* ###### ###### #####( ###### #####. ###### ##### ##### ###### | ||
* ############# ############# ############# ############# ##### ###### | ||
* ############ ############ ############# ############ ##### ###### | ||
* ###### | ||
* ############# | ||
* ############ | ||
* Adyen Salesforce Commerce Cloud | ||
* Copyright (c) 2022 Adyen B.V. | ||
* This file is open source and available under the MIT license. | ||
* See the LICENSE file for more info. | ||
*/ | ||
const constants = require('*/cartridge/adyenConstants/constants'); | ||
const Transaction = require('dw/system/Transaction'); | ||
//script includes | ||
const PaymentMgr = require('dw/order/PaymentMgr'); | ||
const Money = require('dw/value/Money'); | ||
|
||
let giftCardsHelper = { | ||
createGiftCardPaymentInstrument(parsedGiftCardObj, divideBy, order) { | ||
let paymentInstrument; | ||
const paidGiftCardAmount = { | ||
value: parsedGiftCardObj.giftCard.amount.value, | ||
currency: parsedGiftCardObj.giftCard.amount.currency | ||
}; | ||
const paidGiftCardAmountFormatted = new Money(paidGiftCardAmount.value, paidGiftCardAmount.currency).divide(divideBy); | ||
Transaction.wrap(() => { | ||
paymentInstrument = order.createPaymentInstrument( | ||
constants.METHOD_ADYEN_COMPONENT, | ||
paidGiftCardAmountFormatted, | ||
); | ||
const { paymentProcessor } = PaymentMgr.getPaymentMethod( | ||
paymentInstrument.paymentMethod, | ||
); | ||
paymentInstrument.paymentTransaction.paymentProcessor = paymentProcessor; | ||
paymentInstrument.custom.adyenPaymentMethod = parsedGiftCardObj.giftCard.name; | ||
paymentInstrument.custom[`${constants.OMS_NAMESPACE}_Adyen_Payment_Method`] = parsedGiftCardObj.giftCard.name; | ||
paymentInstrument.custom.Adyen_Payment_Method_Variant = parsedGiftCardObj.giftCard.brand; | ||
paymentInstrument.custom[ | ||
`${constants.OMS_NAMESPACE}_Adyen_Payment_Method_Variant` | ||
] = parsedGiftCardObj.giftCard.brand; | ||
paymentInstrument.paymentTransaction.custom.Adyen_log = JSON.stringify(parsedGiftCardObj); | ||
paymentInstrument.paymentTransaction.custom.Adyen_pspReference = parsedGiftCardObj.giftCard.pspReference; | ||
}) | ||
} | ||
}; | ||
|
||
module.exports = giftCardsHelper; |