Skip to content

Commit

Permalink
Merge branch 'master' into CR-SET-09
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijaIv committed Jan 25, 2024
2 parents d6cdb72 + a70215d commit 84e2898
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
with:
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
- name: gcloud sdk
uses: google-github-actions/setup-gcloud@v2.0.1
uses: google-github-actions/setup-gcloud@v2.1.0
- run: npm run unit
- name: gcloud functions deploy
run: |
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
with:
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
- name: gcloud sdk
uses: google-github-actions/setup-gcloud@v2.0.1
uses: google-github-actions/setup-gcloud@v2.1.0
- name: gcloud functions deploy
run: |
gcloud functions deploy extension-ci \
Expand Down
14 changes: 7 additions & 7 deletions extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"localtunnel": "2.0.2",
"mocha": "10.2.0",
"nock": "13.5.0",
"prettier": "3.2.3",
"prettier": "3.2.4",
"proxyquire": "2.1.3",
"puppeteer": "21.7.0",
"sinon": "17.0.1",
Expand Down
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
14 changes: 7 additions & 7 deletions notification/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion notification/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"mocha": "10.2.0",
"nock": "13.5.0",
"p-map": "7.0.1",
"prettier": "3.2.3",
"prettier": "3.2.4",
"sinon": "17.0.1",
"c8": "8.0.1"
},
Expand Down
9 changes: 5 additions & 4 deletions notification/src/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ function getAllAdyenMerchantAccounts() {

function getAdyenPaymentMethodsToNames() {
return {
scheme: 'Credit Card',
pp: 'PayPal',
klarna: 'Klarna',
gpay: 'Google Pay',
scheme: { en: 'Credit Card' },
pp: { en: 'PayPal' },
klarna: { en: 'Klarna' },
affirm: { en: 'Affirm' },
gpay: { en: 'Google Pay' },
...(config.adyenPaymentMethodsToNames || {}),
}
}
Expand Down

0 comments on commit 84e2898

Please sign in to comment.