-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: (SFI-541)add paypal lineItems * chore: fix eslint issues * feat: (SFI-541)get all lineItems * fix: remove default itemCategory * fix: unit tests
- Loading branch information
1 parent
cc5d044
commit 0e5fbec
Showing
10 changed files
with
441 additions
and
252 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
50 changes: 50 additions & 0 deletions
50
src/cartridges/int_adyen_overlay/cartridge/scripts/__tests__/paypalHelper.test.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,50 @@ | ||
const paypalHelper = require('../paypalHelper') | ||
describe('paypalHelper', () => { | ||
let args,lineItem, result | ||
beforeEach(() => { | ||
args = (item) => ({ | ||
Order: { | ||
getAllLineItems: jest.fn(() => ([item])) | ||
} | ||
}) | ||
|
||
lineItem = { | ||
productName: 'test', | ||
productID: '123', | ||
quantityValue: '1', | ||
getAdjustedTax: '1000', | ||
adjustedNetPrice: '10000', | ||
category: 'PHYSICAL_GOODS', | ||
} | ||
|
||
result = { | ||
quantity: '1', | ||
description: 'test', | ||
itemCategory: 'PHYSICAL_GOODS', | ||
sku: '123', | ||
amountExcludingTax: '10000', | ||
taxAmount: '1000' | ||
} | ||
}) | ||
it('should return lineItems for paypal', () => { | ||
const paypalLineItems = paypalHelper.getLineItems(args(lineItem)) | ||
expect(paypalLineItems[0]).toStrictEqual(result) | ||
}) | ||
|
||
it('should return lineItems for paypal with default itemCategory when category is not as per paypal', () => { | ||
const paypalLineItems = paypalHelper.getLineItems(args({...lineItem, category: 'TEST_GOODS'})) | ||
expect(paypalLineItems[0]).toStrictEqual({ | ||
quantity: '1', | ||
description: 'test', | ||
sku: '123', | ||
amountExcludingTax: '10000', | ||
taxAmount: '1000' | ||
}) | ||
}) | ||
|
||
it('should return no lineItems for paypal if order or basket is not defined', () => { | ||
|
||
const paypalLineItems = paypalHelper.getLineItems({}) | ||
expect(paypalLineItems).toBeNull() | ||
}) | ||
}) |
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
50 changes: 50 additions & 0 deletions
50
src/cartridges/int_adyen_overlay/cartridge/scripts/paypalHelper.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,50 @@ | ||
/** | ||
* ###### | ||
* ###### | ||
* ############ ####( ###### #####. ###### ############ ############ | ||
* ############# #####( ###### #####. ###### ############# ############# | ||
* ###### #####( ###### #####. ###### ##### ###### ##### ###### | ||
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ###### | ||
* ###### ###### #####( ###### #####. ###### ##### ##### ###### | ||
* ############# ############# ############# ############# ##### ###### | ||
* ############ ############ ############# ############ ##### ###### | ||
* ###### | ||
* ############# | ||
* ############ | ||
* Adyen Salesforce Commerce Cloud | ||
* Copyright (c) 2021 Adyen B.V. | ||
* This file is open source and available under the MIT license. | ||
* See the LICENSE file for more info. | ||
* | ||
* Add all product and shipping line items to request | ||
*/ | ||
|
||
const LineItemHelper = require('*/cartridge/scripts/util/lineItemHelper'); | ||
|
||
const PAYPAL_ITEM_CATEGORY = ["PHYSICAL_GOODS","DIGITAL_GOODS","DONATION"] | ||
function getLineItems({ Order: order, Basket: basket }) { | ||
if (!(order || basket)) return null; | ||
const orderOrBasket = order || basket; | ||
const allLineItems = LineItemHelper.getAllLineItems(orderOrBasket.getAllLineItems()); | ||
return allLineItems.map((lineItem) => { | ||
const lineItemObject = {}; | ||
const description = LineItemHelper.getDescription(lineItem); | ||
const id = LineItemHelper.getId(lineItem); | ||
const quantity = LineItemHelper.getQuantity(lineItem); | ||
const itemAmount = LineItemHelper.getItemAmount(lineItem).divide(quantity); | ||
const vatAmount = LineItemHelper.getVatAmount(lineItem).divide(quantity); | ||
if (lineItem.hasOwnProperty('category')) { | ||
if (PAYPAL_ITEM_CATEGORY.indexOf(lineItem.category) > -1) { | ||
lineItemObject.itemCategory = lineItem.category | ||
} | ||
} | ||
lineItemObject.quantity= quantity; | ||
lineItemObject.description= description; | ||
lineItemObject.sku= id; | ||
lineItemObject.amountExcludingTax= itemAmount.getValue().toFixed(); | ||
lineItemObject.taxAmount= vatAmount.getValue().toFixed() | ||
return lineItemObject; | ||
}); | ||
} | ||
|
||
module.exports.getLineItems = getLineItems; |
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
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