Skip to content

Commit ec207dc

Browse files
authored
chore(clerk-js, shared): Create experimental PaymentElement (#6180)
1 parent f48b883 commit ec207dc

File tree

27 files changed

+1080
-202
lines changed

27 files changed

+1080
-202
lines changed

.changeset/great-bees-teach.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/chrome-extension': patch
3+
---
4+
5+
Refactor re-exports from `@clerk/clerk-react`.

.changeset/happy-kiwis-peel.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@clerk/nextjs': minor
3+
'@clerk/clerk-react': minor
4+
'@clerk/shared': minor
5+
---
6+
7+
Export experimental hooks and components for PaymentElement
8+
- `__experimental_usePaymentElement`
9+
- `__experimental_PaymentElementProvider`
10+
- `__experimental_PaymentElement`

.changeset/hot-seas-rhyme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': minor
3+
---
4+
5+
Remove `@stripe/react-stripe-js` dependency and only allow loading of stripe-js via `Clerk.__internal_loadStripeJs()`.

.changeset/many-mirrors-vanish.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@clerk/tanstack-react-start': minor
3+
'@clerk/react-router': minor
4+
'@clerk/remix': minor
5+
---
6+
7+
Export experimental hooks and components for PaymentElement
8+
- `__experimental_usePaymentElement`
9+
- `__experimental_PaymentElementProvider`
10+
- `__experimental_PaymentElement`

.changeset/olive-streets-fall.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/types': minor
3+
---
4+
5+
Add `__internal_loadStripeJs` in Clerk interface.

packages/clerk-js/bundlewatch.config.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
{ "path": "./dist/clerk.browser.js", "maxSize": "72.2KB" },
55
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "115KB" },
66
{ "path": "./dist/clerk.headless*.js", "maxSize": "55KB" },
7-
{ "path": "./dist/ui-common*.js", "maxSize": "110KB" },
7+
{ "path": "./dist/ui-common*.js", "maxSize": "111.8KB" },
88
{ "path": "./dist/vendors*.js", "maxSize": "40.2KB" },
99
{ "path": "./dist/coinbase*.js", "maxSize": "38KB" },
10+
{ "path": "./dist/stripe-vendors*.js", "maxSize": "1KB" },
1011
{ "path": "./dist/createorganization*.js", "maxSize": "5KB" },
1112
{ "path": "./dist/impersonationfab*.js", "maxSize": "5KB" },
1213
{ "path": "./dist/organizationprofile*.js", "maxSize": "10KB" },
@@ -21,9 +22,8 @@
2122
{ "path": "./dist/waitlist*.js", "maxSize": "1.5KB" },
2223
{ "path": "./dist/keylessPrompt*.js", "maxSize": "6.5KB" },
2324
{ "path": "./dist/pricingTable*.js", "maxSize": "4.02KB" },
24-
{ "path": "./dist/checkout*.js", "maxSize": "7.3KB" },
25-
{ "path": "./dist/paymentSources*.js", "maxSize": "9.17KB" },
26-
{ "path": "./dist/up-billing-page*.js", "maxSize": "3.5KB" },
25+
{ "path": "./dist/checkout*.js", "maxSize": "8.34KB" },
26+
{ "path": "./dist/up-billing-page*.js", "maxSize": "3.0KB" },
2727
{ "path": "./dist/op-billing-page*.js", "maxSize": "3.0KB" },
2828
{ "path": "./dist/up-plans-page*.js", "maxSize": "1.0KB" },
2929
{ "path": "./dist/op-plans-page*.js", "maxSize": "1.0KB" },

packages/clerk-js/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
"@floating-ui/react": "0.27.12",
7070
"@floating-ui/react-dom": "^2.1.3",
7171
"@formkit/auto-animate": "^0.8.2",
72-
"@stripe/react-stripe-js": "3.1.1",
7372
"@stripe/stripe-js": "5.6.0",
7473
"@swc/helpers": "^0.5.17",
7574
"@zxcvbn-ts/core": "3.0.4",

packages/clerk-js/rspack.config.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const common = ({ mode, variant, disableRHC = false }) => {
8181
* Necessary to prevent the Stripe dependencies from being bundled into
8282
* SDKs such as Browser Extensions.
8383
*/
84+
// TODO: @COMMERCE: Do we still need this?
8485
externals: disableRHC ? ['@stripe/stripe-js', '@stripe/react-stripe-js'] : undefined,
8586
optimization: {
8687
splitChunks: {
@@ -100,6 +101,12 @@ const common = ({ mode, variant, disableRHC = false }) => {
100101
name: 'coinbase-wallet-sdk',
101102
chunks: 'all',
102103
},
104+
stripeVendor: {
105+
test: /[\\/]node_modules[\\/](@stripe\/stripe-js)[\\/]/,
106+
name: 'stripe-vendors',
107+
chunks: 'all',
108+
enforce: true,
109+
},
103110
/**
104111
* Sign up is shared between the SignUp component and the SignIn component.
105112
*/
@@ -108,17 +115,6 @@ const common = ({ mode, variant, disableRHC = false }) => {
108115
name: 'signup',
109116
test: module => !!(module.resource && module.resource.includes('/ui/components/SignUp')),
110117
},
111-
paymentSources: {
112-
minChunks: 1,
113-
name: 'paymentSources',
114-
test: module =>
115-
!!(
116-
module.resource &&
117-
(module.resource.includes('/ui/components/PaymentSources') ||
118-
// Include `@stripe/react-stripe-js` and `@stripe/stripe-js` in the checkout chunk
119-
module.resource.includes('/node_modules/@stripe'))
120-
),
121-
},
122118
common: {
123119
minChunks: 1,
124120
name: 'ui-common',

packages/clerk-js/src/core/clerk.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,16 @@ export class Clerk implements ClerkInterface {
645645
.then(controls => controls.closeModal('blankCaptcha'));
646646
};
647647

648+
public __internal_loadStripeJs = async () => {
649+
if (__BUILD_DISABLE_RHC__) {
650+
clerkUnsupportedEnvironmentWarning('Stripe');
651+
return { loadStripe: () => Promise.resolve(null) };
652+
}
653+
654+
const { loadStripe } = await import('@stripe/stripe-js');
655+
return loadStripe;
656+
};
657+
648658
public openSignUp = (props?: SignUpProps): void => {
649659
this.assertComponentsReady(this.#componentControls);
650660
if (sessionExistsAndSingleSessionModeEnabled(this, this.environment)) {

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type {
55
CommercePaymentSourceResource,
66
ConfirmCheckoutParams,
77
} from '@clerk/types';
8-
import type { SetupIntent } from '@stripe/stripe-js';
98
import { useMemo, useState } from 'react';
109

1110
import { Card } from '@/ui/elements/Card';
@@ -146,25 +145,18 @@ const useCheckoutMutations = () => {
146145
}
147146
};
148147

149-
const payWithExistingPaymentSource = async (e: React.FormEvent<HTMLFormElement>) => {
148+
const payWithExistingPaymentSource = (e: React.FormEvent<HTMLFormElement>) => {
150149
e.preventDefault();
151150

152151
const data = new FormData(e.currentTarget);
153152
const paymentSourceId = data.get('payment_source_id') as string;
154153

155-
await confirmCheckout({
154+
return confirmCheckout({
156155
paymentSourceId,
157-
...(subscriberType === 'org' ? { orgId: organization?.id } : {}),
158156
});
159157
};
160158

161-
const addPaymentSourceAndPay = async (ctx: { stripeSetupIntent?: SetupIntent }) => {
162-
await confirmCheckout({
163-
gateway: 'stripe',
164-
paymentToken: ctx.stripeSetupIntent?.payment_method as string,
165-
...(subscriberType === 'org' ? { orgId: organization?.id } : {}),
166-
});
167-
};
159+
const addPaymentSourceAndPay = (ctx: { gateway: 'stripe'; paymentToken: string }) => confirmCheckout(ctx);
168160

169161
const payWithTestCard = async () => {
170162
card.setLoading();

0 commit comments

Comments
 (0)