Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/all-tigers-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': patch
'@clerk/types': patch
---

Move `credit` at the top-level and remove `proration` property
7 changes: 2 additions & 5 deletions packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ export const CheckoutForm = ({
onCheckoutComplete: (checkout: CommerceCheckoutResource) => void;
}) => {
const { plan, planPeriod, totals, isImmediatePlanChange } = checkout;
const showCredits =
totals.totalDueNow.amount > 0 && !!totals.proration?.credit?.amount && totals.proration.credit.amount > 0;
const showCredits = !!totals.credit?.amount && totals.credit.amount > 0;
const showDowngradeInfo = !isImmediatePlanChange;

return (
Expand Down Expand Up @@ -69,9 +68,7 @@ export const CheckoutForm = ({
<LineItems.Title title={'Credit for the remainder of your current subscription.'} />
{/* TODO(@Commerce): needs localization */}
{/* TODO(@Commerce): Replace client-side calculation with server-side calculation once data are available in the response */}
<LineItems.Description
text={`- ${totals.proration?.credit.currencySymbol}${totals.proration?.credit.amountFormatted}`}
/>
<LineItems.Description text={`- ${totals.credit?.currencySymbol}${totals.credit?.amountFormatted}`} />
</LineItems.Group>
)}
<LineItems.Group borderTop>
Expand Down
7 changes: 2 additions & 5 deletions packages/clerk-js/src/utils/commerce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ export const commerceTotalsFromJSON = <T extends CommerceInvoiceTotalsJSON | Com
// @ts-ignore
totals['totalDueNow'] = commerceMoneyFromJSON(data.total_due_now);
}
if ('proration' in data) {
if ('credit' in data) {
// @ts-ignore
totals['proration'] = {
// @ts-ignore
credit: commerceMoneyFromJSON(data.proration.credit),
};
totals['credit'] = commerceMoneyFromJSON(data.credit);
}

return totals as T extends { total_due_now: CommerceMoneyJSON } ? CommerceCheckoutTotals : CommerceInvoiceTotals;
Expand Down
4 changes: 1 addition & 3 deletions packages/types/src/commerce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ export interface CommerceCheckoutTotals {
grandTotal: CommerceMoney;
taxTotal: CommerceMoney;
totalDueNow: CommerceMoney;
proration?: {
credit: CommerceMoney;
};
credit: CommerceMoney;
}

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
Expand Down
6 changes: 1 addition & 5 deletions packages/types/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,11 +673,7 @@ export interface CommerceCheckoutTotalsJSON {
subtotal: CommerceMoneyJSON;
tax_total: CommerceMoneyJSON;
total_due_now: CommerceMoneyJSON;
proration?: {
days: number;
rate_per_day: CommerceMoneyJSON;
total_proration: CommerceMoneyJSON;
};
credit: CommerceMoneyJSON;
}

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