Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #7 from toasttab/LGC-1806_partial_redeem_adjust_am…
Browse files Browse the repository at this point in the history
…ount

LGC-1806: Store correct amount with partial redeem
  • Loading branch information
konradgorski-toast authored Jul 20, 2022
2 parents 61e655d + 003d010 commit 33a81de
Show file tree
Hide file tree
Showing 4 changed files with 1,677 additions and 567 deletions.
12 changes: 9 additions & 3 deletions cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ function getBalance(identifier) {
function redeem(transactionGuid, identifier, amount) {
var card = find(identifier);
if(!card['active']) throw "ERROR_CARD_NOT_ACTIVATED";
var requestedAmount = parseFloat(amount);
var origBalance = parseFloat(card['balance']);
var balance = origBalance - parseFloat(amount);
if (balance < 0.0) balance = 0.0;
var balance = origBalance - requestedAmount;
if (balance < 0.0) {
var actualAmount = origBalance;
balance = 0.0;
} else {
var actualAmount = requestedAmount;
}
card['balance'] = balance.toFixed(2);
transactions.create('redeem', transactionGuid, identifier, amount);
transactions.create('redeem', transactionGuid, identifier, actualAmount);
return update(card);
}

Expand Down
Loading

0 comments on commit 33a81de

Please sign in to comment.