Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 469
chore(clerk-js,types): Update checkout flow to support free trials#6494
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
panteliselef
merged 28 commits into
main
from
elef/com-1123-update-checkout-flow-to-support-free-trialsAug 13, 2025
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
b228074
chore(clerk-js,types): Update PricingTable with trial info
panteliselef 9eda6fa
chore(clerk-js,types): Update checkout to handle trials
panteliselef 1c6b47c
chore(clerk-js,types): Update checkout to handle trials
panteliselef e729316
handle checkout confirming step
panteliselef 0388c4a
respect fapi
panteliselef 11e6953
add tests
panteliselef 1cb9c20
Merge branch 'refs/heads/main' into elef/com-1121-update-pricingtable…
panteliselef 4b3d116
patch
panteliselef 13f3e53
add localizations
panteliselef eb68681
patch type in react test
panteliselef ae0d7e6
Merge branch 'main' into elef/com-1121-update-pricingtable-plan-card-…
panteliselef 252f581
Merge branch 'refs/heads/main' into elef/com-1123-update-checkout-flo…
panteliselef c01e7bb
Merge branch 'elef/com-1121-update-pricingtable-plan-card-with-free-t…
panteliselef 4fe6457
handle conflicts
panteliselef 9505525
Merge branch 'main' into elef/com-1123-update-checkout-flow-to-suppor…
panteliselef 7c875ab
address duplicate
panteliselef f35f64c
handle localizations
panteliselef 4122331
address review
panteliselef afc4836
add checkout tests
panteliselef cfa14a1
Merge branch 'main' into elef/com-1123-update-checkout-flow-to-suppor…
panteliselef bac7ba5
revert localization key changes
panteliselef 14a1c1b
bump bundlewatch.config.json
panteliselef 4a877c4
fix tests
panteliselef bbf4534
mock to avoid logging errors
panteliselef f71b276
add changeset
panteliselef fa5a912
Merge branch 'main' into elef/com-1123-update-checkout-flow-to-suppor…
panteliselef 7962c84
Merge branch 'main' into elef/com-1123-update-checkout-flow-to-suppor…
panteliselef 972b353
bump bundlewatch.config.json
panteliselef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| '@clerk/localizations': minor | ||
| '@clerk/clerk-js': minor | ||
| '@clerk/shared': minor | ||
| '@clerk/types': minor | ||
| --- | ||
| Add support for trials in `<Checkout/>` | ||
| - Added `freeTrialEndsAt` property to `CommerceCheckoutResource` interface. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 15 additions & 6 deletions
21 packages/clerk-js/src/ui/components/Checkout/CheckoutComplete.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 50 additions & 27 deletions
77 packages/clerk-js/src/ui/components/Checkout/CheckoutForm.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -17,6 +17,7 @@ import { Box, Button, Col, descriptors, Flex, Form, localizationKeys, Text } fro | ||
| import { ChevronUpDown, InformationCircle } from '../../icons'; | ||
| import * as AddPaymentSource from '../PaymentSources/AddPaymentSource'; | ||
| import { PaymentSourceRow } from '../PaymentSources/PaymentSourceRow'; | ||
| import { SubscriptionBadge } from '../Subscriptions/badge'; | ||
| type PaymentMethodSource = 'existing' | 'new'; | ||
| @@ -25,7 +26,7 @@ const capitalize = (name: string) => name[0].toUpperCase() + name.slice(1); | ||
| export const CheckoutForm = withCardStateProvider(() => { | ||
| const { checkout } = useCheckout(); | ||
| const { id, plan, totals, isImmediatePlanChange, planPeriod } = checkout; | ||
| const { id, plan, totals, isImmediatePlanChange, planPeriod, freeTrialEndsAt } = checkout; | ||
| if (!id) { | ||
| return null; | ||
| @@ -53,6 +54,11 @@ export const CheckoutForm = withCardStateProvider(() => { | ||
| <LineItems.Title | ||
| title={plan.name} | ||
| description={planPeriod === 'annual' ? localizationKeys('commerce.billedAnnually') : undefined} | ||
| badge={ | ||
| plan.freeTrialEnabled && freeTrialEndsAt ? ( | ||
| <SubscriptionBadge subscription={{ status: 'free_trial' }} /> | ||
| ) : null | ||
| } | ||
| /> | ||
| <LineItems.Description | ||
| prefix={planPeriod === 'annual' ? 'x12' : undefined} | ||
| @@ -87,6 +93,20 @@ export const CheckoutForm = withCardStateProvider(() => { | ||
| <LineItems.Description text={`${totals.pastDue?.currencySymbol}${totals.pastDue?.amountFormatted}`} /> | ||
| </LineItems.Group> | ||
| )} | ||
| {!!freeTrialEndsAt && !!plan.freeTrialDays && ( | ||
| <LineItems.Group variant='tertiary'> | ||
| <LineItems.Title | ||
| title={localizationKeys('commerce.checkout.totalDueAfterTrial', { | ||
| days: plan.freeTrialDays, | ||
| })} | ||
| /> | ||
| <LineItems.Description | ||
| text={`${totals.grandTotal?.currencySymbol}${totals.grandTotal?.amountFormatted}`} | ||
| /> | ||
| </LineItems.Group> | ||
| )} | ||
| <LineItems.Group borderTop> | ||
| <LineItems.Title title={localizationKeys('commerce.totalDueToday')} /> | ||
| <LineItems.Description text={`${totals.totalDueNow.currencySymbol}${totals.totalDueNow.amountFormatted}`} /> | ||
| @@ -278,15 +298,32 @@ export const PayWithTestPaymentSource = () => { | ||
| ); | ||
| }; | ||
| const AddPaymentSourceForCheckout = withCardStateProvider(() => { | ||
| const { addPaymentSourceAndPay } = useCheckoutMutations(); | ||
| const useSubmitLabel = () => { | ||
| const { checkout } = useCheckout(); | ||
| const { status, totals } = checkout; | ||
| const { status, freeTrialEndsAt, totals } = checkout; | ||
| if (status === 'needs_initialization') { | ||
| return null; | ||
| throw new Error('Clerk: Invalid state'); | ||
| } | ||
| if (freeTrialEndsAt) { | ||
| return localizationKeys('commerce.startFreeTrial'); | ||
| } | ||
| if (totals.totalDueNow.amount > 0) { | ||
| return localizationKeys('commerce.pay', { | ||
| amount: `${totals.totalDueNow.currencySymbol}${totals.totalDueNow.amountFormatted}`, | ||
| }); | ||
| } | ||
| return localizationKeys('commerce.subscribe'); | ||
| }; | ||
panteliselef marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const AddPaymentSourceForCheckout = withCardStateProvider(() => { | ||
| const { addPaymentSourceAndPay } = useCheckoutMutations(); | ||
| const submitLabel = useSubmitLabel(); | ||
| const { checkout } = useCheckout(); | ||
| return ( | ||
| <AddPaymentSource.Root | ||
| onSuccess={addPaymentSourceAndPay} | ||
| @@ -296,15 +333,7 @@ const AddPaymentSourceForCheckout = withCardStateProvider(() => { | ||
| <PayWithTestPaymentSource /> | ||
| </DevOnly> | ||
| {totals.totalDueNow.amount > 0 ? ( | ||
| <AddPaymentSource.FormButton | ||
| text={localizationKeys('commerce.pay', { | ||
| amount: `${totals.totalDueNow.currencySymbol}${totals.totalDueNow.amountFormatted}`, | ||
| })} | ||
| /> | ||
| ) : ( | ||
| <AddPaymentSource.FormButton text={localizationKeys('commerce.subscribe')} /> | ||
| )} | ||
| <AddPaymentSource.FormButton text={submitLabel} /> | ||
| </AddPaymentSource.Root> | ||
| ); | ||
| }); | ||
| @@ -317,8 +346,9 @@ const ExistingPaymentSourceForm = withCardStateProvider( | ||
| totalDueNow: CommerceMoneyAmount; | ||
| paymentSources: CommercePaymentSourceResource[]; | ||
| }) => { | ||
| const submitLabel = useSubmitLabel(); | ||
| const { checkout } = useCheckout(); | ||
| const { paymentSource } = checkout; | ||
| const { paymentSource, freeTrialEndsAt } = checkout; | ||
| const { payWithExistingPaymentSource } = useCheckoutMutations(); | ||
| const card = useCardState(); | ||
| @@ -340,6 +370,8 @@ const ExistingPaymentSourceForm = withCardStateProvider( | ||
| }); | ||
| }, [paymentSources]); | ||
| const isSchedulePayment = totalDueNow.amount > 0 && !freeTrialEndsAt; | ||
| return ( | ||
| <Form | ||
| onSubmit={payWithExistingPaymentSource} | ||
| @@ -349,7 +381,7 @@ const ExistingPaymentSourceForm = withCardStateProvider( | ||
| rowGap: t.space.$4, | ||
| })} | ||
| > | ||
| {totalDueNow.amount > 0 ? ( | ||
| {isSchedulePayment ? ( | ||
| <Select | ||
| elementId='paymentSource' | ||
| options={options} | ||
| @@ -399,17 +431,8 @@ const ExistingPaymentSourceForm = withCardStateProvider( | ||
| width: '100%', | ||
| }} | ||
| isLoading={card.isLoading} | ||
| > | ||
| <Text | ||
| localizationKey={ | ||
| totalDueNow.amount > 0 | ||
| ? localizationKeys('commerce.pay', { | ||
| amount: `${totalDueNow.currencySymbol}${totalDueNow.amountFormatted}`, | ||
| }) | ||
| : localizationKeys('commerce.subscribe') | ||
| } | ||
| /> | ||
| </Button> | ||
| localizationKey={submitLabel} | ||
| /> | ||
| </Form> | ||
| ); | ||
| }, | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.