Skip to content

Commit

Permalink
Merge pull request #1140 from logeecom/master
Browse files Browse the repository at this point in the history
Pull request from logeecom fork
  • Loading branch information
MarijaIv authored Jan 25, 2024
2 parents de7f16f + d4b8162 commit a70215d
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 7 deletions.
26 changes: 23 additions & 3 deletions extension/src/paymentHandler/line-items-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function _getLocales(cart, payment) {
}

function _createAdyenLineItemFromLineItem(ctpLineItem, locales) {
const quantity = ctpLineItem.quantity
return {
id: ctpLineItem.variant.sku,
quantity: ctpLineItem.quantity,
Expand All @@ -55,12 +56,21 @@ function _createAdyenLineItemFromLineItem(ctpLineItem, locales) {
locales,
KLARNA_DEFAULT_LINE_ITEM_NAME,
),
amountIncludingTax: ctpLineItem.price.value.centAmount,
amountExcludingTax: parseFloat(
(ctpLineItem.taxedPrice.totalNet.centAmount / quantity).toFixed(0),
),
amountIncludingTax: parseFloat(
(ctpLineItem.taxedPrice.totalGross.centAmount / quantity).toFixed(0),
),
taxAmount: parseFloat(
(ctpLineItem.taxedPrice.totalTax.centAmount / quantity).toFixed(0),
),
taxPercentage: ctpLineItem.taxRate.amount * ADYEN_PERCENTAGE_MINOR_UNIT,
}
}

function _createAdyenLineItemFromCustomLineItem(ctpLineItem, locales) {
const quantity = ctpLineItem.quantity
return {
id: ctpLineItem.id,
quantity: ctpLineItem.quantity,
Expand All @@ -69,7 +79,15 @@ function _createAdyenLineItemFromCustomLineItem(ctpLineItem, locales) {
locales,
KLARNA_DEFAULT_LINE_ITEM_NAME,
),
amountIncludingTax: ctpLineItem.money.centAmount,
amountExcludingTax: parseFloat(
(ctpLineItem.taxedPrice.totalNet.centAmount / quantity).toFixed(0),
),
amountIncludingTax: parseFloat(
(ctpLineItem.taxedPrice.totalGross.centAmount / quantity).toFixed(0),
),
taxAmount: parseFloat(
(ctpLineItem.taxedPrice.totalTax.centAmount / quantity).toFixed(0),
),
taxPercentage: ctpLineItem.taxRate.amount * ADYEN_PERCENTAGE_MINOR_UNIT,
}
}
Expand All @@ -81,7 +99,9 @@ function _createShippingInfoAdyenLineItem(shippingInfo, locales) {
description:
_getShippingMethodDescription(shippingInfo, locales) ||
KLARNA_DEFAULT_SHIPPING_METHOD_DESCRIPTION,
amountIncludingTax: shippingInfo.price.centAmount,
amountExcludingTax: shippingInfo.taxedPrice.totalNet.centAmount,
amountIncludingTax: shippingInfo.taxedPrice.totalGross.centAmount,
taxAmount: shippingInfo.taxedPrice.totalTax.centAmount,
taxPercentage: shippingInfo.taxRate.amount * ADYEN_PERCENTAGE_MINOR_UNIT,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ describe('create-lineitems-session-request::execute', () => {
expect(ctpLineItem.price.value.centAmount).to.equal(
adyenLineItem.amountIncludingTax,
)
expect(
parseFloat(
(
ctpLineItem.price.value.centAmount /
(1 + ctpLineItem.taxRate.amount)
).toFixed(0),
),
).to.equal(adyenLineItem.amountExcludingTax)
expect(
ctpLineItem.price.value.centAmount -
parseFloat(
(
ctpLineItem.price.value.centAmount /
(1 + ctpLineItem.taxRate.amount)
).toFixed(0),
),
).to.equal(adyenLineItem.taxAmount)
expect(ctpLineItem.taxRate.amount * ADYEN_PERCENTAGE_MINOR_UNIT).to.equal(
adyenLineItem.taxPercentage,
)
Expand All @@ -85,6 +102,23 @@ describe('create-lineitems-session-request::execute', () => {
expect(ctpShippingInfo.price.centAmount).to.equal(
adyenShippingInfo.amountIncludingTax,
)
expect(
parseFloat(
(
ctpShippingInfo.price.centAmount /
(1 + ctpShippingInfo.taxRate.amount)
).toFixed(0),
),
).to.equal(adyenShippingInfo.amountExcludingTax)
expect(
ctpShippingInfo.price.centAmount -
parseFloat(
(
ctpShippingInfo.price.centAmount /
(1 + ctpShippingInfo.taxRate.amount)
).toFixed(0),
),
).to.equal(adyenShippingInfo.taxAmount)
expect(
ctpShippingInfo.taxRate.amount * ADYEN_PERCENTAGE_MINOR_UNIT,
).to.equal(adyenShippingInfo.taxPercentage)
Expand Down
24 changes: 24 additions & 0 deletions extension/test/unit/fixtures/ctp-cart-custom-shipping-method.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@
"currencyCode": "EUR",
"centAmount": 1710,
"fractionDigits": 2
},
"totalTax": {
"type": "centPrecision",
"currencyCode": "EUR",
"centAmount": 273,
"fractionDigits": 2
}
},
"lineItemMode": "Standard"
Expand All @@ -234,6 +240,12 @@
"centAmount": 9690,
"fractionDigits": 2
},
"totalTax": {
"type": "centPrecision",
"currencyCode": "EUR",
"centAmount": 1548,
"fractionDigits": 2
},
"taxPortions": [
{
"rate": 0.19,
Expand Down Expand Up @@ -311,6 +323,12 @@
"currencyCode": "EUR",
"centAmount": 3780,
"fractionDigits": 2
},
"totalTax": {
"type": "centPrecision",
"currencyCode": "EUR",
"centAmount": 604,
"fractionDigits": 2
}
},
"shippingMethodState": "MatchesCart"
Expand Down Expand Up @@ -370,6 +388,12 @@
"currencyCode": "EUR",
"centAmount": 4200,
"fractionDigits": 2
},
"totalTax": {
"type": "centPrecision",
"currencyCode": "EUR",
"centAmount": 671,
"fractionDigits": 2
}
}
}
Expand Down
32 changes: 28 additions & 4 deletions extension/test/unit/fixtures/ctp-cart.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"value": {
"type": "centPrecision",
"currencyCode": "EUR",
"centAmount": 1000,
"centAmount": 856,
"fractionDigits": 2
},
"id": "944f69af-6996-40ac-be82-9fead65e0e26"
Expand Down Expand Up @@ -197,13 +197,19 @@
"totalNet": {
"type": "centPrecision",
"currencyCode": "EUR",
"centAmount": 1437,
"centAmount": 1438,
"fractionDigits": 2
},
"totalGross": {
"type": "centPrecision",
"currencyCode": "EUR",
"centAmount": 1710,
"centAmount": 1711,
"fractionDigits": 2
},
"totalTax": {
"type": "centPrecision",
"currencyCode": "EUR",
"centAmount": 273,
"fractionDigits": 2
}
},
Expand All @@ -230,6 +236,12 @@
"centAmount": 8610,
"fractionDigits": 2
},
"totalTax": {
"type": "centPrecision",
"currencyCode": "EUR",
"centAmount": 1375,
"fractionDigits": 2
},
"taxPortions": [
{
"rate": 0.19,
Expand All @@ -248,7 +260,7 @@
"price": {
"type": "centPrecision",
"currencyCode": "EUR",
"centAmount": 3000,
"centAmount": 2700,
"fractionDigits": 2
},
"shippingRate": {
Expand Down Expand Up @@ -357,6 +369,12 @@
"currencyCode": "EUR",
"centAmount": 2700,
"fractionDigits": 2
},
"totalTax": {
"type": "centPrecision",
"currencyCode": "EUR",
"centAmount": 431,
"fractionDigits": 2
}
},
"shippingMethodState": "MatchesCart"
Expand Down Expand Up @@ -416,6 +434,12 @@
"currencyCode": "EUR",
"centAmount": 4200,
"fractionDigits": 2
},
"totalTax": {
"type": "centPrecision",
"currencyCode": "EUR",
"centAmount": 671,
"fractionDigits": 2
}
}
}
Expand Down

0 comments on commit a70215d

Please sign in to comment.