Skip to content

Commit

Permalink
Merge pull request #135 from epilot-dev/fix/resolve-undefined-cashbac…
Browse files Browse the repository at this point in the history
…k-period

Fix: add logic for required cashback period and amount
  • Loading branch information
JoFont authored Nov 19, 2024
2 parents 58e4151 + 2925041 commit d93033e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
8 changes: 4 additions & 4 deletions 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
9 changes: 5 additions & 4 deletions src/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!)
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit d93033e

Please sign in to comment.