Skip to content

Commit

Permalink
[CHK-1481] fix: update carts amount (#226)
Browse files Browse the repository at this point in the history
* [CHK-1481] fix: update cart amounts after payment activation

* [CHK-1481] fix: amount computation complexity
  • Loading branch information
MarcoAGreco authored Jun 16, 2023
1 parent 1332206 commit c1e1177
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/utils/api/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,33 @@ const activePaymentTask = (
let reason;
if (responseType.status === 200) {
reason = "";
const cartInfo = getSessionItem(SessionItems.cart) as
| Cart
| undefined;
if (cartInfo !== undefined) {
const rptIdAmountMap = new Map(
responseType.value.payments.map(
(p) => [p.rptId, p.amount] as [RptId, AmountEuroCents]
)
);

const updatedPaymentNotices = cartInfo.paymentNotices.map(
(paymentNotice) => {
const updatedAmount = rptIdAmountMap.get(
`${paymentNotice.fiscalCode}${paymentNotice.noticeNumber}` as RptId
);

return {
...paymentNotice,
amount: updatedAmount ?? paymentNotice.amount,
};
}
);
setSessionItem(SessionItems.cart, {
...cart,
paymentNotices: updatedPaymentNotices,
});
}
}
if (responseType.status === 400) {
reason = (
Expand Down

0 comments on commit c1e1177

Please sign in to comment.