Skip to content

Commit db0138f

Browse files
authored
refactor(clerk-js): Move credit out of proration object (#5849)
1 parent 527def8 commit db0138f

File tree

5 files changed

+12
-18
lines changed

5 files changed

+12
-18
lines changed

.changeset/all-tigers-learn.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
'@clerk/types': patch
4+
---
5+
6+
Move `credit` at the top-level and remove `proration` property

packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ export const CheckoutForm = ({
3131
onCheckoutComplete: (checkout: CommerceCheckoutResource) => void;
3232
}) => {
3333
const { plan, planPeriod, totals, isImmediatePlanChange } = checkout;
34-
const showCredits =
35-
totals.totalDueNow.amount > 0 && !!totals.proration?.credit?.amount && totals.proration.credit.amount > 0;
34+
const showCredits = !!totals.credit?.amount && totals.credit.amount > 0;
3635
const showDowngradeInfo = !isImmediatePlanChange;
3736

3837
return (
@@ -69,9 +68,7 @@ export const CheckoutForm = ({
6968
<LineItems.Title title={'Credit for the remainder of your current subscription.'} />
7069
{/* TODO(@Commerce): needs localization */}
7170
{/* TODO(@Commerce): Replace client-side calculation with server-side calculation once data are available in the response */}
72-
<LineItems.Description
73-
text={`- ${totals.proration?.credit.currencySymbol}${totals.proration?.credit.amountFormatted}`}
74-
/>
71+
<LineItems.Description text={`- ${totals.credit?.currencySymbol}${totals.credit?.amountFormatted}`} />
7572
</LineItems.Group>
7673
)}
7774
<LineItems.Group borderTop>

packages/clerk-js/src/utils/commerce.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ export const commerceTotalsFromJSON = <T extends CommerceInvoiceTotalsJSON | Com
2626
// @ts-ignore
2727
totals['totalDueNow'] = commerceMoneyFromJSON(data.total_due_now);
2828
}
29-
if ('proration' in data) {
29+
if ('credit' in data) {
3030
// @ts-ignore
31-
totals['proration'] = {
32-
// @ts-ignore
33-
credit: commerceMoneyFromJSON(data.proration.credit),
34-
};
31+
totals['credit'] = commerceMoneyFromJSON(data.credit);
3532
}
3633

3734
return totals as T extends { total_due_now: CommerceMoneyJSON } ? CommerceCheckoutTotals : CommerceInvoiceTotals;

packages/types/src/commerce.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ export interface CommerceCheckoutTotals {
141141
grandTotal: CommerceMoney;
142142
taxTotal: CommerceMoney;
143143
totalDueNow: CommerceMoney;
144-
proration?: {
145-
credit: CommerceMoney;
146-
};
144+
credit: CommerceMoney;
147145
}
148146

149147
// eslint-disable-next-line @typescript-eslint/no-empty-object-type

packages/types/src/json.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -673,11 +673,7 @@ export interface CommerceCheckoutTotalsJSON {
673673
subtotal: CommerceMoneyJSON;
674674
tax_total: CommerceMoneyJSON;
675675
total_due_now: CommerceMoneyJSON;
676-
proration?: {
677-
days: number;
678-
rate_per_day: CommerceMoneyJSON;
679-
total_proration: CommerceMoneyJSON;
680-
};
676+
credit: CommerceMoneyJSON;
681677
}
682678

683679
// eslint-disable-next-line @typescript-eslint/no-empty-object-type

0 commit comments

Comments
 (0)