diff --git a/package-lock.json b/package-lock.json index cde9c02..195fe2f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "4.44.0", "license": "UNLICENSED", "dependencies": { - "@epilot/pricing-client": "^3.35.15", + "@epilot/pricing-client": "^3.35.17", "@types/dinero.js": "^1.9.0", "dinero.js": "^1.9.1" }, @@ -825,9 +825,9 @@ } }, "node_modules/@epilot/pricing-client": { - "version": "3.35.15", - "resolved": "https://registry.npmjs.org/@epilot/pricing-client/-/pricing-client-3.35.15.tgz", - "integrity": "sha512-klS4anO4I4ygBR/c6T18cl+LzJUkhVchrE1UGhK2e4GgZr0jvnsdteWoUgXuO2+UP4CmaC1bXFdufN1IpRlX0w==", + "version": "3.35.17", + "resolved": "https://registry.npmjs.org/@epilot/pricing-client/-/pricing-client-3.35.17.tgz", + "integrity": "sha512-Zs7S0rLAeOaTs6pHtC/87SO22xev1b86DOcY4L4jJf8nO/oiYziPqNcqeW2hHKSJiehf70jn3X0c/J2RrTRJiQ==", "dependencies": { "@dazn/lambda-powertools-correlation-ids": "^1.28.1", "buffer": "^6.0.3", diff --git a/package.json b/package.json index 26bc0c4..caae596 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "author": "epilot GmbH", "license": "UNLICENSED", "dependencies": { - "@epilot/pricing-client": "^3.35.15", + "@epilot/pricing-client": "^3.35.17", "@types/dinero.js": "^1.9.0", "dinero.js": "^1.9.1" }, diff --git a/src/pricing.ts b/src/pricing.ts index bf469b8..563429d 100644 --- a/src/pricing.ts +++ b/src/pricing.ts @@ -453,6 +453,8 @@ const recomputeDetailTotals = ( typeof priceItemToAppend.cashback_amount !== 'undefined' ? toDineroFromInteger(priceItemToAppend.cashback_amount!) : undefined; + + const cashbackPeriod = priceItemToAppend.cashback_period; const priceBeforeDiscountAmountTotal = typeof priceItemToAppend.before_discount_amount_total !== 'undefined' ? toDineroFromInteger(priceItemToAppend.before_discount_amount_total!) @@ -564,13 +566,12 @@ const recomputeDetailTotals = ( } // Cashback totals - if (priceCashBackAmount) { - const cashbackPeriod = priceItemToAppend.cashback_period; + if (priceCashBackAmount && cashbackPeriod !== undefined) { const cashbackMatchIndex = cashbacks.findIndex((cashback) => cashback.cashback_period === cashbackPeriod); if (cashbackMatchIndex !== -1) { - const matchingCashback = cashbacks[cashbackMatchIndex]!; - const cashbackAmountTotal = toDineroFromInteger(matchingCashback.amount_total!); + const matchingCashback = cashbacks[cashbackMatchIndex]; + const cashbackAmountTotal = toDineroFromInteger(matchingCashback.amount_total); matchingCashback.amount_total = cashbackAmountTotal.add(priceCashBackAmount).getAmount(); } else { cashbacks.push({