@edx/frontend-app-alacarte-checkout 1.64.0 → 1.65.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -258,12 +258,12 @@ const ExpressCheckout = ({ stripe, totalAmountCents, currency, onPaymentAuthoriz
|
|
|
258
258
|
});
|
|
259
259
|
// A new wallet attempt is starting — clear the last attempt's errors.
|
|
260
260
|
// Once a click handler is registered Stripe waits for resolve() (1s
|
|
261
|
-
// limit) before opening the sheet
|
|
261
|
+
// limit) before opening the sheet; required fields are configured on create.
|
|
262
262
|
expressElement.on('click', (event) => {
|
|
263
263
|
var _a;
|
|
264
264
|
setWalletError(null);
|
|
265
|
+
event.resolve();
|
|
265
266
|
(_a = onWalletClickRef.current) === null || _a === void 0 ? void 0 : _a.call(onWalletClickRef);
|
|
266
|
-
event.resolve({ emailRequired: true, billingAddressRequired: true });
|
|
267
267
|
});
|
|
268
268
|
// The learner dismissed the wallet sheet without paying.
|
|
269
269
|
expressElement.on('cancel', () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpressCheckout.js","sourceRoot":"","sources":["../../../src/components/ExpressCheckout/ExpressCheckout.tsx"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAc,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAU5C,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,QAAQ,MAAM,YAAY,CAAC;AAqClC,uFAAuF;AACvF,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,CAAC;AAErC;;;;;;;GAOG;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,YAErE,KAAC,cAAc,KAAG,GACX,CACV,IACG,EAKN,cACE,GAAG,EAAE,aAAa,EAClB,SAAS,EAAE,eAAe,CAAC,UAAU,EAAE,YAAY,CAAC,iBACvC,UAAU,IAAI,CAAC,YAAY,iBAC5B,gBAAgB,GAC5B,EACF,cACE,GAAG,EAAE,cAAc,EACnB,SAAS,EAAE,eAAe,CAAC,WAAW,EAAE,aAAa,CAAC,iBACzC,WAAW,IAAI,CAAC,aAAa,iBAC9B,iBAAiB,GAC7B,IACE,EACL,WAAW,IAAI,CACd,YAAG,SAAS,EAAC,yBAAyB,EAAC,IAAI,EAAC,OAAO,YAChD,WAAW,GACV,CACL,EAEA,YAAY,IAAI,CACf,KAAC,QAAQ,IAAC,kBAAkB,EAAC,4BAA4B,EAAC,MAAM,EAAC,MAAM,EAAC,YAAY,EAAE,CAAC,EAAE,MAAM,SAAG,CACnG,IACG,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\nimport { useIntl } from '@openedx/frontend-base';\nimport { Skeleton } from '@openedx/paragon';\nimport type {\n ExpressCheckoutAvailablePaymentMethodsChangeEvent,\n ExpressCheckoutClickEvent,\n ExpressCheckoutConfirmEvent,\n ExpressCheckoutReadyEvent,\n StripeElementsLike,\n StripeElementLike,\n StripeLike,\n} from '../../types';\nimport { PayPalWordmark } from '../BrandMarks/BrandMarks';\nimport { useInert } from '../../utils/inert';\nimport { loadPaypal } from '../../utils/paypal';\nimport messages from './Messages';\n\nexport interface ExpressCheckoutProps {\n /** Stripe.js instance — null until loaded. */\n stripe: StripeLike | null,\n /** Total amount in the smallest currency unit (cents). */\n totalAmountCents: number | null,\n /** ISO 4217 currency code, e.g. 'USD'. */\n currency: string | null,\n /** Two-letter country code (kept for API stability). */\n country: string,\n /**\n * Called when the user authorises a wallet payment (Apple Pay / Google Pay).\n * Receives the Stripe PaymentMethod id and the billing country from the wallet.\n * Must resolve on success or reject on failure.\n */\n onPaymentAuthorized: (paymentMethodId: string, walletCountry?: string) => Promise<void>,\n /** Called when the learner clicks Apple Pay / Google Pay, before the sheet opens. */\n onWalletClick?: () => void,\n /** Called when the learner closes the Apple Pay / Google Pay sheet without paying. */\n onWalletCancel?: () => void,\n /** PayPal JS SDK client id — PayPal stays disabled without it. */\n paypalClientId?: string | null,\n /** PayPal `createOrder`: places the order with PayPal and resolves its id. */\n onPaypalCreateOrder?: () => Promise<string>,\n /** PayPal `onApprove`: captures the approved PayPal order. */\n onPaypalApprove?: (paypalOrderId: string) => Promise<void>,\n /** PayPal `onCancel` / `onError`: abandons the unapproved PayPal order. */\n onPaypalCancel?: (paypalOrderId: string) => Promise<void>,\n /** Disables the Apple Pay / Google Pay slots. */\n disabled?: boolean,\n /** Disables the PayPal slot — PayPal doesn't need Stripe, so it has its own flag. */\n paypalDisabled?: boolean,\n}\n\ntype WalletSlot = 'apple' | 'google';\n\n// Shows the block anyway if an SDK never settles (blocked script, Stripe never loads).\nexport const SKELETON_MAX_MS = 10000;\n\n/**\n * Express checkout: PayPal (local) | Apple Pay | Google Pay.\n *\n * Apple and Google each get their own Express Checkout Element (one wallet per\n * mount) so we can lay them out in equal columns. A single ECE with both wallets\n * stacks / overflows in this narrow column. `always` keeps the Shopify-like\n * show-even-without-a-saved-card behaviour.\n */\nconst ExpressCheckout: React.FC<ExpressCheckoutProps> = ({\n stripe,\n totalAmountCents,\n currency,\n onPaymentAuthorized,\n onWalletClick,\n onWalletCancel,\n paypalClientId,\n onPaypalCreateOrder,\n onPaypalApprove,\n onPaypalCancel,\n disabled,\n paypalDisabled,\n}) => {\n const { formatMessage } = useIntl();\n const appleMountRef = useRef<HTMLDivElement | null>(null);\n const googleMountRef = useRef<HTMLDivElement | null>(null);\n const appleElementsRef = useRef<StripeElementsLike | null>(null);\n const googleElementsRef = useRef<StripeElementsLike | null>(null);\n const appleElementRef = useRef<StripeElementLike | null>(null);\n const googleElementRef = useRef<StripeElementLike | null>(null);\n const onPaymentAuthorizedRef = useRef(onPaymentAuthorized);\n const onWalletClickRef = useRef(onWalletClick);\n const onWalletCancelRef = useRef(onWalletCancel);\n const paypalMountRef = useRef<HTMLDivElement | null>(null);\n // The disabled class only blocks the pointer — inert drops the slot's\n // iframe from the tab order too.\n const paypalSlotRef = useInert<HTMLDivElement>(!!paypalDisabled);\n const paypalHandlersRef = useRef({ onPaypalCreateOrder, onPaypalApprove, onPaypalCancel });\n // PayPal order created but not yet approved — cancelled if the buttons error out.\n const openPaypalOrderRef = useRef<string | null>(null);\n\n const [appleReady, setAppleReady] = useState(false);\n const [googleReady, setGoogleReady] = useState(false);\n const [appleVisible, setAppleVisible] = useState(false);\n const [googleVisible, setGoogleVisible] = useState(false);\n const [walletError, setWalletError] = useState<string | null>(null);\n const [paypalRendered, setPaypalRendered] = useState(false);\n // PayPal finished: rendered, ineligible, failed, or never possible (no client id).\n const [paypalSettled, setPaypalSettled] = useState(false);\n // Latched so later remounts (currency / amount change) don't bring the skeleton back.\n const [loaded, setLoaded] = useState(false);\n\n // Stripe wallets require a positive charge. Use an explicit > 0 check —\n // `!!totalAmountCents` treats a $0 (free) total as \"no amount\" and would\n // also break remounts after a coupon brings the total to zero.\n const canCharge = totalAmountCents != null && totalAmountCents > 0 && !!currency;\n const paypalEnabled = !!paypalClientId && canCharge && !!onPaypalCreateOrder && !!onPaypalApprove;\n // Keep slots in the grid until ready so Stripe measures a full column width.\n const showAppleSlot = !appleReady || appleVisible;\n const showGoogleSlot = !googleReady || googleVisible;\n const columnCount = 1 + (showAppleSlot ? 1 : 0) + (showGoogleSlot ? 1 : 0);\n const allSettled = paypalSettled && appleReady && googleReady;\n const showSkeleton = !loaded && !allSettled;\n\n useEffect(() => {\n if (allSettled) setLoaded(true);\n }, [allSettled]);\n\n useEffect(() => {\n const timer = setTimeout(() => setLoaded(true), SKELETON_MAX_MS);\n return () => clearTimeout(timer);\n }, []);\n\n useEffect(() => {\n onPaymentAuthorizedRef.current = onPaymentAuthorized;\n }, [onPaymentAuthorized]);\n\n useEffect(() => {\n onWalletClickRef.current = onWalletClick;\n }, [onWalletClick]);\n\n useEffect(() => {\n onWalletCancelRef.current = onWalletCancel;\n }, [onWalletCancel]);\n\n // Wallet hosts keep object refs for remounts, so toggle inert here instead.\n useEffect(() => {\n appleMountRef.current?.toggleAttribute('inert', !!disabled);\n googleMountRef.current?.toggleAttribute('inert', !!disabled);\n }, [disabled]);\n\n useEffect(() => {\n paypalHandlersRef.current = { onPaypalCreateOrder, onPaypalApprove, onPaypalCancel };\n }, [onPaypalCreateOrder, onPaypalApprove, onPaypalCancel]);\n\n // PayPal buttons: tCheckoutPlaceOrder(PAYPAL) on click, capture on approve,\n // cancel when the learner closes the PayPal window.\n useEffect(() => {\n const mountNode = paypalMountRef.current;\n if (!paypalEnabled || !paypalClientId || !currency || !mountNode) {\n console.log('[ExpressCheckout] PayPal disabled', {\n hasClientId: !!paypalClientId,\n canCharge,\n hasCreateOrder: !!onPaypalCreateOrder,\n hasApprove: !!onPaypalApprove,\n });\n setPaypalRendered(false);\n // Without a client id PayPal can never render — don't wait for it.\n // Same for a $0 total: express PayPal is not applicable.\n setPaypalSettled(!paypalClientId || !canCharge);\n return undefined;\n }\n\n let cancelled = false;\n const cancelOpenOrder = async () => {\n const orderId = openPaypalOrderRef.current;\n openPaypalOrderRef.current = null;\n if (orderId) await paypalHandlersRef.current.onPaypalCancel?.(orderId);\n };\n\n loadPaypal(paypalClientId, currency)\n .then(async (paypal) => {\n if (cancelled) return;\n const buttons = paypal.Buttons({\n fundingSource: paypal.FUNDING.PAYPAL,\n style: {\n layout: 'horizontal',\n color: 'gold',\n shape: 'rect',\n label: 'paypal',\n height: 48,\n // Matches the Stripe wallets' `borderRadius: '12px'` appearance.\n borderRadius: 12,\n tagline: false,\n },\n createOrder: async () => {\n setWalletError(null);\n const orderId = await paypalHandlersRef.current.onPaypalCreateOrder!();\n openPaypalOrderRef.current = orderId;\n return orderId;\n },\n onApprove: async ({ orderID }) => {\n openPaypalOrderRef.current = null;\n try {\n await paypalHandlersRef.current.onPaypalApprove!(orderID);\n } catch (err) {\n // The checkout page already shows the capture error.\n console.warn('[ExpressCheckout] PayPal capture failed', err);\n }\n },\n onCancel: async () => {\n await cancelOpenOrder();\n },\n onError: (err) => {\n console.warn('[ExpressCheckout] PayPal error', err);\n // createOrder failures are already shown by the checkout page.\n if (openPaypalOrderRef.current) {\n setWalletError(formatMessage(messages.paypalError));\n cancelOpenOrder().catch(() => {});\n }\n },\n });\n if (!buttons.isEligible()) {\n console.warn('[ExpressCheckout] PayPal buttons not eligible', { currency });\n if (!cancelled) setPaypalSettled(true);\n return;\n }\n await buttons.render(mountNode);\n if (!cancelled) {\n setPaypalRendered(true);\n setPaypalSettled(true);\n }\n })\n .catch((err) => {\n console.warn('[ExpressCheckout] PayPal SDK unavailable', err);\n if (!cancelled) {\n setPaypalRendered(false);\n setPaypalSettled(true);\n }\n });\n\n return () => {\n cancelled = true;\n mountNode.innerHTML = '';\n setPaypalRendered(false);\n setPaypalSettled(false);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [paypalEnabled, paypalClientId, currency]);\n\n useEffect(() => {\n if (\n !stripe\n || !canCharge\n || totalAmountCents == null\n || !currency\n || !appleMountRef.current\n || !googleMountRef.current\n ) {\n console.log('[ExpressCheckout] skip mount', {\n hasStripe: !!stripe,\n totalAmountCents,\n currency,\n canCharge,\n hasAppleMount: !!appleMountRef.current,\n hasGoogleMount: !!googleMountRef.current,\n });\n setAppleReady(false);\n setGoogleReady(false);\n setAppleVisible(false);\n setGoogleVisible(false);\n setWalletError(null);\n return undefined;\n }\n\n console.log('[ExpressCheckout] mounting wallet slots', { totalAmountCents, currency });\n setAppleReady(false);\n setGoogleReady(false);\n setAppleVisible(false);\n setGoogleVisible(false);\n\n const sharedElementsOpts = {\n mode: 'payment' as const,\n amount: totalAmountCents,\n currency: currency.toLowerCase(),\n paymentMethodCreation: 'manual' as const,\n appearance: {\n variables: { borderRadius: '12px' },\n },\n };\n\n const bindWallet = (\n slot: WalletSlot,\n elements: StripeElementsLike,\n expressElement: StripeElementLike,\n mountNode: HTMLDivElement,\n setReady: (v: boolean) => void,\n setVisible: (v: boolean) => void,\n ) => {\n // Availability comes from `availablepaymentmethodschange`: it fires on initial\n // render and again if it changes later (iOS checks Apple Pay asynchronously,\n // so a one-shot read on `ready` could hide the button for good).\n let availabilityReported = false;\n expressElement.on(\n 'availablepaymentmethodschange',\n (event: ExpressCheckoutAvailablePaymentMethodsChangeEvent) => {\n const methods = event.paymentMethods;\n const visible = !!(slot === 'apple' ? methods?.applePay : methods?.googlePay)?.available;\n console.log(`[ExpressCheckout] available payment methods (${slot})`, {\n visible,\n raw: methods ?? null,\n });\n availabilityReported = true;\n setVisible(visible);\n setReady(true);\n },\n );\n\n // Fallback for the deprecated `ready` payload, only while the change event\n // hasn't reported. A negative answer here may be stale, so it's ignored.\n expressElement.on('ready', (event: ExpressCheckoutReadyEvent) => {\n const methods = event.availablePaymentMethods;\n const visible = slot === 'apple' ? !!methods?.applePay : !!methods?.googlePay;\n console.log(`[ExpressCheckout] ready (${slot})`, { visible, raw: methods ?? null });\n if (availabilityReported || !visible) return;\n setVisible(true);\n setReady(true);\n });\n\n // A wallet that fails to load counts as unavailable, so it can't hold the skeleton.\n expressElement.on('loaderror', (event: unknown) => {\n console.warn(`[ExpressCheckout] load error (${slot})`, event);\n setVisible(false);\n setReady(true);\n });\n\n // A new wallet attempt is starting — clear the last attempt's errors.\n // Once a click handler is registered Stripe waits for resolve() (1s\n // limit) before opening the sheet, so resolve with the create options.\n expressElement.on('click', (event: ExpressCheckoutClickEvent) => {\n setWalletError(null);\n onWalletClickRef.current?.();\n event.resolve({ emailRequired: true, billingAddressRequired: true });\n });\n\n // The learner dismissed the wallet sheet without paying.\n expressElement.on('cancel', () => {\n onWalletCancelRef.current?.();\n });\n\n expressElement.on('confirm', async (event: ExpressCheckoutConfirmEvent) => {\n setWalletError(null);\n if (!elements.submit) {\n event.paymentFailed({ reason: 'fail' });\n return;\n }\n\n const walletLabel = formatMessage(\n slot === 'apple' ? messages.applePay : messages.googlePay,\n );\n\n let paymentMethodId: string;\n let walletCountry: string | undefined;\n try {\n const { error: submitError } = await elements.submit();\n if (submitError) {\n setWalletError(submitError.message || formatMessage(messages.walletUnavailable, {\n wallet: walletLabel,\n }));\n event.paymentFailed({ reason: 'fail' });\n return;\n }\n\n const { paymentMethod, error } = await stripe.createPaymentMethod({ elements });\n if (error || !paymentMethod?.id) {\n setWalletError(error?.message || formatMessage(messages.walletUnavailable, {\n wallet: walletLabel,\n }));\n event.paymentFailed({ reason: 'fail' });\n return;\n }\n\n paymentMethodId = paymentMethod.id;\n walletCountry = event.billingDetails?.address?.country\n || paymentMethod.billing_details?.address?.country;\n } catch (err) {\n console.warn(`[ExpressCheckout] wallet setup failed (${slot})`, err);\n setWalletError(formatMessage(messages.walletUnavailable, { wallet: walletLabel }));\n event.paymentFailed({ reason: 'fail' });\n return;\n }\n\n try {\n await onPaymentAuthorizedRef.current(paymentMethodId, walletCountry);\n } catch (err) {\n // The wallet worked; the payment itself failed (e.g. card declined).\n // The checkout page already shows that error, so don't blame the wallet.\n console.warn(`[ExpressCheckout] payment failed (${slot})`, err);\n event.paymentFailed({ reason: 'fail' });\n }\n });\n\n expressElement.mount(mountNode);\n };\n\n const appleElements = stripe.elements(sharedElementsOpts);\n const googleElements = stripe.elements(sharedElementsOpts);\n appleElementsRef.current = appleElements;\n googleElementsRef.current = googleElements;\n\n const appleElement = appleElements.create('expressCheckout', {\n buttonHeight: 48,\n emailRequired: true,\n billingAddressRequired: true,\n paymentMethodOrder: ['applePay'],\n buttonType: { applePay: 'plain' },\n buttonTheme: { applePay: 'black' },\n paymentMethods: {\n applePay: 'always',\n googlePay: 'never',\n link: 'never',\n paypal: 'never',\n amazonPay: 'never',\n klarna: 'never',\n },\n layout: { maxColumns: 1, maxRows: 0, overflow: 'never' },\n });\n appleElementRef.current = appleElement;\n\n const googleElement = googleElements.create('expressCheckout', {\n buttonHeight: 48,\n emailRequired: true,\n billingAddressRequired: true,\n paymentMethodOrder: ['googlePay'],\n buttonType: { googlePay: 'plain' },\n buttonTheme: { googlePay: 'black' },\n paymentMethods: {\n applePay: 'never',\n googlePay: 'always',\n link: 'never',\n paypal: 'never',\n amazonPay: 'never',\n klarna: 'never',\n },\n layout: { maxColumns: 1, maxRows: 0, overflow: 'never' },\n });\n googleElementRef.current = googleElement;\n\n bindWallet(\n 'apple',\n appleElements,\n appleElement,\n appleMountRef.current,\n setAppleReady,\n setAppleVisible,\n );\n bindWallet(\n 'google',\n googleElements,\n googleElement,\n googleMountRef.current,\n setGoogleReady,\n setGoogleVisible,\n );\n\n return () => {\n try {\n appleElement.unmount?.();\n appleElement.destroy?.();\n googleElement.unmount?.();\n googleElement.destroy?.();\n } catch {\n // Elements may already be gone.\n }\n appleElementRef.current = null;\n googleElementRef.current = null;\n appleElementsRef.current = null;\n googleElementsRef.current = null;\n setAppleReady(false);\n setGoogleReady(false);\n setAppleVisible(false);\n setGoogleVisible(false);\n };\n // Remount when the chargeable total changes (e.g. coupon apply). Calling\n // elements.update() alone can leave ECE wallets stuck unavailable after the\n // amount changes; a fresh mount re-runs availability cleanly.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [stripe, currency, totalAmountCents, canCharge]);\n\n const walletClassName = (ready: boolean, visible: boolean) => {\n const base = `express-checkout__wallet${disabled ? ' express-checkout__slot--disabled' : ''}`;\n if (!ready) return `${base} express-checkout__wallet--pending`;\n if (!visible) return `${base} express-checkout__wallet--unavailable`;\n return base;\n };\n\n return (\n <div\n className={`express-checkout${showSkeleton ? ' express-checkout--loading' : ''}`}\n role=\"group\"\n aria-labelledby=\"express-checkout-heading\"\n aria-busy={showSkeleton}\n >\n <h3 id=\"express-checkout-heading\" className=\"express-checkout__heading\">\n {formatMessage(messages.heading)}\n </h3>\n <div\n className={`express-checkout__buttons express-checkout__buttons--cols-${columnCount}`}\n style={{ gridTemplateColumns: `repeat(${columnCount}, minmax(0, 1fr))` }}\n >\n <div\n ref={paypalSlotRef}\n className={`express-checkout__paypal${paypalDisabled ? ' express-checkout__slot--disabled' : ''}`}\n >\n {/* PayPal SDK renders its button here; the wordmark stands in until it does. */}\n <div\n ref={paypalMountRef}\n className={paypalRendered ? undefined : 'express-checkout__paypal-mount--pending'}\n data-testid=\"paypal-slot\"\n />\n {!paypalRendered && (\n <button\n type=\"button\"\n disabled\n aria-label={formatMessage(messages.paypal)}\n className=\"express-checkout__button express-checkout__button--paypal\"\n >\n <PayPalWordmark />\n </button>\n )}\n </div>\n\n {/* Always in the DOM so remounts can find the nodes; CSS hides unavailable.\n No aria-label on the slots: a labelled div is exposed as a group, so\n screen readers would announce a group around each wallet's own button. */}\n <div\n ref={appleMountRef}\n className={walletClassName(appleReady, appleVisible)}\n aria-hidden={appleReady && !appleVisible}\n data-testid=\"apple-pay-slot\"\n />\n <div\n ref={googleMountRef}\n className={walletClassName(googleReady, googleVisible)}\n aria-hidden={googleReady && !googleVisible}\n data-testid=\"google-pay-slot\"\n />\n </div>\n {walletError && (\n <p className=\"express-checkout__error\" role=\"alert\">\n {walletError}\n </p>\n )}\n {/* One skeleton over the whole block; the slots stay mounted underneath so the SDKs can load. */}\n {showSkeleton && (\n <Skeleton containerClassName=\"express-checkout__skeleton\" height=\"100%\" borderRadius={8} inline />\n )}\n </div>\n );\n};\n\nexport default ExpressCheckout;\n"]}
|
|
1
|
+
{"version":3,"file":"ExpressCheckout.js","sourceRoot":"","sources":["../../../src/components/ExpressCheckout/ExpressCheckout.tsx"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAc,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAU5C,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,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E,aAAa,GACzB,EACD,CAAC,cAAc,IAAI,CAClB,iBACE,IAAI,EAAC,QAAQ,EACb,QAAQ,sBACI,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAC,EAC1C,SAAS,EAAC,2DAA2D,YAErE,KAAC,cAAc,KAAG,GACX,CACV,IACG,EAKN,cACE,GAAG,EAAE,aAAa,EAClB,SAAS,EAAE,eAAe,CAAC,UAAU,EAAE,YAAY,CAAC,iBACvC,UAAU,IAAI,CAAC,YAAY,iBAC5B,gBAAgB,GAC5B,EACF,cACE,GAAG,EAAE,cAAc,EACnB,SAAS,EAAE,eAAe,CAAC,WAAW,EAAE,aAAa,CAAC,iBACzC,WAAW,IAAI,CAAC,aAAa,iBAC9B,iBAAiB,GAC7B,IACE,EACL,WAAW,IAAI,CACd,YAAG,SAAS,EAAC,yBAAyB,EAAC,IAAI,EAAC,OAAO,YAChD,WAAW,GACV,CACL,EAEA,YAAY,IAAI,CACf,KAAC,QAAQ,IAAC,kBAAkB,EAAC,4BAA4B,EAAC,MAAM,EAAC,MAAM,EAAC,YAAY,EAAE,CAAC,EAAE,MAAM,SAAG,CACnG,IACG,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\nimport { useIntl } from '@openedx/frontend-base';\nimport { Skeleton } from '@openedx/paragon';\nimport type {\n ExpressCheckoutAvailablePaymentMethodsChangeEvent,\n ExpressCheckoutClickEvent,\n ExpressCheckoutConfirmEvent,\n ExpressCheckoutReadyEvent,\n StripeElementsLike,\n StripeElementLike,\n StripeLike,\n} from '../../types';\nimport { PayPalWordmark } from '../BrandMarks/BrandMarks';\nimport { useInert } from '../../utils/inert';\nimport { loadPaypal } from '../../utils/paypal';\nimport messages from './Messages';\n\nexport interface ExpressCheckoutProps {\n /** Stripe.js instance — null until loaded. */\n stripe: StripeLike | null,\n /** Total amount in the smallest currency unit (cents). */\n totalAmountCents: number | null,\n /** ISO 4217 currency code, e.g. 'USD'. */\n currency: string | null,\n /** Two-letter country code (kept for API stability). */\n country: string,\n /**\n * Called when the user authorises a wallet payment (Apple Pay / Google Pay).\n * Receives the Stripe PaymentMethod id and the billing country from the wallet.\n * Must resolve on success or reject on failure.\n */\n onPaymentAuthorized: (paymentMethodId: string, walletCountry?: string) => Promise<void>,\n /** Called when the learner clicks Apple Pay / Google Pay, before the sheet opens. */\n onWalletClick?: () => void,\n /** Called when the learner closes the Apple Pay / Google Pay sheet without paying. */\n onWalletCancel?: () => void,\n /** PayPal JS SDK client id — PayPal stays disabled without it. */\n paypalClientId?: string | null,\n /** PayPal `createOrder`: places the order with PayPal and resolves its id. */\n onPaypalCreateOrder?: () => Promise<string>,\n /** PayPal `onApprove`: captures the approved PayPal order. */\n onPaypalApprove?: (paypalOrderId: string) => Promise<void>,\n /** PayPal `onCancel` / `onError`: abandons the unapproved PayPal order. */\n onPaypalCancel?: (paypalOrderId: string) => Promise<void>,\n /** Disables the Apple Pay / Google Pay slots. */\n disabled?: boolean,\n /** Disables the PayPal slot — PayPal doesn't need Stripe, so it has its own flag. */\n paypalDisabled?: boolean,\n}\n\ntype WalletSlot = 'apple' | 'google';\n\n// Shows the block anyway if an SDK never settles (blocked script, Stripe never loads).\nexport const SKELETON_MAX_MS = 10000;\n\n/**\n * Express checkout: PayPal (local) | Apple Pay | Google Pay.\n *\n * Apple and Google each get their own Express Checkout Element (one wallet per\n * mount) so we can lay them out in equal columns. A single ECE with both wallets\n * stacks / overflows in this narrow column. `always` keeps the Shopify-like\n * show-even-without-a-saved-card behaviour.\n */\nconst ExpressCheckout: React.FC<ExpressCheckoutProps> = ({\n stripe,\n totalAmountCents,\n currency,\n onPaymentAuthorized,\n onWalletClick,\n onWalletCancel,\n paypalClientId,\n onPaypalCreateOrder,\n onPaypalApprove,\n onPaypalCancel,\n disabled,\n paypalDisabled,\n}) => {\n const { formatMessage } = useIntl();\n const appleMountRef = useRef<HTMLDivElement | null>(null);\n const googleMountRef = useRef<HTMLDivElement | null>(null);\n const appleElementsRef = useRef<StripeElementsLike | null>(null);\n const googleElementsRef = useRef<StripeElementsLike | null>(null);\n const appleElementRef = useRef<StripeElementLike | null>(null);\n const googleElementRef = useRef<StripeElementLike | null>(null);\n const onPaymentAuthorizedRef = useRef(onPaymentAuthorized);\n const onWalletClickRef = useRef(onWalletClick);\n const onWalletCancelRef = useRef(onWalletCancel);\n const paypalMountRef = useRef<HTMLDivElement | null>(null);\n // The disabled class only blocks the pointer — inert drops the slot's\n // iframe from the tab order too.\n const paypalSlotRef = useInert<HTMLDivElement>(!!paypalDisabled);\n const paypalHandlersRef = useRef({ onPaypalCreateOrder, onPaypalApprove, onPaypalCancel });\n // PayPal order created but not yet approved — cancelled if the buttons error out.\n const openPaypalOrderRef = useRef<string | null>(null);\n\n const [appleReady, setAppleReady] = useState(false);\n const [googleReady, setGoogleReady] = useState(false);\n const [appleVisible, setAppleVisible] = useState(false);\n const [googleVisible, setGoogleVisible] = useState(false);\n const [walletError, setWalletError] = useState<string | null>(null);\n const [paypalRendered, setPaypalRendered] = useState(false);\n // PayPal finished: rendered, ineligible, failed, or never possible (no client id).\n const [paypalSettled, setPaypalSettled] = useState(false);\n // Latched so later remounts (currency / amount change) don't bring the skeleton back.\n const [loaded, setLoaded] = useState(false);\n\n // Stripe wallets require a positive charge. Use an explicit > 0 check —\n // `!!totalAmountCents` treats a $0 (free) total as \"no amount\" and would\n // also break remounts after a coupon brings the total to zero.\n const canCharge = totalAmountCents != null && totalAmountCents > 0 && !!currency;\n const paypalEnabled = !!paypalClientId && canCharge && !!onPaypalCreateOrder && !!onPaypalApprove;\n // Keep slots in the grid until ready so Stripe measures a full column width.\n const showAppleSlot = !appleReady || appleVisible;\n const showGoogleSlot = !googleReady || googleVisible;\n const columnCount = 1 + (showAppleSlot ? 1 : 0) + (showGoogleSlot ? 1 : 0);\n const allSettled = paypalSettled && appleReady && googleReady;\n const showSkeleton = !loaded && !allSettled;\n\n useEffect(() => {\n if (allSettled) setLoaded(true);\n }, [allSettled]);\n\n useEffect(() => {\n const timer = setTimeout(() => setLoaded(true), SKELETON_MAX_MS);\n return () => clearTimeout(timer);\n }, []);\n\n useEffect(() => {\n onPaymentAuthorizedRef.current = onPaymentAuthorized;\n }, [onPaymentAuthorized]);\n\n useEffect(() => {\n onWalletClickRef.current = onWalletClick;\n }, [onWalletClick]);\n\n useEffect(() => {\n onWalletCancelRef.current = onWalletCancel;\n }, [onWalletCancel]);\n\n // Wallet hosts keep object refs for remounts, so toggle inert here instead.\n useEffect(() => {\n appleMountRef.current?.toggleAttribute('inert', !!disabled);\n googleMountRef.current?.toggleAttribute('inert', !!disabled);\n }, [disabled]);\n\n useEffect(() => {\n paypalHandlersRef.current = { onPaypalCreateOrder, onPaypalApprove, onPaypalCancel };\n }, [onPaypalCreateOrder, onPaypalApprove, onPaypalCancel]);\n\n // PayPal buttons: tCheckoutPlaceOrder(PAYPAL) on click, capture on approve,\n // cancel when the learner closes the PayPal window.\n useEffect(() => {\n const mountNode = paypalMountRef.current;\n if (!paypalEnabled || !paypalClientId || !currency || !mountNode) {\n console.log('[ExpressCheckout] PayPal disabled', {\n hasClientId: !!paypalClientId,\n canCharge,\n hasCreateOrder: !!onPaypalCreateOrder,\n hasApprove: !!onPaypalApprove,\n });\n setPaypalRendered(false);\n // Without a client id PayPal can never render — don't wait for it.\n // Same for a $0 total: express PayPal is not applicable.\n setPaypalSettled(!paypalClientId || !canCharge);\n return undefined;\n }\n\n let cancelled = false;\n const cancelOpenOrder = async () => {\n const orderId = openPaypalOrderRef.current;\n openPaypalOrderRef.current = null;\n if (orderId) await paypalHandlersRef.current.onPaypalCancel?.(orderId);\n };\n\n loadPaypal(paypalClientId, currency)\n .then(async (paypal) => {\n if (cancelled) return;\n const buttons = paypal.Buttons({\n fundingSource: paypal.FUNDING.PAYPAL,\n style: {\n layout: 'horizontal',\n color: 'gold',\n shape: 'rect',\n label: 'paypal',\n height: 48,\n // Matches the Stripe wallets' `borderRadius: '12px'` appearance.\n borderRadius: 12,\n tagline: false,\n },\n createOrder: async () => {\n setWalletError(null);\n const orderId = await paypalHandlersRef.current.onPaypalCreateOrder!();\n openPaypalOrderRef.current = orderId;\n return orderId;\n },\n onApprove: async ({ orderID }) => {\n openPaypalOrderRef.current = null;\n try {\n await paypalHandlersRef.current.onPaypalApprove!(orderID);\n } catch (err) {\n // The checkout page already shows the capture error.\n console.warn('[ExpressCheckout] PayPal capture failed', err);\n }\n },\n onCancel: async () => {\n await cancelOpenOrder();\n },\n onError: (err) => {\n console.warn('[ExpressCheckout] PayPal error', err);\n // createOrder failures are already shown by the checkout page.\n if (openPaypalOrderRef.current) {\n setWalletError(formatMessage(messages.paypalError));\n cancelOpenOrder().catch(() => {});\n }\n },\n });\n if (!buttons.isEligible()) {\n console.warn('[ExpressCheckout] PayPal buttons not eligible', { currency });\n if (!cancelled) setPaypalSettled(true);\n return;\n }\n await buttons.render(mountNode);\n if (!cancelled) {\n setPaypalRendered(true);\n setPaypalSettled(true);\n }\n })\n .catch((err) => {\n console.warn('[ExpressCheckout] PayPal SDK unavailable', err);\n if (!cancelled) {\n setPaypalRendered(false);\n setPaypalSettled(true);\n }\n });\n\n return () => {\n cancelled = true;\n mountNode.innerHTML = '';\n setPaypalRendered(false);\n setPaypalSettled(false);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [paypalEnabled, paypalClientId, currency]);\n\n useEffect(() => {\n if (\n !stripe\n || !canCharge\n || totalAmountCents == null\n || !currency\n || !appleMountRef.current\n || !googleMountRef.current\n ) {\n console.log('[ExpressCheckout] skip mount', {\n hasStripe: !!stripe,\n totalAmountCents,\n currency,\n canCharge,\n hasAppleMount: !!appleMountRef.current,\n hasGoogleMount: !!googleMountRef.current,\n });\n setAppleReady(false);\n setGoogleReady(false);\n setAppleVisible(false);\n setGoogleVisible(false);\n setWalletError(null);\n return undefined;\n }\n\n console.log('[ExpressCheckout] mounting wallet slots', { totalAmountCents, currency });\n setAppleReady(false);\n setGoogleReady(false);\n setAppleVisible(false);\n setGoogleVisible(false);\n\n const sharedElementsOpts = {\n mode: 'payment' as const,\n amount: totalAmountCents,\n currency: currency.toLowerCase(),\n paymentMethodCreation: 'manual' as const,\n appearance: {\n variables: { borderRadius: '12px' },\n },\n };\n\n const bindWallet = (\n slot: WalletSlot,\n elements: StripeElementsLike,\n expressElement: StripeElementLike,\n mountNode: HTMLDivElement,\n setReady: (v: boolean) => void,\n setVisible: (v: boolean) => void,\n ) => {\n // Availability comes from `availablepaymentmethodschange`: it fires on initial\n // render and again if it changes later (iOS checks Apple Pay asynchronously,\n // so a one-shot read on `ready` could hide the button for good).\n let availabilityReported = false;\n expressElement.on(\n 'availablepaymentmethodschange',\n (event: ExpressCheckoutAvailablePaymentMethodsChangeEvent) => {\n const methods = event.paymentMethods;\n const visible = !!(slot === 'apple' ? methods?.applePay : methods?.googlePay)?.available;\n console.log(`[ExpressCheckout] available payment methods (${slot})`, {\n visible,\n raw: methods ?? null,\n });\n availabilityReported = true;\n setVisible(visible);\n setReady(true);\n },\n );\n\n // Fallback for the deprecated `ready` payload, only while the change event\n // hasn't reported. A negative answer here may be stale, so it's ignored.\n expressElement.on('ready', (event: ExpressCheckoutReadyEvent) => {\n const methods = event.availablePaymentMethods;\n const visible = slot === 'apple' ? !!methods?.applePay : !!methods?.googlePay;\n console.log(`[ExpressCheckout] ready (${slot})`, { visible, raw: methods ?? null });\n if (availabilityReported || !visible) return;\n setVisible(true);\n setReady(true);\n });\n\n // A wallet that fails to load counts as unavailable, so it can't hold the skeleton.\n expressElement.on('loaderror', (event: unknown) => {\n console.warn(`[ExpressCheckout] load error (${slot})`, event);\n setVisible(false);\n setReady(true);\n });\n\n // A new wallet attempt is starting — clear the last attempt's errors.\n // Once a click handler is registered Stripe waits for resolve() (1s\n // limit) before opening the sheet; required fields are configured on create.\n expressElement.on('click', (event: ExpressCheckoutClickEvent) => {\n setWalletError(null);\n event.resolve();\n onWalletClickRef.current?.();\n });\n\n // The learner dismissed the wallet sheet without paying.\n expressElement.on('cancel', () => {\n onWalletCancelRef.current?.();\n });\n\n expressElement.on('confirm', async (event: ExpressCheckoutConfirmEvent) => {\n setWalletError(null);\n if (!elements.submit) {\n event.paymentFailed({ reason: 'fail' });\n return;\n }\n\n const walletLabel = formatMessage(\n slot === 'apple' ? messages.applePay : messages.googlePay,\n );\n\n let paymentMethodId: string;\n let walletCountry: string | undefined;\n try {\n const { error: submitError } = await elements.submit();\n if (submitError) {\n setWalletError(submitError.message || formatMessage(messages.walletUnavailable, {\n wallet: walletLabel,\n }));\n event.paymentFailed({ reason: 'fail' });\n return;\n }\n\n const { paymentMethod, error } = await stripe.createPaymentMethod({ elements });\n if (error || !paymentMethod?.id) {\n setWalletError(error?.message || formatMessage(messages.walletUnavailable, {\n wallet: walletLabel,\n }));\n event.paymentFailed({ reason: 'fail' });\n return;\n }\n\n paymentMethodId = paymentMethod.id;\n walletCountry = event.billingDetails?.address?.country\n || paymentMethod.billing_details?.address?.country;\n } catch (err) {\n console.warn(`[ExpressCheckout] wallet setup failed (${slot})`, err);\n setWalletError(formatMessage(messages.walletUnavailable, { wallet: walletLabel }));\n event.paymentFailed({ reason: 'fail' });\n return;\n }\n\n try {\n await onPaymentAuthorizedRef.current(paymentMethodId, walletCountry);\n } catch (err) {\n // The wallet worked; the payment itself failed (e.g. card declined).\n // The checkout page already shows that error, so don't blame the wallet.\n console.warn(`[ExpressCheckout] payment failed (${slot})`, err);\n event.paymentFailed({ reason: 'fail' });\n }\n });\n\n expressElement.mount(mountNode);\n };\n\n const appleElements = stripe.elements(sharedElementsOpts);\n const googleElements = stripe.elements(sharedElementsOpts);\n appleElementsRef.current = appleElements;\n googleElementsRef.current = googleElements;\n\n const appleElement = appleElements.create('expressCheckout', {\n buttonHeight: 48,\n emailRequired: true,\n billingAddressRequired: true,\n paymentMethodOrder: ['applePay'],\n buttonType: { applePay: 'plain' },\n buttonTheme: { applePay: 'black' },\n paymentMethods: {\n applePay: 'always',\n googlePay: 'never',\n link: 'never',\n paypal: 'never',\n amazonPay: 'never',\n klarna: 'never',\n },\n layout: { maxColumns: 1, maxRows: 0, overflow: 'never' },\n });\n appleElementRef.current = appleElement;\n\n const googleElement = googleElements.create('expressCheckout', {\n buttonHeight: 48,\n emailRequired: true,\n billingAddressRequired: true,\n paymentMethodOrder: ['googlePay'],\n buttonType: { googlePay: 'plain' },\n buttonTheme: { googlePay: 'black' },\n paymentMethods: {\n applePay: 'never',\n googlePay: 'always',\n link: 'never',\n paypal: 'never',\n amazonPay: 'never',\n klarna: 'never',\n },\n layout: { maxColumns: 1, maxRows: 0, overflow: 'never' },\n });\n googleElementRef.current = googleElement;\n\n bindWallet(\n 'apple',\n appleElements,\n appleElement,\n appleMountRef.current,\n setAppleReady,\n setAppleVisible,\n );\n bindWallet(\n 'google',\n googleElements,\n googleElement,\n googleMountRef.current,\n setGoogleReady,\n setGoogleVisible,\n );\n\n return () => {\n try {\n appleElement.unmount?.();\n appleElement.destroy?.();\n googleElement.unmount?.();\n googleElement.destroy?.();\n } catch {\n // Elements may already be gone.\n }\n appleElementRef.current = null;\n googleElementRef.current = null;\n appleElementsRef.current = null;\n googleElementsRef.current = null;\n setAppleReady(false);\n setGoogleReady(false);\n setAppleVisible(false);\n setGoogleVisible(false);\n };\n // Remount when the chargeable total changes (e.g. coupon apply). Calling\n // elements.update() alone can leave ECE wallets stuck unavailable after the\n // amount changes; a fresh mount re-runs availability cleanly.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [stripe, currency, totalAmountCents, canCharge]);\n\n const walletClassName = (ready: boolean, visible: boolean) => {\n const base = `express-checkout__wallet${disabled ? ' express-checkout__slot--disabled' : ''}`;\n if (!ready) return `${base} express-checkout__wallet--pending`;\n if (!visible) return `${base} express-checkout__wallet--unavailable`;\n return base;\n };\n\n return (\n <div\n className={`express-checkout${showSkeleton ? ' express-checkout--loading' : ''}`}\n role=\"group\"\n aria-labelledby=\"express-checkout-heading\"\n aria-busy={showSkeleton}\n >\n <h3 id=\"express-checkout-heading\" className=\"express-checkout__heading\">\n {formatMessage(messages.heading)}\n </h3>\n <div\n className={`express-checkout__buttons express-checkout__buttons--cols-${columnCount}`}\n style={{ gridTemplateColumns: `repeat(${columnCount}, minmax(0, 1fr))` }}\n >\n <div\n ref={paypalSlotRef}\n className={`express-checkout__paypal${paypalDisabled ? ' express-checkout__slot--disabled' : ''}`}\n >\n {/* PayPal SDK renders its button here; the wordmark stands in until it does. */}\n <div\n ref={paypalMountRef}\n className={paypalRendered ? undefined : 'express-checkout__paypal-mount--pending'}\n data-testid=\"paypal-slot\"\n />\n {!paypalRendered && (\n <button\n type=\"button\"\n disabled\n aria-label={formatMessage(messages.paypal)}\n className=\"express-checkout__button express-checkout__button--paypal\"\n >\n <PayPalWordmark />\n </button>\n )}\n </div>\n\n {/* Always in the DOM so remounts can find the nodes; CSS hides unavailable.\n No aria-label on the slots: a labelled div is exposed as a group, so\n screen readers would announce a group around each wallet's own button. */}\n <div\n ref={appleMountRef}\n className={walletClassName(appleReady, appleVisible)}\n aria-hidden={appleReady && !appleVisible}\n data-testid=\"apple-pay-slot\"\n />\n <div\n ref={googleMountRef}\n className={walletClassName(googleReady, googleVisible)}\n aria-hidden={googleReady && !googleVisible}\n data-testid=\"google-pay-slot\"\n />\n </div>\n {walletError && (\n <p className=\"express-checkout__error\" role=\"alert\">\n {walletError}\n </p>\n )}\n {/* One skeleton over the whole block; the slots stay mounted underneath so the SDKs can load. */}\n {showSkeleton && (\n <Skeleton containerClassName=\"express-checkout__skeleton\" height=\"100%\" borderRadius={8} inline />\n )}\n </div>\n );\n};\n\nexport default ExpressCheckout;\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -268,10 +268,7 @@ export interface ConfirmCardPaymentData {
|
|
|
268
268
|
/** Express Checkout Element `click` — `resolve` must be called within 1s or the sheet won't open. */
|
|
269
269
|
export interface ExpressCheckoutClickEvent {
|
|
270
270
|
expressPaymentType?: string;
|
|
271
|
-
resolve: (
|
|
272
|
-
emailRequired?: boolean;
|
|
273
|
-
billingAddressRequired?: boolean;
|
|
274
|
-
}) => void;
|
|
271
|
+
resolve: () => void;
|
|
275
272
|
}
|
|
276
273
|
export interface ExpressCheckoutConfirmEvent {
|
|
277
274
|
expressPaymentType?: string;
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Status, Phase } from './constants';\n\nexport type { Status, Phase };\n\n// --- Bootstrap domain --------------------------------------------------------\nexport type GqlRunner = (query: string, variables?: Record<string, unknown>, retry?: boolean) => Promise<any>;\n\n// --- Cart domain -------------------------------------------------------------\nexport interface Cart {\n biId: string,\n uid: string,\n}\n\nexport interface CartIds {\n customerUid: string,\n salableUid: string,\n billingPlanUid: string,\n}\n\nexport type BillingCycle = 'monthly' | 'annual';\n\nexport type PaymentMethod = 'card' | 'googlepay' | 'paypal';\n\nexport type SupportedPaymentMethod = Exclude<PaymentMethod, 'googlepay'>;\n\nexport type BillingPeriod = 'MONTHLY' | 'ANNUAL' | 'QUARTERLY' | string;\n\nexport interface BillingPlanOwnershipModel {\n uid: string,\n omName: string,\n}\n\nexport interface BillingPlan {\n uid: string,\n stripePriceId: string,\n /** Price amount e.g. \"39.99\" */\n amount: string,\n /** Currency code e.g. \"USD\" */\n currency: string,\n isTemplate: boolean,\n ownershipModel: BillingPlanOwnershipModel,\n}\n\nexport interface CurrentUserSubscriberResult {\n isSubscriber: boolean,\n subscriptionBiId: string | null,\n status: string | null,\n subscriptionStartDate: string | null,\n currentPeriodEnd: string | null,\n}\n\n/** Course shown on checkout / post-checkout when arriving via ?course_run_key=. */\nexport interface CourseDetail {\n maId: string,\n maName: string,\n maDescription: string | null,\n tShortDescription: string | null,\n imageUrl: string | null,\n tCourseKey: string | null,\n tBrandText: string | null,\n tPrimarySubjectArea: string | null,\n tLevelType: string | null,\n tLanguage: string | null,\n tPacingType: string | null,\n tDurationLow: number | null,\n tDurationHigh: number | null,\n tDurationUnit: string | null,\n tEffortLow: number | null,\n tEffortHigh: number | null,\n tEffortUnit: string | null,\n tUrlCourse: string | null,\n tB2cSubscriptionInclusion: boolean | null,\n tHasOfacRestrictions: boolean | null,\n tCatalogActive: boolean | null,\n /** How many learners are enrolled in this course — real per-course count, not the\n * platform-wide subscription figure. */\n tEnrollmentCount: number | null,\n}\n\n/** Returned by legacy subscription billing lookups (unused by à la carte). */\nexport interface BillingPlansResult {\n plans: BillingPlan[],\n}\n\n/** Returned by getSalableUid — the product uid and its ownership models. */\nexport interface ProductInfo {\n uid: string,\n maName: string,\n ownershipModels: { uid: string, omName: string }[],\n}\n\nexport interface CartStatusResult {\n status: Status | null,\n stripeSubscriptionId: string | null,\n /** Stripe-hosted challenge URL for the checkout confirmation step. */\n stripeConfirmationRedirectUrl: string | null,\n /** PayPal-hosted approval URL for the same checkout confirmation step. */\n paypalApprovalUrl: string | null,\n lastComment: string,\n}\n\nexport interface CartBillingAddress {\n tFirstName: string,\n tLastName: string,\n upaLine1: string,\n upaCity: string,\n upaPostcode: string,\n gadStateOrProvince: string,\n gadCountry: { iso2Code: string },\n}\n\nexport interface UpdateCartItemArgs {\n cartItemUid: string,\n billingAddress?: CartBillingAddress,\n paymentMethodId?: string,\n /** Payer email attached when the payment type is TwouPaypalPayment. */\n paypalEmail?: string | null,\n}\n\n/** Auto-renewal consent captured on TwouCart at checkout confirmation (SUBS-228). */\nexport interface CheckoutConsent {\n /** Main auto-renewal checkbox — always required at submit. */\n tConsentRecurring: boolean,\n /** UK/CA resident checkbox; null when that checkbox is not shown. */\n tConsentUkCa: boolean | null,\n /** ISO-8601 timestamp when consent was captured. */\n tConsentAt: string,\n /** Exact disclosure text shown to the learner (audit trail). */\n tConsentText: string,\n}\n\nexport interface UpdateCartConsentArgs {\n cartUid: string,\n consent: CheckoutConsent,\n /** Absolute checkout return URL stored in the backend's tStripeReturnUrl field. */\n returnUrl?: string | null,\n}\n\nexport interface BillingInfo {\n firstName: string,\n lastName: string,\n city: string,\n zip: string,\n country: string,\n line1: string,\n state: string,\n}\n\n// --- Checkout client surface -------------------------------------------------\nexport interface CheckoutClient {\n gql: GqlRunner,\n setToken: (token: string) => void,\n createCart: (vars: CartIds) => Promise<Cart>,\n getCartItem: (biId: string) => Promise<{ cartUid: string, cartItemUid: string }>,\n updateCartItem: (args: UpdateCartItemArgs) => Promise<void>,\n updateCartConsent: (args: UpdateCartConsentArgs) => Promise<void>,\n placeOrder: (cartUid: string) => Promise<unknown>,\n getCartStatus: (biId: string) => Promise<CartStatusResult>,\n getSalableUid: (maId: string) => Promise<ProductInfo>,\n isCurrentUserSubscriber: () => Promise<CurrentUserSubscriberResult | null>,\n getCourseDetail: (courseKey: string) => Promise<CourseDetail | null>,\n}\n\nexport interface DevAuth {\n iamUrl: string,\n clientId: string,\n clientSecret: string,\n}\n\n// --- Minimal Stripe.js types -------------------------------------------------\n// Just the surface this module uses. If you depend on `@stripe/stripe-js`,\n// you can replace these with its richer types.\nexport interface StripeElementChangeEvent {\n empty?: boolean,\n complete?: boolean,\n error?: { message?: string, code?: string },\n [key: string]: unknown,\n}\n\nexport interface CardFieldState {\n empty: boolean,\n complete: boolean,\n /** Stripe validation error message (e.g. \"Your card number is invalid.\"), empty string if no error. */\n error: string,\n /** True once the element has been blurred at least once. */\n blurred: boolean,\n /** True while the element's input has focus. */\n focused?: boolean,\n /** Card network Stripe detected from the number (e.g. 'visa'); card number only. */\n brand?: string,\n}\n\nexport interface CardFieldStates {\n number: CardFieldState,\n expiry: CardFieldState,\n cvc: CardFieldState,\n}\n\n// --- Stripe Payment Request (Apple Pay / Google Pay) -------------------------\nexport interface PaymentRequestPaymentMethodEvent {\n paymentMethod: {\n id: string,\n billing_details?: {\n address?: { country?: string },\n name?: string,\n email?: string,\n },\n },\n complete: (status: 'success' | 'fail') => void,\n}\n\nexport interface PaymentRequestCanMakePaymentResult {\n applePay?: boolean,\n googlePay?: boolean,\n link?: boolean,\n}\n\nexport interface PaymentRequestLike {\n canMakePayment: () => Promise<PaymentRequestCanMakePaymentResult | null>,\n on: (event: string, handler: (ev: PaymentRequestPaymentMethodEvent) => void) => void,\n show: () => void | Promise<void>,\n update: (details: { total: { label: string, amount: number } }) => void,\n}\n\nexport interface StripeElementLike {\n mount: (node: HTMLElement) => void,\n on: (event: string, handler: (...args: any[]) => void) => void,\n unmount?: () => void,\n destroy?: () => void,\n focus?: () => void,\n}\n\nexport interface StripeElementsOptions {\n mode?: 'payment' | 'setup' | 'subscription',\n amount?: number,\n currency?: string,\n /** Lets Express Checkout Element yield a PaymentMethod for our place-order flow. */\n paymentMethodCreation?: 'manual',\n}\n\nexport interface StripeElementsLike {\n create: (type: string, options?: Record<string, unknown>) => StripeElementLike,\n submit?: () => Promise<{ error?: StripeError }>,\n update?: (options: { amount?: number, currency?: string }) => void,\n}\n\nexport interface StripeError {\n message?: string,\n code?: string,\n /** Stripe.js error category, e.g. 'card_error' or 'api_connection_error'. */\n type?: string,\n}\n\nexport interface PaymentMethodResult {\n paymentMethod?: {\n id: string,\n billing_details?: {\n address?: { country?: string },\n name?: string,\n email?: string,\n },\n },\n error?: StripeError,\n}\n\nexport interface ConfirmResult {\n error?: StripeError,\n setupIntent?: unknown,\n paymentIntent?: unknown,\n}\n\nexport type CreatePaymentMethodParams =\n | {\n type: 'card',\n card: StripeElementLike,\n billing_details?: Record<string, unknown>,\n }\n | {\n elements: StripeElementsLike,\n };\n\nexport interface ConfirmCardPaymentData {\n payment_method?:\n | {\n card: StripeElementLike,\n billing_details?: Record<string, unknown>,\n }\n | string,\n}\n\n/** Express Checkout Element `click` — `resolve` must be called within 1s or the sheet won't open. */\nexport interface ExpressCheckoutClickEvent {\n expressPaymentType?: string,\n resolve: (opts?: { emailRequired?: boolean, billingAddressRequired?: boolean }) => void,\n}\n\nexport interface ExpressCheckoutConfirmEvent {\n expressPaymentType?: string,\n billingDetails?: {\n address?: { country?: string },\n name?: string,\n email?: string,\n },\n paymentFailed: (opts?: { reason?: string }) => void,\n}\n\nexport interface ExpressCheckoutReadyEvent {\n /** Deprecated by Stripe — prefer `availablepaymentmethodschange`. */\n availablePaymentMethods?: {\n applePay?: boolean,\n googlePay?: boolean,\n link?: boolean,\n } | undefined,\n}\n\n/** Fires on initial render and whenever wallet availability changes after load. */\nexport interface ExpressCheckoutAvailablePaymentMethodsChangeEvent {\n /** `undefined` when no buttons will render. */\n paymentMethods?: {\n applePay?: { available: boolean },\n googlePay?: { available: boolean },\n link?: { available: boolean },\n } | undefined,\n}\n\nexport interface StripeLike {\n elements: (options?: StripeElementsOptions) => StripeElementsLike,\n createPaymentMethod: (params: CreatePaymentMethodParams) => Promise<PaymentMethodResult>,\n confirmCardSetup: (clientSecret: string) => Promise<ConfirmResult>,\n confirmCardPayment: (\n clientSecret: string,\n data?: ConfirmCardPaymentData,\n ) => Promise<ConfirmResult>,\n paymentRequest: (options: {\n country: string,\n currency: string,\n total: { label: string, amount: number },\n requestPayerName?: boolean,\n requestPayerEmail?: boolean,\n disableWallets?: ('link' | 'applePay' | 'googlePay' | 'browserCard')[],\n }) => PaymentRequestLike,\n}\n\ndeclare global {\n interface Window {\n Stripe?: (publishableKey: string) => StripeLike,\n }\n}\n\nexport interface TrialDateRange {\n /** e.g. \"June 22, 2026\" */\n displayStart: string,\n /** e.g. \"June 29, 2026\" */\n displayEnd: string,\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Status, Phase } from './constants';\n\nexport type { Status, Phase };\n\n// --- Bootstrap domain --------------------------------------------------------\nexport type GqlRunner = (query: string, variables?: Record<string, unknown>, retry?: boolean) => Promise<any>;\n\n// --- Cart domain -------------------------------------------------------------\nexport interface Cart {\n biId: string,\n uid: string,\n}\n\nexport interface CartIds {\n customerUid: string,\n salableUid: string,\n billingPlanUid: string,\n}\n\nexport type BillingCycle = 'monthly' | 'annual';\n\nexport type PaymentMethod = 'card' | 'googlepay' | 'paypal';\n\nexport type SupportedPaymentMethod = Exclude<PaymentMethod, 'googlepay'>;\n\nexport type BillingPeriod = 'MONTHLY' | 'ANNUAL' | 'QUARTERLY' | string;\n\nexport interface BillingPlanOwnershipModel {\n uid: string,\n omName: string,\n}\n\nexport interface BillingPlan {\n uid: string,\n stripePriceId: string,\n /** Price amount e.g. \"39.99\" */\n amount: string,\n /** Currency code e.g. \"USD\" */\n currency: string,\n isTemplate: boolean,\n ownershipModel: BillingPlanOwnershipModel,\n}\n\nexport interface CurrentUserSubscriberResult {\n isSubscriber: boolean,\n subscriptionBiId: string | null,\n status: string | null,\n subscriptionStartDate: string | null,\n currentPeriodEnd: string | null,\n}\n\n/** Course shown on checkout / post-checkout when arriving via ?course_run_key=. */\nexport interface CourseDetail {\n maId: string,\n maName: string,\n maDescription: string | null,\n tShortDescription: string | null,\n imageUrl: string | null,\n tCourseKey: string | null,\n tBrandText: string | null,\n tPrimarySubjectArea: string | null,\n tLevelType: string | null,\n tLanguage: string | null,\n tPacingType: string | null,\n tDurationLow: number | null,\n tDurationHigh: number | null,\n tDurationUnit: string | null,\n tEffortLow: number | null,\n tEffortHigh: number | null,\n tEffortUnit: string | null,\n tUrlCourse: string | null,\n tB2cSubscriptionInclusion: boolean | null,\n tHasOfacRestrictions: boolean | null,\n tCatalogActive: boolean | null,\n /** How many learners are enrolled in this course — real per-course count, not the\n * platform-wide subscription figure. */\n tEnrollmentCount: number | null,\n}\n\n/** Returned by legacy subscription billing lookups (unused by à la carte). */\nexport interface BillingPlansResult {\n plans: BillingPlan[],\n}\n\n/** Returned by getSalableUid — the product uid and its ownership models. */\nexport interface ProductInfo {\n uid: string,\n maName: string,\n ownershipModels: { uid: string, omName: string }[],\n}\n\nexport interface CartStatusResult {\n status: Status | null,\n stripeSubscriptionId: string | null,\n /** Stripe-hosted challenge URL for the checkout confirmation step. */\n stripeConfirmationRedirectUrl: string | null,\n /** PayPal-hosted approval URL for the same checkout confirmation step. */\n paypalApprovalUrl: string | null,\n lastComment: string,\n}\n\nexport interface CartBillingAddress {\n tFirstName: string,\n tLastName: string,\n upaLine1: string,\n upaCity: string,\n upaPostcode: string,\n gadStateOrProvince: string,\n gadCountry: { iso2Code: string },\n}\n\nexport interface UpdateCartItemArgs {\n cartItemUid: string,\n billingAddress?: CartBillingAddress,\n paymentMethodId?: string,\n /** Payer email attached when the payment type is TwouPaypalPayment. */\n paypalEmail?: string | null,\n}\n\n/** Auto-renewal consent captured on TwouCart at checkout confirmation (SUBS-228). */\nexport interface CheckoutConsent {\n /** Main auto-renewal checkbox — always required at submit. */\n tConsentRecurring: boolean,\n /** UK/CA resident checkbox; null when that checkbox is not shown. */\n tConsentUkCa: boolean | null,\n /** ISO-8601 timestamp when consent was captured. */\n tConsentAt: string,\n /** Exact disclosure text shown to the learner (audit trail). */\n tConsentText: string,\n}\n\nexport interface UpdateCartConsentArgs {\n cartUid: string,\n consent: CheckoutConsent,\n /** Absolute checkout return URL stored in the backend's tStripeReturnUrl field. */\n returnUrl?: string | null,\n}\n\nexport interface BillingInfo {\n firstName: string,\n lastName: string,\n city: string,\n zip: string,\n country: string,\n line1: string,\n state: string,\n}\n\n// --- Checkout client surface -------------------------------------------------\nexport interface CheckoutClient {\n gql: GqlRunner,\n setToken: (token: string) => void,\n createCart: (vars: CartIds) => Promise<Cart>,\n getCartItem: (biId: string) => Promise<{ cartUid: string, cartItemUid: string }>,\n updateCartItem: (args: UpdateCartItemArgs) => Promise<void>,\n updateCartConsent: (args: UpdateCartConsentArgs) => Promise<void>,\n placeOrder: (cartUid: string) => Promise<unknown>,\n getCartStatus: (biId: string) => Promise<CartStatusResult>,\n getSalableUid: (maId: string) => Promise<ProductInfo>,\n isCurrentUserSubscriber: () => Promise<CurrentUserSubscriberResult | null>,\n getCourseDetail: (courseKey: string) => Promise<CourseDetail | null>,\n}\n\nexport interface DevAuth {\n iamUrl: string,\n clientId: string,\n clientSecret: string,\n}\n\n// --- Minimal Stripe.js types -------------------------------------------------\n// Just the surface this module uses. If you depend on `@stripe/stripe-js`,\n// you can replace these with its richer types.\nexport interface StripeElementChangeEvent {\n empty?: boolean,\n complete?: boolean,\n error?: { message?: string, code?: string },\n [key: string]: unknown,\n}\n\nexport interface CardFieldState {\n empty: boolean,\n complete: boolean,\n /** Stripe validation error message (e.g. \"Your card number is invalid.\"), empty string if no error. */\n error: string,\n /** True once the element has been blurred at least once. */\n blurred: boolean,\n /** True while the element's input has focus. */\n focused?: boolean,\n /** Card network Stripe detected from the number (e.g. 'visa'); card number only. */\n brand?: string,\n}\n\nexport interface CardFieldStates {\n number: CardFieldState,\n expiry: CardFieldState,\n cvc: CardFieldState,\n}\n\n// --- Stripe Payment Request (Apple Pay / Google Pay) -------------------------\nexport interface PaymentRequestPaymentMethodEvent {\n paymentMethod: {\n id: string,\n billing_details?: {\n address?: { country?: string },\n name?: string,\n email?: string,\n },\n },\n complete: (status: 'success' | 'fail') => void,\n}\n\nexport interface PaymentRequestCanMakePaymentResult {\n applePay?: boolean,\n googlePay?: boolean,\n link?: boolean,\n}\n\nexport interface PaymentRequestLike {\n canMakePayment: () => Promise<PaymentRequestCanMakePaymentResult | null>,\n on: (event: string, handler: (ev: PaymentRequestPaymentMethodEvent) => void) => void,\n show: () => void | Promise<void>,\n update: (details: { total: { label: string, amount: number } }) => void,\n}\n\nexport interface StripeElementLike {\n mount: (node: HTMLElement) => void,\n on: (event: string, handler: (...args: any[]) => void) => void,\n unmount?: () => void,\n destroy?: () => void,\n focus?: () => void,\n}\n\nexport interface StripeElementsOptions {\n mode?: 'payment' | 'setup' | 'subscription',\n amount?: number,\n currency?: string,\n /** Lets Express Checkout Element yield a PaymentMethod for our place-order flow. */\n paymentMethodCreation?: 'manual',\n}\n\nexport interface StripeElementsLike {\n create: (type: string, options?: Record<string, unknown>) => StripeElementLike,\n submit?: () => Promise<{ error?: StripeError }>,\n update?: (options: { amount?: number, currency?: string }) => void,\n}\n\nexport interface StripeError {\n message?: string,\n code?: string,\n /** Stripe.js error category, e.g. 'card_error' or 'api_connection_error'. */\n type?: string,\n}\n\nexport interface PaymentMethodResult {\n paymentMethod?: {\n id: string,\n billing_details?: {\n address?: { country?: string },\n name?: string,\n email?: string,\n },\n },\n error?: StripeError,\n}\n\nexport interface ConfirmResult {\n error?: StripeError,\n setupIntent?: unknown,\n paymentIntent?: unknown,\n}\n\nexport type CreatePaymentMethodParams =\n | {\n type: 'card',\n card: StripeElementLike,\n billing_details?: Record<string, unknown>,\n }\n | {\n elements: StripeElementsLike,\n };\n\nexport interface ConfirmCardPaymentData {\n payment_method?:\n | {\n card: StripeElementLike,\n billing_details?: Record<string, unknown>,\n }\n | string,\n}\n\n/** Express Checkout Element `click` — `resolve` must be called within 1s or the sheet won't open. */\nexport interface ExpressCheckoutClickEvent {\n expressPaymentType?: string,\n resolve: () => void,\n}\n\nexport interface ExpressCheckoutConfirmEvent {\n expressPaymentType?: string,\n billingDetails?: {\n address?: { country?: string },\n name?: string,\n email?: string,\n },\n paymentFailed: (opts?: { reason?: string }) => void,\n}\n\nexport interface ExpressCheckoutReadyEvent {\n /** Deprecated by Stripe — prefer `availablepaymentmethodschange`. */\n availablePaymentMethods?: {\n applePay?: boolean,\n googlePay?: boolean,\n link?: boolean,\n } | undefined,\n}\n\n/** Fires on initial render and whenever wallet availability changes after load. */\nexport interface ExpressCheckoutAvailablePaymentMethodsChangeEvent {\n /** `undefined` when no buttons will render. */\n paymentMethods?: {\n applePay?: { available: boolean },\n googlePay?: { available: boolean },\n link?: { available: boolean },\n } | undefined,\n}\n\nexport interface StripeLike {\n elements: (options?: StripeElementsOptions) => StripeElementsLike,\n createPaymentMethod: (params: CreatePaymentMethodParams) => Promise<PaymentMethodResult>,\n confirmCardSetup: (clientSecret: string) => Promise<ConfirmResult>,\n confirmCardPayment: (\n clientSecret: string,\n data?: ConfirmCardPaymentData,\n ) => Promise<ConfirmResult>,\n paymentRequest: (options: {\n country: string,\n currency: string,\n total: { label: string, amount: number },\n requestPayerName?: boolean,\n requestPayerEmail?: boolean,\n disableWallets?: ('link' | 'applePay' | 'googlePay' | 'browserCard')[],\n }) => PaymentRequestLike,\n}\n\ndeclare global {\n interface Window {\n Stripe?: (publishableKey: string) => StripeLike,\n }\n}\n\nexport interface TrialDateRange {\n /** e.g. \"June 22, 2026\" */\n displayStart: string,\n /** e.g. \"June 29, 2026\" */\n displayEnd: string,\n}\n"]}
|