Skip to content

Commit 115601d

Browse files
authored
fix(clerk-js): Checkout CTAs to not display payment of zero amount (#5720)
1 parent 3946fd3 commit 115601d

6 files changed

Lines changed: 34 additions & 13 deletions

File tree

.changeset/upset-webs-stand.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/types': patch
3+
---
4+
5+
Update `checkout.totals.totalDueNow` to always be defined.

.changeset/witty-bikes-relate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Update the text in Checkout buttons from "Pay $0" to "Subscribe".

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ const CheckoutFormElements = ({
169169
<PaymentSourceMethods
170170
checkout={checkout}
171171
paymentSources={paymentSources}
172-
totalDueNow={checkout.totals.totalDueNow || checkout.totals.grandTotal}
172+
totalDueNow={checkout.totals.totalDueNow}
173173
onPaymentSourceSubmit={onPaymentSourceSubmit}
174174
isSubmitting={isSubmitting}
175175
/>
@@ -192,12 +192,17 @@ const CheckoutFormElements = ({
192192
<AddPaymentSource
193193
checkout={checkout}
194194
onSuccess={onAddPaymentSourceSuccess}
195-
submitLabel={localizationKeys(
196-
'userProfile.__experimental_billingPage.paymentSourcesSection.formButtonPrimary__pay',
197-
{
198-
amount: `${(checkout.totals.totalDueNow || checkout.totals.grandTotal).currencySymbol}${(checkout.totals.totalDueNow || checkout.totals.grandTotal).amountFormatted}`,
199-
},
200-
)}
195+
// @ts-ignore TODO(@COMMERCE): needs localization
196+
submitLabel={
197+
checkout.totals.totalDueNow.amount > 0
198+
? localizationKeys(
199+
'userProfile.__experimental_billingPage.paymentSourcesSection.formButtonPrimary__pay',
200+
{
201+
amount: `${checkout.totals.totalDueNow.currencySymbol}${checkout.totals.totalDueNow.amountFormatted}`,
202+
},
203+
)
204+
: 'Subscribe'
205+
}
201206
/>
202207
</__experimental_PaymentSourcesContext.Provider>
203208
</Disclosure.Content>
@@ -283,9 +288,15 @@ const PaymentSourceMethods = ({
283288
}}
284289
isLoading={isSubmitting}
285290
>
286-
{/* TODO(@COMMERCE): needs localization */}
287-
Pay {totalDueNow.currencySymbol}
288-
{totalDueNow.amountFormatted}
291+
{totalDueNow.amount > 0 ? (
292+
<>
293+
{/* TODO(@COMMERCE): needs localization */}
294+
Pay {totalDueNow.currencySymbol}
295+
{totalDueNow.amountFormatted}
296+
</>
297+
) : (
298+
'Subscribe'
299+
)}
289300
</Button>
290301
</Form>
291302
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ export const commerceTotalsFromJSON = (data: __experimental_CommerceTotalsJSON):
1919
grandTotal: commerceMoneyFromJSON(data.grand_total),
2020
subtotal: commerceMoneyFromJSON(data.subtotal),
2121
taxTotal: commerceMoneyFromJSON(data.tax_total),
22-
totalDueNow: data.total_due_now ? commerceMoneyFromJSON(data.total_due_now) : undefined,
22+
totalDueNow: commerceMoneyFromJSON(data.total_due_now),
2323
};
2424
};

packages/types/src/commerce.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export interface __experimental_CommerceTotals {
146146
subtotal: __experimental_CommerceMoney;
147147
grandTotal: __experimental_CommerceMoney;
148148
taxTotal: __experimental_CommerceMoney;
149-
totalDueNow?: __experimental_CommerceMoney;
149+
totalDueNow: __experimental_CommerceMoney;
150150
}
151151

152152
export type __experimental_CreateCheckoutParams = WithOptionalOrgType<{

packages/types/src/json.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ export interface __experimental_CommerceTotalsJSON {
674674
grand_total: __experimental_CommerceMoneyJSON;
675675
subtotal: __experimental_CommerceMoneyJSON;
676676
tax_total: __experimental_CommerceMoneyJSON;
677-
total_due_now?: __experimental_CommerceMoneyJSON;
677+
total_due_now: __experimental_CommerceMoneyJSON;
678678
}
679679

680680
export interface __experimental_CommerceCheckoutJSON extends ClerkResourceJSON {

0 commit comments

Comments
 (0)