Skip to content

fix(clerk-js): Checkout CTAs to not display payment of zero amount #5720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/upset-webs-stand.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/types': patch
---

Update `checkout.totals.totalDueNow` to always be defined.
5 changes: 5 additions & 0 deletions .changeset/witty-bikes-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Update the text in Checkout buttons from "Pay $0" to "Subscribe".
31 changes: 21 additions & 10 deletions packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const CheckoutFormElements = ({
<PaymentSourceMethods
checkout={checkout}
paymentSources={paymentSources}
totalDueNow={checkout.totals.totalDueNow || checkout.totals.grandTotal}
totalDueNow={checkout.totals.totalDueNow}
onPaymentSourceSubmit={onPaymentSourceSubmit}
isSubmitting={isSubmitting}
/>
Expand All @@ -192,12 +192,17 @@ const CheckoutFormElements = ({
<AddPaymentSource
checkout={checkout}
onSuccess={onAddPaymentSourceSuccess}
submitLabel={localizationKeys(
'userProfile.__experimental_billingPage.paymentSourcesSection.formButtonPrimary__pay',
{
amount: `${(checkout.totals.totalDueNow || checkout.totals.grandTotal).currencySymbol}${(checkout.totals.totalDueNow || checkout.totals.grandTotal).amountFormatted}`,
},
)}
// @ts-ignore TODO(@COMMERCE): needs localization
submitLabel={
checkout.totals.totalDueNow.amount > 0
? localizationKeys(
'userProfile.__experimental_billingPage.paymentSourcesSection.formButtonPrimary__pay',
{
amount: `${checkout.totals.totalDueNow.currencySymbol}${checkout.totals.totalDueNow.amountFormatted}`,
},
)
: 'Subscribe'
}
/>
</__experimental_PaymentSourcesContext.Provider>
</Disclosure.Content>
Expand Down Expand Up @@ -283,9 +288,15 @@ const PaymentSourceMethods = ({
}}
isLoading={isSubmitting}
>
{/* TODO(@COMMERCE): needs localization */}
Pay {totalDueNow.currencySymbol}
{totalDueNow.amountFormatted}
{totalDueNow.amount > 0 ? (
<>
{/* TODO(@COMMERCE): needs localization */}
Pay {totalDueNow.currencySymbol}
{totalDueNow.amountFormatted}
</>
) : (
'Subscribe'
)}
</Button>
</Form>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/clerk-js/src/utils/commerce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export const commerceTotalsFromJSON = (data: __experimental_CommerceTotalsJSON):
grandTotal: commerceMoneyFromJSON(data.grand_total),
subtotal: commerceMoneyFromJSON(data.subtotal),
taxTotal: commerceMoneyFromJSON(data.tax_total),
totalDueNow: data.total_due_now ? commerceMoneyFromJSON(data.total_due_now) : undefined,
totalDueNow: commerceMoneyFromJSON(data.total_due_now),
};
};
2 changes: 1 addition & 1 deletion packages/types/src/commerce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export interface __experimental_CommerceTotals {
subtotal: __experimental_CommerceMoney;
grandTotal: __experimental_CommerceMoney;
taxTotal: __experimental_CommerceMoney;
totalDueNow?: __experimental_CommerceMoney;
totalDueNow: __experimental_CommerceMoney;
}

export type __experimental_CreateCheckoutParams = WithOptionalOrgType<{
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ export interface __experimental_CommerceTotalsJSON {
grand_total: __experimental_CommerceMoneyJSON;
subtotal: __experimental_CommerceMoneyJSON;
tax_total: __experimental_CommerceMoneyJSON;
total_due_now?: __experimental_CommerceMoneyJSON;
total_due_now: __experimental_CommerceMoneyJSON;
}

export interface __experimental_CommerceCheckoutJSON extends ClerkResourceJSON {
Expand Down