Skip to content

WIP commerce custom flows #6200

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
9 changes: 9 additions & 0 deletions .changeset/stale-pillows-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@clerk/clerk-js': minor
'@clerk/nextjs': minor
'@clerk/shared': minor
'@clerk/clerk-react': minor
'@clerk/types': minor
---

wip
8 changes: 8 additions & 0 deletions .changeset/twelve-yaks-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@clerk/clerk-js': minor
'@clerk/shared': minor
'@clerk/clerk-react': minor
'@clerk/types': minor
---

wip
4 changes: 3 additions & 1 deletion integration/tests/pricing-table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withBilling] })('pricing tabl
});
await u.po.checkout.clickPayOrSubscribe();
await expect(u.po.page.locator('.cl-checkout-root').getByText('The card was declined.').first()).toBeVisible();
await u.po.checkout.waitForStipeElements();
// It should unmount and remount the payment element
await u.po.checkout.waitForStipeElements({ state: 'hidden' });
await u.po.checkout.waitForStipeElements({ state: 'visible' });
await u.po.checkout.fillTestCard();
await u.po.checkout.clickPayOrSubscribe();
await expect(u.po.page.locator('.cl-checkout-root').getByText('Payment was successful!')).toBeVisible();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"test:integration:ap-flows": "pnpm test:integration:base --grep @ap-flows",
"test:integration:astro": "E2E_APP_ID=astro.* pnpm test:integration:base --grep @astro",
"test:integration:base": "pnpm playwright test --config integration/playwright.config.ts",
"test:integration:billing": "E2E_APP_ID=withBilling.* pnpm test:integration:base --grep @billing",
"test:integration:billing": "E2E_APP_ID=withBilling.next.appRouter pnpm test:integration:base --grep @billing",
"test:integration:cleanup": "pnpm playwright test --config integration/playwright.cleanup.config.ts",
"test:integration:deployment:nextjs": "pnpm playwright test --config integration/playwright.deployments.config.ts",
"test:integration:elements": "E2E_APP_ID=elements.* pnpm test:integration:base --grep @elements",
Expand Down
4 changes: 2 additions & 2 deletions packages/clerk-js/bundlewatch.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{ "path": "./dist/ui-common*.js", "maxSize": "110KB" },
{ "path": "./dist/vendors*.js", "maxSize": "40.2KB" },
{ "path": "./dist/coinbase*.js", "maxSize": "38KB" },
{ "path": "./dist/stripe-vendors*.js", "maxSize": "5.54KB" },
{ "path": "./dist/createorganization*.js", "maxSize": "5KB" },
{ "path": "./dist/impersonationfab*.js", "maxSize": "5KB" },
{ "path": "./dist/organizationprofile*.js", "maxSize": "12KB" },
Expand All @@ -21,8 +22,7 @@
{ "path": "./dist/waitlist*.js", "maxSize": "1.5KB" },
{ "path": "./dist/keylessPrompt*.js", "maxSize": "6.5KB" },
{ "path": "./dist/pricingTable*.js", "maxSize": "4.02KB" },
{ "path": "./dist/checkout*.js", "maxSize": "7.3KB" },
{ "path": "./dist/paymentSources*.js", "maxSize": "9.17KB" },
{ "path": "./dist/checkout*.js", "maxSize": "8.30KB" },
{ "path": "./dist/up-billing-page*.js", "maxSize": "3.0KB" },
{ "path": "./dist/op-billing-page*.js", "maxSize": "3.0KB" },
{ "path": "./dist/sessionTasks*.js", "maxSize": "1.5KB" }
Expand Down
1 change: 0 additions & 1 deletion packages/clerk-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
"@floating-ui/react": "0.27.12",
"@floating-ui/react-dom": "^2.1.3",
"@formkit/auto-animate": "^0.8.2",
"@stripe/react-stripe-js": "3.1.1",
"@stripe/stripe-js": "5.6.0",
"@swc/helpers": "^0.5.17",
"@zxcvbn-ts/core": "3.0.4",
Expand Down
23 changes: 12 additions & 11 deletions packages/clerk-js/rspack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const common = ({ mode, variant, disableRHC = false }) => {
* Necessary to prevent the Stripe dependencies from being bundled into
* SDKs such as Browser Extensions.
*/
// TODO: @COMMERCE: Do we still need this?
externals: disableRHC ? ['@stripe/stripe-js', '@stripe/react-stripe-js'] : undefined,
optimization: {
splitChunks: {
Expand All @@ -100,6 +101,12 @@ const common = ({ mode, variant, disableRHC = false }) => {
name: 'coinbase-wallet-sdk',
chunks: 'all',
},
stripeVendor: {
test: /[\\/]node_modules[\\/](@stripe\/stripe-js)[\\/]/,
name: 'stripe-vendors',
chunks: 'all',
enforce: true,
},
/**
* Sign up is shared between the SignUp component and the SignIn component.
*/
Expand All @@ -108,17 +115,11 @@ const common = ({ mode, variant, disableRHC = false }) => {
name: 'signup',
test: module => !!(module.resource && module.resource.includes('/ui/components/SignUp')),
},
paymentSources: {
minChunks: 1,
name: 'paymentSources',
test: module =>
!!(
module.resource &&
(module.resource.includes('/ui/components/PaymentSources') ||
// Include `@stripe/react-stripe-js` and `@stripe/stripe-js` in the checkout chunk
module.resource.includes('/node_modules/@stripe'))
),
},
// paymentSources: {
// minChunks: 1,
// name: 'paymentSources',
// test: module => !!(module.resource && module.resource.includes('/ui/components/PaymentSources')),
// },
common: {
minChunks: 1,
name: 'ui-common',
Expand Down
17 changes: 17 additions & 0 deletions packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ import type { FapiClient, FapiRequestCallback } from './fapiClient';
import { createFapiClient } from './fapiClient';
import { createClientFromJwt } from './jwt-client';
import { APIKeys } from './modules/apiKeys';
import type { CheckoutFunction } from './modules/checkout';
import { createCheckoutInstance } from './modules/checkout';
import { CommerceBilling } from './modules/commerce';
import {
BaseResource,
Expand Down Expand Up @@ -195,6 +197,7 @@ export class Clerk implements ClerkInterface {
};
private static _billing: CommerceBillingNamespace;
private static _apiKeys: APIKeysNamespace;
private _checkout: CheckoutFunction | undefined;

public client: ClientResource | undefined;
public session: SignedInSessionResource | null | undefined;
Expand Down Expand Up @@ -337,6 +340,13 @@ export class Clerk implements ClerkInterface {
return Clerk._apiKeys;
}

get checkout() {
if (!this._checkout) {
this._checkout = params => createCheckoutInstance(this, params);
}
return this._checkout;
}

public __internal_getOption<K extends keyof ClerkOptions>(key: K): ClerkOptions[K] {
return this.#options[key];
}
Expand Down Expand Up @@ -645,6 +655,11 @@ export class Clerk implements ClerkInterface {
.then(controls => controls.closeModal('blankCaptcha'));
};

public __internal_loadStripeJs = async () => {
const { loadStripe } = await import('@stripe/stripe-js');
return loadStripe;
};

public openSignUp = (props?: SignUpProps): void => {
this.assertComponentsReady(this.#componentControls);
if (sessionExistsAndSingleSessionModeEnabled(this, this.environment)) {
Expand Down Expand Up @@ -1120,6 +1135,7 @@ export class Clerk implements ClerkInterface {
*/
public setActive = async ({ session, organization, beforeEmit, redirectUrl }: SetActiveParams): Promise<void> => {
this.__internal_setActiveInProgress = true;
console.log('session provided', session, redirectUrl);
try {
if (!this.client) {
throw new Error('setActive is being called before the client is loaded. Wait for init.');
Expand All @@ -1146,6 +1162,7 @@ export class Clerk implements ClerkInterface {
}

let newSession = session === undefined ? this.session : session;
console.log('newSession', newSession?.id);

// At this point, the `session` variable should contain either an `SignedInSessionResource`
// ,`null` or `undefined`.
Expand Down
Loading