@edx/frontend-app-alacarte-checkout 1.28.0 → 1.29.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.
- package/dist/app.js +1 -1
- package/dist/app.js.map +1 -1
- package/dist/checkoutPage/CheckoutPage.js +3 -1
- package/dist/checkoutPage/CheckoutPage.js.map +1 -1
- package/dist/components/Checkout/Checkout.d.ts +3 -1
- package/dist/components/Checkout/Checkout.js +8 -6
- package/dist/components/Checkout/Checkout.js.map +1 -1
- package/dist/components/ExpressCheckout/ExpressCheckout.d.ts +8 -5
- package/dist/components/ExpressCheckout/ExpressCheckout.js +83 -6
- package/dist/components/ExpressCheckout/ExpressCheckout.js.map +1 -1
- package/dist/components/ExpressCheckout/Messages.d.ts +5 -0
- package/dist/components/ExpressCheckout/Messages.js +5 -0
- package/dist/components/ExpressCheckout/Messages.js.map +1 -1
- package/dist/components/PaymentForm/PaymentForm.d.ts +7 -3
- package/dist/components/PaymentForm/PaymentForm.js +2 -7
- package/dist/components/PaymentForm/PaymentForm.js.map +1 -1
- package/dist/components/ProgramEnrollmentCard/ProgramEnrollmentCard.js +1 -1
- package/dist/components/ProgramEnrollmentCard/ProgramEnrollmentCard.js.map +1 -1
- package/dist/data/hooks/useAlacarteCheckout.d.ts +11 -0
- package/dist/data/hooks/useAlacarteCheckout.js +113 -3
- package/dist/data/hooks/useAlacarteCheckout.js.map +1 -1
- package/dist/styles/components/expressCheckout.scss +16 -0
- package/dist/types/alacarte.d.ts +21 -1
- package/dist/types/alacarte.js.map +1 -1
- package/dist/utils/alacarteApi.d.ts +6 -2
- package/dist/utils/alacarteApi.js +34 -4
- package/dist/utils/alacarteApi.js.map +1 -1
- package/dist/utils/alacarteCheckout.js +3 -1
- package/dist/utils/alacarteCheckout.js.map +1 -1
- package/dist/utils/alacartePayment.d.ts +18 -0
- package/dist/utils/alacartePayment.js +27 -0
- package/dist/utils/alacartePayment.js.map +1 -1
- package/dist/utils/alacarteQueries.d.ts +7 -1
- package/dist/utils/alacarteQueries.js +12 -0
- package/dist/utils/alacarteQueries.js.map +1 -1
- package/dist/utils/paypal.d.ts +34 -0
- package/dist/utils/paypal.js +39 -0
- package/dist/utils/paypal.js.map +1 -0
- package/dist/utils/placeOrderErrors.js +5 -0
- package/dist/utils/placeOrderErrors.js.map +1 -1
- package/dist/utils/provision.js +2 -2
- package/dist/utils/provision.js.map +1 -1
- package/package.json +1 -1
package/dist/app.js
CHANGED
|
@@ -5,7 +5,7 @@ const app = {
|
|
|
5
5
|
appId,
|
|
6
6
|
routes,
|
|
7
7
|
slots,
|
|
8
|
-
// Environment-specific values (STRIPE_PUBLIC_KEY, VIAX_API_URL)
|
|
8
|
+
// Environment-specific values (STRIPE_PUBLIC_KEY, VIAX_API_URL, PAYPAL_CLIENT_ID)
|
|
9
9
|
// are supplied by site.config.{dev,stage,prod}.tsx at site build time.
|
|
10
10
|
};
|
|
11
11
|
export default app;
|
package/dist/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,MAAM,GAAG,GAAQ;IACf,KAAK;IACL,MAAM;IACN,KAAK;IACL,
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,MAAM,GAAG,GAAQ;IACf,KAAK;IACL,MAAM;IACN,KAAK;IACL,kFAAkF;IAClF,uEAAuE;CACxE,CAAC;AAEF,eAAe,GAAG,CAAC","sourcesContent":["import { App } from '@openedx/frontend-base';\nimport { appId } from '@src/constants';\nimport routes from '@src/routes';\nimport slots from '@src/slots';\n\nconst app: App = {\n appId,\n routes,\n slots,\n // Environment-specific values (STRIPE_PUBLIC_KEY, VIAX_API_URL, PAYPAL_CLIENT_ID)\n // are supplied by site.config.{dev,stage,prod}.tsx at site build time.\n};\n\nexport default app;\n"]}
|
|
@@ -9,6 +9,8 @@ const CheckoutPage = () => {
|
|
|
9
9
|
const siteConfig = getSiteConfig();
|
|
10
10
|
const LMS_BASE_URL = siteConfig.lmsBaseUrl.replace(/\/$/, '');
|
|
11
11
|
const stripePublishableKey = config.STRIPE_PUBLIC_KEY;
|
|
12
|
+
// Optional — the PayPal express button stays disabled without it.
|
|
13
|
+
const paypalClientId = config.PAYPAL_CLIENT_ID || undefined;
|
|
12
14
|
const apiUrl = config.VIAX_API_URL;
|
|
13
15
|
const isDevelopment = siteConfig.environment === 'development';
|
|
14
16
|
const disableComplianceCheck = config.DISABLE_COMPLIANCE_CHECK === true;
|
|
@@ -21,7 +23,7 @@ const CheckoutPage = () => {
|
|
|
21
23
|
if (!stripePublishableKey || !apiUrl || !edxSessionUrl) {
|
|
22
24
|
return (_jsx(PageWrapper, { children: _jsxs(Alert, { variant: "danger", children: ["We're having trouble loading the checkout. Please refresh the page or try again in a few moments. If the problem persists,", ' ', _jsx("a", { href: "https://courses.edx.org/support/contact_us", children: "contact support" }), "."] }) }));
|
|
23
25
|
}
|
|
24
|
-
return (_jsx(PageWrapper, { children: _jsx(CheckoutGate, { stripePublishableKey: stripePublishableKey, apiUrl: apiUrl, edxSessionUrl: edxSessionUrl, geolocationUrl: geolocationUrl, complianceCheckUrl: complianceCheckUrl, disableComplianceCheck: disableComplianceCheck, skipSubscriptionCourseRuns: skipSubscriptionCourseRuns, learnerDashboardUrl: `${LMS_BASE_URL}/dashboard`, homeUrl: LMS_BASE_URL || '/', onComplete: (_subscriptionBiId) => {
|
|
26
|
+
return (_jsx(PageWrapper, { children: _jsx(CheckoutGate, { stripePublishableKey: stripePublishableKey, paypalClientId: paypalClientId, apiUrl: apiUrl, edxSessionUrl: edxSessionUrl, geolocationUrl: geolocationUrl, complianceCheckUrl: complianceCheckUrl, disableComplianceCheck: disableComplianceCheck, skipSubscriptionCourseRuns: skipSubscriptionCourseRuns, learnerDashboardUrl: `${LMS_BASE_URL}/dashboard`, homeUrl: LMS_BASE_URL || '/', onComplete: (_subscriptionBiId) => {
|
|
25
27
|
console.log(_subscriptionBiId);
|
|
26
28
|
// window.location.href = `/checkout/confirmation?sub=${_subscriptionBiId ?? ''}`;
|
|
27
29
|
// Success screen.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckoutPage.js","sourceRoot":"","sources":["../../src/checkoutPage/CheckoutPage.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,YAAY,MAAM,yCAAyC,CAAC;AAEnE,MAAM,WAAW,GAA4C,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAC7E,KAAC,SAAS,cAAE,QAAQ,GAAa,CAClC,CAAC;AAEF,MAAM,YAAY,GAAa,GAAG,EAAE;IAClC,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACnC,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IACnC,MAAM,YAAY,GAAG,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC9D,MAAM,oBAAoB,GAAG,MAAM,CAAC,iBAA2B,CAAC;IAChE,MAAM,MAAM,GAAG,MAAM,CAAC,YAAsB,CAAC;IAC7C,MAAM,aAAa,GAAG,UAAU,CAAC,WAAW,KAAK,aAAa,CAAC;IAC/D,MAAM,sBAAsB,GAAG,MAAM,CAAC,w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@openedx/paragon';\nimport { getAppConfig, getSiteConfig } from '@openedx/frontend-base';\nimport { appId } from '@src/constants';\nimport CheckoutGate from '../components/CheckoutGate/CheckoutGate';\n\nconst PageWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => (\n <Container>{children}</Container>\n);\n\nconst CheckoutPage: React.FC = () => {\n const config = getAppConfig(appId);\n const siteConfig = getSiteConfig();\n const LMS_BASE_URL = siteConfig.lmsBaseUrl.replace(/\\/$/, '');\n const stripePublishableKey = config.STRIPE_PUBLIC_KEY as string;\n const apiUrl = config.VIAX_API_URL as string;\n const isDevelopment = siteConfig.environment === 'development';\n const disableComplianceCheck = config.DISABLE_COMPLIANCE_CHECK === true;\n const skipSubscriptionCourseRuns = config.SKIP_SUBSCRIPTION_COURSE_RUNS === true;\n const edxSessionUrl = `${isDevelopment ? 'https://courses.stage.edx.org' : LMS_BASE_URL}/api/edx-session`;\n const geolocationUrl = `${isDevelopment ? 'https://courses.stage.edx.org' : LMS_BASE_URL}/api/geolocation/lookup`;\n const complianceCheckUrl = disableComplianceCheck\n ? undefined\n : `${isDevelopment ? 'https://courses.stage.edx.org' : LMS_BASE_URL}/api/compliance-check`;\n\n if (!stripePublishableKey || !apiUrl || !edxSessionUrl) {\n return (\n <PageWrapper>\n <Alert variant=\"danger\">\n We're having trouble loading the checkout. Please refresh the\n page or try again in a few moments. If the problem persists,{' '}\n <a href=\"https://courses.edx.org/support/contact_us\">\n contact support\n </a>\n .\n </Alert>\n </PageWrapper>\n );\n }\n\n return (\n <PageWrapper>\n <CheckoutGate\n stripePublishableKey={stripePublishableKey}\n apiUrl={apiUrl}\n edxSessionUrl={edxSessionUrl}\n geolocationUrl={geolocationUrl}\n complianceCheckUrl={complianceCheckUrl}\n disableComplianceCheck={disableComplianceCheck}\n skipSubscriptionCourseRuns={skipSubscriptionCourseRuns}\n learnerDashboardUrl={`${LMS_BASE_URL}/dashboard`}\n homeUrl={LMS_BASE_URL || '/'}\n onComplete={(_subscriptionBiId) => {\n console.log(_subscriptionBiId);\n // window.location.href = `/checkout/confirmation?sub=${_subscriptionBiId ?? ''}`;\n // Success screen.\n }}\n />\n </PageWrapper>\n );\n};\n\nexport default CheckoutPage;\n"]}
|
|
1
|
+
{"version":3,"file":"CheckoutPage.js","sourceRoot":"","sources":["../../src/checkoutPage/CheckoutPage.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,YAAY,MAAM,yCAAyC,CAAC;AAEnE,MAAM,WAAW,GAA4C,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAC7E,KAAC,SAAS,cAAE,QAAQ,GAAa,CAClC,CAAC;AAEF,MAAM,YAAY,GAAa,GAAG,EAAE;IAClC,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACnC,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IACnC,MAAM,YAAY,GAAG,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC9D,MAAM,oBAAoB,GAAG,MAAM,CAAC,iBAA2B,CAAC;IAChE,kEAAkE;IAClE,MAAM,cAAc,GAAI,MAAM,CAAC,gBAAuC,IAAI,SAAS,CAAC;IACpF,MAAM,MAAM,GAAG,MAAM,CAAC,YAAsB,CAAC;IAC7C,MAAM,aAAa,GAAG,UAAU,CAAC,WAAW,KAAK,aAAa,CAAC;IAC/D,MAAM,sBAAsB,GAAG,MAAM,CAAC,wBAAwB,KAAK,IAAI,CAAC;IACxE,MAAM,0BAA0B,GAAG,MAAM,CAAC,6BAA6B,KAAK,IAAI,CAAC;IACjF,MAAM,aAAa,GAAG,GAAG,aAAa,CAAC,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC,YAAY,kBAAkB,CAAC;IAC1G,MAAM,cAAc,GAAG,GAAG,aAAa,CAAC,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC,YAAY,yBAAyB,CAAC;IAClH,MAAM,kBAAkB,GAAG,sBAAsB;QAC/C,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC,YAAY,uBAAuB,CAAC;IAE7F,IAAI,CAAC,oBAAoB,IAAI,CAAC,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QACvD,OAAO,CACL,KAAC,WAAW,cACV,MAAC,KAAK,IAAC,OAAO,EAAC,QAAQ,2IAEwC,GAAG,EAChE,YAAG,IAAI,EAAC,4CAA4C,gCAEhD,SAEE,GACI,CACf,CAAC;IACJ,CAAC;IAED,OAAO,CACL,KAAC,WAAW,cACV,KAAC,YAAY,IACX,oBAAoB,EAAE,oBAAoB,EAC1C,cAAc,EAAE,cAAc,EAC9B,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,aAAa,EAC5B,cAAc,EAAE,cAAc,EAC9B,kBAAkB,EAAE,kBAAkB,EACtC,sBAAsB,EAAE,sBAAsB,EAC9C,0BAA0B,EAAE,0BAA0B,EACtD,mBAAmB,EAAE,GAAG,YAAY,YAAY,EAChD,OAAO,EAAE,YAAY,IAAI,GAAG,EAC5B,UAAU,EAAE,CAAC,iBAAiB,EAAE,EAAE;gBAChC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;gBAC/B,kFAAkF;gBAClF,kBAAkB;YACpB,CAAC,GACD,GACU,CACf,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import React from 'react';\nimport { Alert, Container } from '@openedx/paragon';\nimport { getAppConfig, getSiteConfig } from '@openedx/frontend-base';\nimport { appId } from '@src/constants';\nimport CheckoutGate from '../components/CheckoutGate/CheckoutGate';\n\nconst PageWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => (\n <Container>{children}</Container>\n);\n\nconst CheckoutPage: React.FC = () => {\n const config = getAppConfig(appId);\n const siteConfig = getSiteConfig();\n const LMS_BASE_URL = siteConfig.lmsBaseUrl.replace(/\\/$/, '');\n const stripePublishableKey = config.STRIPE_PUBLIC_KEY as string;\n // Optional — the PayPal express button stays disabled without it.\n const paypalClientId = (config.PAYPAL_CLIENT_ID as string | undefined) || undefined;\n const apiUrl = config.VIAX_API_URL as string;\n const isDevelopment = siteConfig.environment === 'development';\n const disableComplianceCheck = config.DISABLE_COMPLIANCE_CHECK === true;\n const skipSubscriptionCourseRuns = config.SKIP_SUBSCRIPTION_COURSE_RUNS === true;\n const edxSessionUrl = `${isDevelopment ? 'https://courses.stage.edx.org' : LMS_BASE_URL}/api/edx-session`;\n const geolocationUrl = `${isDevelopment ? 'https://courses.stage.edx.org' : LMS_BASE_URL}/api/geolocation/lookup`;\n const complianceCheckUrl = disableComplianceCheck\n ? undefined\n : `${isDevelopment ? 'https://courses.stage.edx.org' : LMS_BASE_URL}/api/compliance-check`;\n\n if (!stripePublishableKey || !apiUrl || !edxSessionUrl) {\n return (\n <PageWrapper>\n <Alert variant=\"danger\">\n We're having trouble loading the checkout. Please refresh the\n page or try again in a few moments. If the problem persists,{' '}\n <a href=\"https://courses.edx.org/support/contact_us\">\n contact support\n </a>\n .\n </Alert>\n </PageWrapper>\n );\n }\n\n return (\n <PageWrapper>\n <CheckoutGate\n stripePublishableKey={stripePublishableKey}\n paypalClientId={paypalClientId}\n apiUrl={apiUrl}\n edxSessionUrl={edxSessionUrl}\n geolocationUrl={geolocationUrl}\n complianceCheckUrl={complianceCheckUrl}\n disableComplianceCheck={disableComplianceCheck}\n skipSubscriptionCourseRuns={skipSubscriptionCourseRuns}\n learnerDashboardUrl={`${LMS_BASE_URL}/dashboard`}\n homeUrl={LMS_BASE_URL || '/'}\n onComplete={(_subscriptionBiId) => {\n console.log(_subscriptionBiId);\n // window.location.href = `/checkout/confirmation?sub=${_subscriptionBiId ?? ''}`;\n // Success screen.\n }}\n />\n </PageWrapper>\n );\n};\n\nexport default CheckoutPage;\n"]}
|
|
@@ -6,6 +6,8 @@ export type CheckoutProps = UseCheckoutOptions & {
|
|
|
6
6
|
geolocationUrl?: string;
|
|
7
7
|
/** Learner dashboard / order history URL for confirmation CTAs. */
|
|
8
8
|
orderHistoryUrl?: string;
|
|
9
|
+
/** PayPal JS SDK client id — enables the express PayPal button. */
|
|
10
|
+
paypalClientId?: string;
|
|
9
11
|
};
|
|
10
|
-
declare const Checkout: ({ homeUrl, orderHistoryUrl, ...props }: CheckoutProps) => import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
declare const Checkout: ({ homeUrl, orderHistoryUrl, paypalClientId, ...props }: CheckoutProps) => import("react/jsx-runtime").JSX.Element;
|
|
11
13
|
export default Checkout;
|
|
@@ -48,7 +48,7 @@ import messages from './Messages';
|
|
|
48
48
|
const REDIRECT_ON_NO_ACTIVE_CHECKOUT = false;
|
|
49
49
|
const Checkout = (_a) => {
|
|
50
50
|
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
51
|
-
var { homeUrl = '/', orderHistoryUrl } = _a, props = __rest(_a, ["homeUrl", "orderHistoryUrl"]);
|
|
51
|
+
var { homeUrl = '/', orderHistoryUrl, paypalClientId } = _a, props = __rest(_a, ["homeUrl", "orderHistoryUrl", "paypalClientId"]);
|
|
52
52
|
const { formatMessage } = useIntl();
|
|
53
53
|
const alacarte = useAlacarteCheckout({
|
|
54
54
|
apiUrl: props.apiUrl,
|
|
@@ -122,10 +122,12 @@ const Checkout = (_a) => {
|
|
|
122
122
|
}),
|
|
123
123
|
});
|
|
124
124
|
}), [alacarte, c.billing, c.userCountry, c.stripe]);
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
// Express checkout (PayPal): tCheckoutPlaceOrder(PAYPAL) when the PayPal
|
|
126
|
+
// button is clicked; approve/cancel go straight to the à la carte hook.
|
|
127
|
+
// The card form isn't validated — PayPal collects the payer's details.
|
|
128
|
+
const handlePaypalCreateOrder = useCallback(() => alacarte.startPaypalOrder({
|
|
129
|
+
billing: Object.assign(Object.assign({}, c.billing), { country: c.billing.country || c.userCountry || '' }),
|
|
130
|
+
}), [alacarte, c.billing, c.userCountry]);
|
|
129
131
|
const showProcessing = c.returningFromStripe
|
|
130
132
|
&& c.processingSubscription
|
|
131
133
|
&& c.phase !== 'success'
|
|
@@ -245,7 +247,7 @@ const Checkout = (_a) => {
|
|
|
245
247
|
confirmCardPayment: c.confirmCardPayment,
|
|
246
248
|
});
|
|
247
249
|
}
|
|
248
|
-
: c.placeOrder, onValidationError: setShowValidationBanner, trialEnd: selectedCycle === 'monthly' ? displayEnd : undefined, priceToShow: null, cycleToShow: selectedCycle === 'monthly' ? 'monthly' : 'annual', userCountry: c.userCountry, geolocationUrl: props.geolocationUrl, alacarteLine: alacarte.line, stripe: c.stripe, expressCountry: c.billing.country || c.userCountry || 'US', onExpressPayment: isAlacarteReady ? handleExpressPayment : undefined,
|
|
250
|
+
: c.placeOrder, onValidationError: setShowValidationBanner, trialEnd: selectedCycle === 'monthly' ? displayEnd : undefined, priceToShow: null, cycleToShow: selectedCycle === 'monthly' ? 'monthly' : 'annual', userCountry: c.userCountry, geolocationUrl: props.geolocationUrl, alacarteLine: alacarte.line, stripe: c.stripe, expressCountry: c.billing.country || c.userCountry || 'US', onExpressPayment: isAlacarteReady ? handleExpressPayment : undefined, paypalClientId: paypalClientId, onPaypalCreateOrder: isAlacarteReady ? handlePaypalCreateOrder : undefined, onPaypalApprove: isAlacarteReady ? alacarte.approvePaypalOrder : undefined, onPaypalCancel: isAlacarteReady ? alacarte.cancelPaypalOrder : undefined })] })), c.phase === 'success' && (_jsx(SuccessScreen, { subscriptionBiId: ((_t = c.subscriptionDetails) === null || _t === void 0 ? void 0 : _t.biId) || '', cardLast4: ((_u = c.subscriptionDetails) === null || _u === void 0 ? void 0 : _u.cardLast4) || '', purchaseDate: displayStart, courseLabel: courseLabel, onFindCourse: handleStartCourse })), c.phase === 'blocked' && (_jsx(BlockedScreen, { detail: c.lastComment }))] }) }), _jsx(Col, { xs: 12, lg: 5, xxl: 3, className: "payment__summary", children: c.phase === 'success' ? (_jsx(EnrollmentSummary, { course: c.course, onStartCourse: handleStartCourse })) : (_jsx(CartSummary, { defaultCycle: selectedCycle, onCycleChange: c.processingSubscription ? undefined : c.setCycle, course: courseForSummary, alacarteLine: alacarte.line, programDetail: alacarteProgramDetail, programName: alacarte.ownedProductName, promoCode: isAlacarteReady ? {
|
|
249
251
|
value: promoCodeValue,
|
|
250
252
|
onChange: (next) => {
|
|
251
253
|
setPromoCodeValue(next);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkout.js","sourceRoot":"","sources":["../../../src/components/Checkout/Checkout.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAc,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,WAAW,MAAM,8BAA8B,CAAC;AAEvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACjF,OAAO,WAAW,MAAM,4BAA4B,CAAC;AACrD,OAAO,iBAAiB,MAAM,wCAAwC,CAAC;AACvE,OAAO,WAAW,MAAM,4BAA4B,CAAC;AACrD,OAAO,uBAAuB,MAAM,oDAAoD,CAAC;AACzF,OAAO,iBAAiB,MAAM,wCAAwC,C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C,CAAC,CAAC,IAAI;4CAClD,KAAK,EAAE,QAAQ,CAAC,WAAW;4CAC3B,UAAU,EAAE,QAAQ,CAAC,cAAc;4CACnC,QAAQ,EAAE,QAAQ,CAAC,YAAY;yCAChC,CAAC,CAAC,CAAC,IAAI,GACR,CACH,GACG,IACF,GACF,IACF,IACL,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import React, { useCallback, useEffect, useState } from 'react';\nimport { Alert, Button, Col, Row } from '@openedx/paragon';\nimport { CheckCircle, Error as ErrorIcon } from '@openedx/paragon/icons';\nimport { useIntl } from '@openedx/frontend-base';\nimport useCheckout from '../../data/hooks/useCheckout';\nimport type { UseCheckoutOptions } from '../../data/hooks/useCheckout';\nimport { useAlacarteCheckout } from '../../data/hooks/useAlacarteCheckout';\nimport { ALLOWED_CHECKOUT_COUNTRIES, GATE_CHECK_COUNTRY } from '../../constants';\nimport CartSummary from '../CartSummary/CartSummary';\nimport EnrollmentSummary from '../EnrollmentSummary/EnrollmentSummary';\nimport PaymentForm from '../PaymentForm/PaymentForm';\nimport CountryUnavailableModal from '../CountryUnavailableModal/CountryUnavailableModal';\nimport OrderBlockedModal from '../OrderBlockedModal/OrderBlockedModal';\nimport AlacarteNotice from '../AlacarteNotice/AlacarteNotice';\nimport AlacarteConfirmation from '../AlacarteConfirmation/AlacarteConfirmation';\nimport PaymentTimeoutAlert from '../PaymentTimeoutAlert/PaymentTimeoutAlert';\nimport PriceChangedAlert from '../PriceChangedAlert/PriceChangedAlert';\nimport AlacarteDebugPanel from '../AlacarteDebugPanel/AlacarteDebugPanel'; // TEMPORARY — remove alongside AlacarteDebugPanel\nimport { getTrialDateRange } from '@src/utils';\nimport { getLearnerFacingCheckoutMessage } from '../../utils/checkoutErrors';\nimport { appliedDiscountPercent } from '../../utils/discount';\nimport { confirmPaymentWithMethodId, getLearnerFacingStripeMessage } from '../../utils/stripeCard';\nimport { SuccessScreen, BlockedScreen, ProcessingScreen } from '../StatusScreens/StatusScreens';\nimport type { BillingCycle, CourseDetail } from '../../types';\nimport type { ProgramDetail } from '../../types/alacarte';\nimport messages from './Messages';\n\n// TEMPORARY — redirect-home-on-noActiveCheckout disabled per request; shows a\n// banner instead so the case is visible while the flow is being verified.\n// Flip back to true to restore the redirect.\nconst REDIRECT_ON_NO_ACTIVE_CHECKOUT = false;\n\nexport type CheckoutProps = UseCheckoutOptions & {\n /** Homepage URL for the country-unavailable modal CTA. */\n homeUrl?: string,\n /** Endpoint used to look up the representative IP for a selected country. */\n geolocationUrl?: string,\n /** Learner dashboard / order history URL for confirmation CTAs. */\n orderHistoryUrl?: string,\n};\n\nconst Checkout = ({\n homeUrl = '/',\n orderHistoryUrl,\n ...props\n}: CheckoutProps) => {\n const { formatMessage } = useIntl();\n const alacarte = useAlacarteCheckout({\n apiUrl: props.apiUrl,\n edxSessionUrl: props.edxSessionUrl,\n skipSubscriptionCourseRuns: props.skipSubscriptionCourseRuns,\n });\n const c = useCheckout(props);\n const [promoCodeValue, setPromoCodeValue] = useState('');\n const [dismissedCouponAlert, setDismissedCouponAlert] = useState<string | null>(null);\n const [showValidationBanner, setShowValidationBanner] = useState(false);\n const [dismissedPriceChange, setDismissedPriceChange] = useState(false);\n // Last code we successfully priced — drives the \"Save {percent}% with code\n // {code}\" hint on the empty field while a coupon is not yet applied.\n const [advertisedOffer, setAdvertisedOffer] = useState<{ code: string, percent: number } | null>(null);\n const isAlacarteReady = (alacarte.phase === 'ready' || alacarte.phase === 'alreadyOwned') && !!alacarte.checkout;\n const appliedCouponCode = alacarte.checkout?.couponCode?.trim()\n ? alacarte.checkout.couponCode.trim()\n : null;\n const discountPercent = appliedDiscountPercent(alacarte.line);\n // Only treat the line discount as a removable coupon when the backend says\n // so (or a coupon code is present). Automatic offers show only in CartSummary's\n // discount row and must not drive PromoCode's applied/remove UI.\n const isCouponDiscount = !!alacarte.line?.discount\n && alacarte.line.discountSource !== 'automatic'\n && (alacarte.line.discountSource === 'coupon' || !!appliedCouponCode);\n const appliedDiscount = isCouponDiscount && discountPercent != null\n ? {\n percent: discountPercent,\n amount: alacarte.line!.discount!.amount,\n currency: alacarte.line!.discount!.currency,\n }\n : null;\n\n // Keep the coupon field in sync when a code is applied via URL or API.\n // Don't overwrite the field with empty when only an automatic offer applies.\n useEffect(() => {\n if (alacarte.checkout?.couponCode) {\n setPromoCodeValue(alacarte.checkout.couponCode);\n }\n }, [alacarte.checkout?.couponCode]);\n\n useEffect(() => {\n if (appliedCouponCode && isCouponDiscount && discountPercent != null) {\n setAdvertisedOffer({ code: appliedCouponCode, percent: discountPercent });\n }\n }, [appliedCouponCode, isCouponDiscount, discountPercent]);\n\n // No query params and no active cart — nothing to check out, send the\n // learner home rather than showing a placeholder.\n useEffect(() => {\n if (REDIRECT_ON_NO_ACTIVE_CHECKOUT && alacarte.phase === 'noActiveCheckout') {\n window.location.href = homeUrl;\n }\n }, [alacarte.phase, homeUrl]);\n\n // Express checkout (Apple Pay / Google Pay): runs the full place-order flow\n // using a wallet-provided PaymentMethod id instead of the mounted card element.\n const handleExpressPayment = useCallback(async (paymentMethodId: string, walletCountry?: string) => {\n if (!c.stripe) throw new Error('Stripe not loaded');\n const stripeInstance = c.stripe;\n const country = (c.billing.country || walletCountry || c.userCountry || '').trim().toUpperCase();\n if (!country) {\n throw new Error('Please select a country before using Apple Pay or Google Pay.');\n }\n\n await alacarte.placeOrderAsync({\n billing: {\n ...c.billing,\n country,\n },\n confirmCardPayment: async (clientSecret: string) => {\n await confirmPaymentWithMethodId({\n stripe: stripeInstance,\n clientSecret,\n paymentMethodId,\n });\n },\n });\n }, [alacarte, c.billing, c.userCountry, c.stripe]);\n\n // PayPal collects country and postal code on PayPal's page, not this form.\n const handlePayPal = useCallback(() => {\n return undefined;\n }, []);\n\n const showProcessing\n = c.returningFromStripe\n && c.processingSubscription\n && c.phase !== 'success'\n && c.phase !== 'blocked'\n && c.phase !== 'failed';\n const showForm\n = !showProcessing\n && (c.phase === 'init'\n || c.phase === 'ready'\n || c.phase === 'failed'\n || c.phase === 'processing');\n const failedMessage = getLearnerFacingCheckoutMessage(c.lastComment);\n\n const { displayStart, displayEnd } = getTrialDateRange();\n\n const isBillingCountryBlocked = GATE_CHECK_COUNTRY\n && !!c.billing.country\n && !ALLOWED_CHECKOUT_COUNTRIES.includes(c.billing.country);\n\n const selectedCycle: BillingCycle = c.selectedCycle;\n\n // Prefer the à la carte course's own detail (skills/badge/image, richer than\n // the subscription flow's ?course_run_key= lookup) when we selected a course.\n // When already-owned the line may be null, so fall back to the selector kind.\n const isCourseProduct = alacarte.line?.kind === 'course' || alacarte.selector?.kind === 'course';\n const isProgramProduct = alacarte.line?.kind === 'program' || alacarte.selector?.kind === 'program';\n\n const alacarteCourseDetail: CourseDetail | null\n = isCourseProduct && alacarte.productDetail && 'maId' in alacarte.productDetail\n ? alacarte.productDetail\n : null;\n const courseForSummary = alacarteCourseDetail ?? c.course;\n\n const alacarteProgramDetail: ProgramDetail | null\n = isProgramProduct && alacarte.productDetail && 'tCourses' in alacarte.productDetail\n ? alacarte.productDetail\n : null;\n\n const handleStartCourse = () => {\n const alacarteCourseUrl = alacarteCourseDetail?.tUrlCourse\n || (alacarte.productDetail && 'tUrlCourse' in alacarte.productDetail\n ? alacarte.productDetail.tUrlCourse\n : null);\n if (alacarteCourseUrl) {\n window.location.href = alacarteCourseUrl;\n } else if (c.course?.tUrlCourse) {\n window.location.href = c.course.tUrlCourse;\n } else {\n window.location.href = homeUrl || '/';\n }\n };\n\n const courseLabel = c.course\n ? [c.course.tBrandText, c.course.maName].filter(Boolean).join(': ')\n : null;\n\n if (showProcessing) {\n return <ProcessingScreen />;\n }\n\n // TEMPORARY — flip to true to dump à la carte hook state while validating\n // against the real backend. Remove AlacarteDebugPanel once the flow is solid.\n const SHOW_ALACARTE_DEBUG = false;\n const alacarteDebug = SHOW_ALACARTE_DEBUG\n ? <AlacarteDebugPanel data={alacarte} />\n : null;\n\n // Confirmation: show once the order is ready (or failed to load). While\n // tPlacedOrder is still polling, keep the checkout form so Pay now can show\n // \"Processing...\" instead of a full-page loader.\n if (alacarte.placedOrder || alacarte.placedOrderError) {\n const confirmationTitle = alacarte.line?.kind === 'program'\n ? alacarte.line.programName\n : alacarte.line?.kind === 'course'\n ? alacarte.line.courseName\n : null;\n\n return (\n <>\n {alacarteDebug}\n <Row className=\"checkout__container alacarte-confirmation__container bg-light-200\">\n <Col xs={12}>\n <AlacarteConfirmation\n order={alacarte.placedOrder}\n awaiting={false}\n error={alacarte.placedOrderError}\n onContinue={handleStartCourse}\n productDetail={alacarte.productDetail}\n productTitle={confirmationTitle}\n ownedCourses={\n alacarte.line?.kind === 'program'\n ? (alacarte.line.ownedCourses ?? null)\n : null\n }\n orderHistoryUrl={orderHistoryUrl ?? null}\n placedAt={alacarte.placedOrderPlacedAt}\n />\n </Col>\n </Row>\n </>\n );\n }\n\n if (alacarte.phase === 'loading') {\n return (\n <>\n {alacarteDebug}\n <ProcessingScreen />\n </>\n );\n }\n if (alacarte.phase === 'noActiveCheckout' && REDIRECT_ON_NO_ACTIVE_CHECKOUT) {\n // Redirects home via the effect above — show a spinner rather than a\n // notice while that happens.\n return (\n <>\n {alacarteDebug}\n <ProcessingScreen />\n </>\n );\n }\n if (alacarte.phase === 'noActiveCheckout') {\n return (\n <>\n {alacarteDebug}\n <AlacarteNotice messageId={alacarte.noticeMessageId!} />\n </>\n );\n }\n // Product unavailable / not found / not purchasable — banner only, no checkout form.\n if (alacarte.phase === 'notPurchasable' || alacarte.phase === 'error') {\n return (\n <>\n {alacarteDebug}\n <Row className=\"checkout__container bg-light-200\">\n <Col xs={12}>\n <Alert\n variant=\"danger\"\n icon={ErrorIcon}\n data-testid=\"alacarte-error-banner\"\n >\n {alacarte.error || 'Something went wrong with checkout.'}\n </Alert>\n </Col>\n </Row>\n </>\n );\n }\n\n const isAlreadyOwned = alacarte.isAlreadyOwned;\n const { paymentTimedOut } = alacarte;\n // Grey out and block the form + summary; only the alert above stays usable.\n const isLocked = isAlreadyOwned || paymentTimedOut;\n // Price differs from what the learner viewed before checkout (ALC-159).\n const showPriceChangedAlert = !!alacarte.priceChanged && !dismissedPriceChange && !isLocked;\n const priceChangedKind = isProgramProduct ? 'program' : 'course';\n\n return (\n <>\n {alacarteDebug}\n <Row className=\"checkout__container bg-light-200\">\n <CountryUnavailableModal\n isOpen={isBillingCountryBlocked}\n homeUrl={homeUrl}\n />\n {alacarte.sanctionsBlocked && (\n <OrderBlockedModal\n isOpen\n referenceCode={alacarte.sanctionsBlocked.referenceCode}\n homeUrl={homeUrl}\n />\n )}\n <Col xs={12} className=\"d-lg-none\">\n <h1 className=\"font-weight-bold text-primary-900\">Checkout</h1>\n {/* Below lg the payment column renders under the summary\n (flex-column-reverse), so the warning goes up here instead. */}\n {paymentTimedOut && <PaymentTimeoutAlert className=\"mb-3\" />}\n {showPriceChangedAlert && (\n <PriceChangedAlert\n kind={priceChangedKind}\n onDismiss={() => setDismissedPriceChange(true)}\n className=\"mb-3\"\n />\n )}\n </Col>\n\n <Col xs={12} className={isLocked ? 'checkout__locked-overlay' : ''}>\n <Row className=\"flex-column-reverse gap-5 flex-lg-row\">\n {/* ── LEFT ── */}\n <Col xs={12} lg={7} xxl={9} className=\"payment__options\">\n <div>\n <h1 className=\"font-weight-bold text-primary-900 d-none d-lg-block mb-4\">\n Checkout\n </h1>\n\n {paymentTimedOut && (\n <PaymentTimeoutAlert className=\"checkout__overlay-alert d-none d-lg-flex mb-3\" />\n )}\n\n {isAlreadyOwned && (\n <Alert\n variant=\"danger\"\n icon={ErrorIcon}\n className=\"checkout__overlay-alert mb-3\"\n data-testid=\"already-owned-alert\"\n >\n <p className=\"mb-3\">\n {formatMessage(\n alacarte.selector?.kind === 'program'\n ? messages.alreadyPaidProgram\n : messages.alreadyPaidCourse,\n )}\n </p>\n <div className=\"d-flex align-items-center justify-content-end gap-3 flex-wrap\">\n {orderHistoryUrl && (\n <a href={orderHistoryUrl} className=\"text-gray-900 font-weight-bold\">\n {formatMessage(messages.viewOrderHistory)}\n </a>\n )}\n <Button variant=\"brand\" className=\"rounded-pill\" onClick={handleStartCourse}>\n {formatMessage(messages.goToCourse)}\n </Button>\n </div>\n </Alert>\n )}\n\n {c.error && (\n <Alert\n variant=\"danger\"\n icon={ErrorIcon}\n dismissible\n onClose={c.clearError}\n >\n {c.error}\n </Alert>\n )}\n\n {alacarte.placeOrderError && (\n <Alert\n variant=\"danger\"\n icon={ErrorIcon}\n dismissible\n onClose={alacarte.clearPlaceOrderError}\n className=\"mb-3\"\n >\n {alacarte.placeOrderError}\n </Alert>\n )}\n\n {alacarte.paymentDecline?.message && !alacarte.placeOrderError && !paymentTimedOut && (\n <Alert\n variant=\"danger\"\n icon={ErrorIcon}\n className=\"mb-3\"\n data-testid=\"payment-decline-alert\"\n >\n {getLearnerFacingStripeMessage({\n message: alacarte.paymentDecline.message,\n code: alacarte.paymentDecline.code ?? undefined,\n })}\n </Alert>\n )}\n\n {alacarte.couponError && (\n <Alert\n variant=\"danger\"\n icon={ErrorIcon}\n dismissible\n onClose={alacarte.clearCouponError}\n className=\"mb-3\"\n data-testid=\"coupon-error-alert\"\n >\n {alacarte.couponError}\n </Alert>\n )}\n\n {showPriceChangedAlert && (\n <PriceChangedAlert\n kind={priceChangedKind}\n onDismiss={() => setDismissedPriceChange(true)}\n className=\"d-none d-lg-flex mb-3\"\n />\n )}\n\n {!alacarte.priceAccepted && !alacarte.priceChanged && isAlacarteReady && alacarte.line?.amountDue && (\n <Alert variant=\"info\" className=\"mb-3\" data-testid=\"price-accept-notice\">\n {formatMessage(messages.priceChangedNotice, {\n amount: alacarte.line.amountDue.amount.toFixed(2),\n currency: alacarte.line.amountDue.currency,\n })}\n </Alert>\n )}\n\n {showForm && (\n <>\n {showValidationBanner && (\n <Alert variant=\"danger\" icon={ErrorIcon} className=\"mb-3\">\n {formatMessage(messages.validationBanner)}\n </Alert>\n )}\n {c.phase === 'failed' && (\n <Alert variant=\"danger\" icon={ErrorIcon} className=\"mb-3\">\n {failedMessage\n || formatMessage(messages.paymentProcessingDescription)}\n </Alert>\n )}\n {appliedCouponCode && appliedDiscount && dismissedCouponAlert !== appliedCouponCode && (\n <Alert\n variant=\"success\"\n icon={CheckCircle}\n dismissible\n closeLabel={formatMessage(messages.dismiss)}\n onClose={() => setDismissedCouponAlert(appliedCouponCode)}\n className=\"coupon-applied-alert\"\n data-testid=\"coupon-applied-alert\"\n >\n <span aria-hidden=\"true\">🎉 </span>\n {formatMessage(messages.couponAppliedAlert)}\n </Alert>\n )}\n {alacarte.removedCouponCode && (() => {\n const removedCode = alacarte.removedCouponCode;\n const removedText = formatMessage(\n messages.couponRemovedAlert,\n { code: removedCode },\n );\n // Bold the interpolated code without baking markup into the\n // translation string — find it in the formatted sentence.\n const codeIndex = removedText.indexOf(removedCode);\n return (\n <Alert\n variant=\"success\"\n icon={CheckCircle}\n dismissible\n closeLabel={formatMessage(messages.dismiss)}\n onClose={alacarte.clearRemovedCouponCode}\n className=\"coupon-removed-alert\"\n data-testid=\"coupon-removed-alert\"\n >\n {codeIndex === -1 ? removedText : (\n <>\n {removedText.slice(0, codeIndex)}\n <strong>{removedCode}</strong>\n {removedText.slice(codeIndex + removedCode.length)}\n </>\n )}\n </Alert>\n );\n })()}\n <PaymentForm\n billing={c.billing}\n setField={c.setField}\n numberMountRef={c.numberMountRef}\n expiryMountRef={c.expiryMountRef}\n cvcMountRef={c.cvcMountRef}\n cardError={c.cardError}\n cardFieldStates={c.cardFieldStates}\n stripeReady={c.stripeReady}\n sessionReady={c.sessionReady}\n submitting={\n isAlacarteReady\n ? (alacarte.placingOrder || alacarte.awaitingPlacedOrder)\n : c.processingSubscription\n }\n onPlaceOrder={\n isAlacarteReady\n ? () => {\n alacarte.placeOrder({\n billing: {\n ...c.billing,\n // Country is required on tCheckoutPlaceOrder (two-letter ISO).\n // Prefer the form selection; fall back to gate geolocation.\n country: c.billing.country || c.userCountry || '',\n },\n confirmCardPayment: c.confirmCardPayment,\n });\n }\n : c.placeOrder\n }\n onValidationError={setShowValidationBanner}\n trialEnd={selectedCycle === 'monthly' ? displayEnd : undefined}\n priceToShow={null}\n cycleToShow={selectedCycle === 'monthly' ? 'monthly' : 'annual'}\n userCountry={c.userCountry}\n geolocationUrl={props.geolocationUrl}\n alacarteLine={alacarte.line}\n stripe={c.stripe}\n expressCountry={c.billing.country || c.userCountry || 'US'}\n onExpressPayment={isAlacarteReady ? handleExpressPayment : undefined}\n onPayPal={isAlacarteReady ? handlePayPal : undefined}\n />\n </>\n )}\n\n {c.phase === 'success' && (\n <SuccessScreen\n subscriptionBiId={c.subscriptionDetails?.biId || ''}\n cardLast4={c.subscriptionDetails?.cardLast4 || ''}\n purchaseDate={displayStart}\n courseLabel={courseLabel}\n onFindCourse={handleStartCourse}\n />\n )}\n\n {c.phase === 'blocked' && (\n <BlockedScreen detail={c.lastComment} />\n )}\n </div>\n </Col>\n\n {/* ── RIGHT — swaps to EnrollmentSummary on success ── */}\n <Col xs={12} lg={5} xxl={3} className=\"payment__summary\">\n {c.phase === 'success' ? (\n <EnrollmentSummary\n course={c.course}\n onStartCourse={handleStartCourse}\n />\n ) : (\n <CartSummary\n defaultCycle={selectedCycle}\n onCycleChange={c.processingSubscription ? undefined : c.setCycle}\n course={courseForSummary}\n alacarteLine={alacarte.line}\n programDetail={alacarteProgramDetail}\n programName={alacarte.ownedProductName}\n promoCode={isAlacarteReady ? {\n value: promoCodeValue,\n onChange: (next) => {\n setPromoCodeValue(next);\n if (alacarte.couponError) alacarte.clearCouponError();\n },\n onApply: () => alacarte.applyCoupon(promoCodeValue),\n onRemove: () => {\n alacarte.removeCoupon();\n setPromoCodeValue('');\n setAdvertisedOffer(null);\n },\n appliedCode: appliedCouponCode,\n discount: appliedDiscount,\n offer: !appliedCouponCode ? advertisedOffer : null,\n error: alacarte.couponError,\n isApplying: alacarte.couponApplying,\n disabled: alacarte.placingOrder,\n } : null}\n />\n )}\n </Col>\n </Row>\n </Col>\n </Row>\n </>\n );\n};\n\nexport default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;4CAClD,KAAK,EAAE,QAAQ,CAAC,WAAW;4CAC3B,UAAU,EAAE,QAAQ,CAAC,cAAc;4CACnC,QAAQ,EAAE,QAAQ,CAAC,YAAY;yCAChC,CAAC,CAAC,CAAC,IAAI,GACR,CACH,GACG,IACF,GACF,IACF,IACL,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["import React, { useCallback, useEffect, useState } from 'react';\nimport { Alert, Button, Col, Row } from '@openedx/paragon';\nimport { CheckCircle, Error as ErrorIcon } from '@openedx/paragon/icons';\nimport { useIntl } from '@openedx/frontend-base';\nimport useCheckout from '../../data/hooks/useCheckout';\nimport type { UseCheckoutOptions } from '../../data/hooks/useCheckout';\nimport { useAlacarteCheckout } from '../../data/hooks/useAlacarteCheckout';\nimport { ALLOWED_CHECKOUT_COUNTRIES, GATE_CHECK_COUNTRY } from '../../constants';\nimport CartSummary from '../CartSummary/CartSummary';\nimport EnrollmentSummary from '../EnrollmentSummary/EnrollmentSummary';\nimport PaymentForm from '../PaymentForm/PaymentForm';\nimport CountryUnavailableModal from '../CountryUnavailableModal/CountryUnavailableModal';\nimport OrderBlockedModal from '../OrderBlockedModal/OrderBlockedModal';\nimport AlacarteNotice from '../AlacarteNotice/AlacarteNotice';\nimport AlacarteConfirmation from '../AlacarteConfirmation/AlacarteConfirmation';\nimport PaymentTimeoutAlert from '../PaymentTimeoutAlert/PaymentTimeoutAlert';\nimport PriceChangedAlert from '../PriceChangedAlert/PriceChangedAlert';\nimport AlacarteDebugPanel from '../AlacarteDebugPanel/AlacarteDebugPanel'; // TEMPORARY — remove alongside AlacarteDebugPanel\nimport { getTrialDateRange } from '@src/utils';\nimport { getLearnerFacingCheckoutMessage } from '../../utils/checkoutErrors';\nimport { appliedDiscountPercent } from '../../utils/discount';\nimport { confirmPaymentWithMethodId, getLearnerFacingStripeMessage } from '../../utils/stripeCard';\nimport { SuccessScreen, BlockedScreen, ProcessingScreen } from '../StatusScreens/StatusScreens';\nimport type { BillingCycle, CourseDetail } from '../../types';\nimport type { ProgramDetail } from '../../types/alacarte';\nimport messages from './Messages';\n\n// TEMPORARY — redirect-home-on-noActiveCheckout disabled per request; shows a\n// banner instead so the case is visible while the flow is being verified.\n// Flip back to true to restore the redirect.\nconst REDIRECT_ON_NO_ACTIVE_CHECKOUT = false;\n\nexport type CheckoutProps = UseCheckoutOptions & {\n /** Homepage URL for the country-unavailable modal CTA. */\n homeUrl?: string,\n /** Endpoint used to look up the representative IP for a selected country. */\n geolocationUrl?: string,\n /** Learner dashboard / order history URL for confirmation CTAs. */\n orderHistoryUrl?: string,\n /** PayPal JS SDK client id — enables the express PayPal button. */\n paypalClientId?: string,\n};\n\nconst Checkout = ({\n homeUrl = '/',\n orderHistoryUrl,\n paypalClientId,\n ...props\n}: CheckoutProps) => {\n const { formatMessage } = useIntl();\n const alacarte = useAlacarteCheckout({\n apiUrl: props.apiUrl,\n edxSessionUrl: props.edxSessionUrl,\n skipSubscriptionCourseRuns: props.skipSubscriptionCourseRuns,\n });\n const c = useCheckout(props);\n const [promoCodeValue, setPromoCodeValue] = useState('');\n const [dismissedCouponAlert, setDismissedCouponAlert] = useState<string | null>(null);\n const [showValidationBanner, setShowValidationBanner] = useState(false);\n const [dismissedPriceChange, setDismissedPriceChange] = useState(false);\n // Last code we successfully priced — drives the \"Save {percent}% with code\n // {code}\" hint on the empty field while a coupon is not yet applied.\n const [advertisedOffer, setAdvertisedOffer] = useState<{ code: string, percent: number } | null>(null);\n const isAlacarteReady = (alacarte.phase === 'ready' || alacarte.phase === 'alreadyOwned') && !!alacarte.checkout;\n const appliedCouponCode = alacarte.checkout?.couponCode?.trim()\n ? alacarte.checkout.couponCode.trim()\n : null;\n const discountPercent = appliedDiscountPercent(alacarte.line);\n // Only treat the line discount as a removable coupon when the backend says\n // so (or a coupon code is present). Automatic offers show only in CartSummary's\n // discount row and must not drive PromoCode's applied/remove UI.\n const isCouponDiscount = !!alacarte.line?.discount\n && alacarte.line.discountSource !== 'automatic'\n && (alacarte.line.discountSource === 'coupon' || !!appliedCouponCode);\n const appliedDiscount = isCouponDiscount && discountPercent != null\n ? {\n percent: discountPercent,\n amount: alacarte.line!.discount!.amount,\n currency: alacarte.line!.discount!.currency,\n }\n : null;\n\n // Keep the coupon field in sync when a code is applied via URL or API.\n // Don't overwrite the field with empty when only an automatic offer applies.\n useEffect(() => {\n if (alacarte.checkout?.couponCode) {\n setPromoCodeValue(alacarte.checkout.couponCode);\n }\n }, [alacarte.checkout?.couponCode]);\n\n useEffect(() => {\n if (appliedCouponCode && isCouponDiscount && discountPercent != null) {\n setAdvertisedOffer({ code: appliedCouponCode, percent: discountPercent });\n }\n }, [appliedCouponCode, isCouponDiscount, discountPercent]);\n\n // No query params and no active cart — nothing to check out, send the\n // learner home rather than showing a placeholder.\n useEffect(() => {\n if (REDIRECT_ON_NO_ACTIVE_CHECKOUT && alacarte.phase === 'noActiveCheckout') {\n window.location.href = homeUrl;\n }\n }, [alacarte.phase, homeUrl]);\n\n // Express checkout (Apple Pay / Google Pay): runs the full place-order flow\n // using a wallet-provided PaymentMethod id instead of the mounted card element.\n const handleExpressPayment = useCallback(async (paymentMethodId: string, walletCountry?: string) => {\n if (!c.stripe) throw new Error('Stripe not loaded');\n const stripeInstance = c.stripe;\n const country = (c.billing.country || walletCountry || c.userCountry || '').trim().toUpperCase();\n if (!country) {\n throw new Error('Please select a country before using Apple Pay or Google Pay.');\n }\n\n await alacarte.placeOrderAsync({\n billing: {\n ...c.billing,\n country,\n },\n confirmCardPayment: async (clientSecret: string) => {\n await confirmPaymentWithMethodId({\n stripe: stripeInstance,\n clientSecret,\n paymentMethodId,\n });\n },\n });\n }, [alacarte, c.billing, c.userCountry, c.stripe]);\n\n // Express checkout (PayPal): tCheckoutPlaceOrder(PAYPAL) when the PayPal\n // button is clicked; approve/cancel go straight to the à la carte hook.\n // The card form isn't validated — PayPal collects the payer's details.\n const handlePaypalCreateOrder = useCallback(() => alacarte.startPaypalOrder({\n billing: {\n ...c.billing,\n country: c.billing.country || c.userCountry || '',\n },\n }), [alacarte, c.billing, c.userCountry]);\n\n const showProcessing\n = c.returningFromStripe\n && c.processingSubscription\n && c.phase !== 'success'\n && c.phase !== 'blocked'\n && c.phase !== 'failed';\n const showForm\n = !showProcessing\n && (c.phase === 'init'\n || c.phase === 'ready'\n || c.phase === 'failed'\n || c.phase === 'processing');\n const failedMessage = getLearnerFacingCheckoutMessage(c.lastComment);\n\n const { displayStart, displayEnd } = getTrialDateRange();\n\n const isBillingCountryBlocked = GATE_CHECK_COUNTRY\n && !!c.billing.country\n && !ALLOWED_CHECKOUT_COUNTRIES.includes(c.billing.country);\n\n const selectedCycle: BillingCycle = c.selectedCycle;\n\n // Prefer the à la carte course's own detail (skills/badge/image, richer than\n // the subscription flow's ?course_run_key= lookup) when we selected a course.\n // When already-owned the line may be null, so fall back to the selector kind.\n const isCourseProduct = alacarte.line?.kind === 'course' || alacarte.selector?.kind === 'course';\n const isProgramProduct = alacarte.line?.kind === 'program' || alacarte.selector?.kind === 'program';\n\n const alacarteCourseDetail: CourseDetail | null\n = isCourseProduct && alacarte.productDetail && 'maId' in alacarte.productDetail\n ? alacarte.productDetail\n : null;\n const courseForSummary = alacarteCourseDetail ?? c.course;\n\n const alacarteProgramDetail: ProgramDetail | null\n = isProgramProduct && alacarte.productDetail && 'tCourses' in alacarte.productDetail\n ? alacarte.productDetail\n : null;\n\n const handleStartCourse = () => {\n const alacarteCourseUrl = alacarteCourseDetail?.tUrlCourse\n || (alacarte.productDetail && 'tUrlCourse' in alacarte.productDetail\n ? alacarte.productDetail.tUrlCourse\n : null);\n if (alacarteCourseUrl) {\n window.location.href = alacarteCourseUrl;\n } else if (c.course?.tUrlCourse) {\n window.location.href = c.course.tUrlCourse;\n } else {\n window.location.href = homeUrl || '/';\n }\n };\n\n const courseLabel = c.course\n ? [c.course.tBrandText, c.course.maName].filter(Boolean).join(': ')\n : null;\n\n if (showProcessing) {\n return <ProcessingScreen />;\n }\n\n // TEMPORARY — flip to true to dump à la carte hook state while validating\n // against the real backend. Remove AlacarteDebugPanel once the flow is solid.\n const SHOW_ALACARTE_DEBUG = false;\n const alacarteDebug = SHOW_ALACARTE_DEBUG\n ? <AlacarteDebugPanel data={alacarte} />\n : null;\n\n // Confirmation: show once the order is ready (or failed to load). While\n // tPlacedOrder is still polling, keep the checkout form so Pay now can show\n // \"Processing...\" instead of a full-page loader.\n if (alacarte.placedOrder || alacarte.placedOrderError) {\n const confirmationTitle = alacarte.line?.kind === 'program'\n ? alacarte.line.programName\n : alacarte.line?.kind === 'course'\n ? alacarte.line.courseName\n : null;\n\n return (\n <>\n {alacarteDebug}\n <Row className=\"checkout__container alacarte-confirmation__container bg-light-200\">\n <Col xs={12}>\n <AlacarteConfirmation\n order={alacarte.placedOrder}\n awaiting={false}\n error={alacarte.placedOrderError}\n onContinue={handleStartCourse}\n productDetail={alacarte.productDetail}\n productTitle={confirmationTitle}\n ownedCourses={\n alacarte.line?.kind === 'program'\n ? (alacarte.line.ownedCourses ?? null)\n : null\n }\n orderHistoryUrl={orderHistoryUrl ?? null}\n placedAt={alacarte.placedOrderPlacedAt}\n />\n </Col>\n </Row>\n </>\n );\n }\n\n if (alacarte.phase === 'loading') {\n return (\n <>\n {alacarteDebug}\n <ProcessingScreen />\n </>\n );\n }\n if (alacarte.phase === 'noActiveCheckout' && REDIRECT_ON_NO_ACTIVE_CHECKOUT) {\n // Redirects home via the effect above — show a spinner rather than a\n // notice while that happens.\n return (\n <>\n {alacarteDebug}\n <ProcessingScreen />\n </>\n );\n }\n if (alacarte.phase === 'noActiveCheckout') {\n return (\n <>\n {alacarteDebug}\n <AlacarteNotice messageId={alacarte.noticeMessageId!} />\n </>\n );\n }\n // Product unavailable / not found / not purchasable — banner only, no checkout form.\n if (alacarte.phase === 'notPurchasable' || alacarte.phase === 'error') {\n return (\n <>\n {alacarteDebug}\n <Row className=\"checkout__container bg-light-200\">\n <Col xs={12}>\n <Alert\n variant=\"danger\"\n icon={ErrorIcon}\n data-testid=\"alacarte-error-banner\"\n >\n {alacarte.error || 'Something went wrong with checkout.'}\n </Alert>\n </Col>\n </Row>\n </>\n );\n }\n\n const isAlreadyOwned = alacarte.isAlreadyOwned;\n const { paymentTimedOut } = alacarte;\n // Grey out and block the form + summary; only the alert above stays usable.\n const isLocked = isAlreadyOwned || paymentTimedOut;\n // Price differs from what the learner viewed before checkout (ALC-159).\n const showPriceChangedAlert = !!alacarte.priceChanged && !dismissedPriceChange && !isLocked;\n const priceChangedKind = isProgramProduct ? 'program' : 'course';\n\n return (\n <>\n {alacarteDebug}\n <Row className=\"checkout__container bg-light-200\">\n <CountryUnavailableModal\n isOpen={isBillingCountryBlocked}\n homeUrl={homeUrl}\n />\n {alacarte.sanctionsBlocked && (\n <OrderBlockedModal\n isOpen\n referenceCode={alacarte.sanctionsBlocked.referenceCode}\n homeUrl={homeUrl}\n />\n )}\n <Col xs={12} className=\"d-lg-none\">\n <h1 className=\"font-weight-bold text-primary-900\">Checkout</h1>\n {/* Below lg the payment column renders under the summary\n (flex-column-reverse), so the warning goes up here instead. */}\n {paymentTimedOut && <PaymentTimeoutAlert className=\"mb-3\" />}\n {showPriceChangedAlert && (\n <PriceChangedAlert\n kind={priceChangedKind}\n onDismiss={() => setDismissedPriceChange(true)}\n className=\"mb-3\"\n />\n )}\n </Col>\n\n <Col xs={12} className={isLocked ? 'checkout__locked-overlay' : ''}>\n <Row className=\"flex-column-reverse gap-5 flex-lg-row\">\n {/* ── LEFT ── */}\n <Col xs={12} lg={7} xxl={9} className=\"payment__options\">\n <div>\n <h1 className=\"font-weight-bold text-primary-900 d-none d-lg-block mb-4\">\n Checkout\n </h1>\n\n {paymentTimedOut && (\n <PaymentTimeoutAlert className=\"checkout__overlay-alert d-none d-lg-flex mb-3\" />\n )}\n\n {isAlreadyOwned && (\n <Alert\n variant=\"danger\"\n icon={ErrorIcon}\n className=\"checkout__overlay-alert mb-3\"\n data-testid=\"already-owned-alert\"\n >\n <p className=\"mb-3\">\n {formatMessage(\n alacarte.selector?.kind === 'program'\n ? messages.alreadyPaidProgram\n : messages.alreadyPaidCourse,\n )}\n </p>\n <div className=\"d-flex align-items-center justify-content-end gap-3 flex-wrap\">\n {orderHistoryUrl && (\n <a href={orderHistoryUrl} className=\"text-gray-900 font-weight-bold\">\n {formatMessage(messages.viewOrderHistory)}\n </a>\n )}\n <Button variant=\"brand\" className=\"rounded-pill\" onClick={handleStartCourse}>\n {formatMessage(messages.goToCourse)}\n </Button>\n </div>\n </Alert>\n )}\n\n {c.error && (\n <Alert\n variant=\"danger\"\n icon={ErrorIcon}\n dismissible\n onClose={c.clearError}\n >\n {c.error}\n </Alert>\n )}\n\n {alacarte.placeOrderError && (\n <Alert\n variant=\"danger\"\n icon={ErrorIcon}\n dismissible\n onClose={alacarte.clearPlaceOrderError}\n className=\"mb-3\"\n >\n {alacarte.placeOrderError}\n </Alert>\n )}\n\n {alacarte.paymentDecline?.message && !alacarte.placeOrderError && !paymentTimedOut && (\n <Alert\n variant=\"danger\"\n icon={ErrorIcon}\n className=\"mb-3\"\n data-testid=\"payment-decline-alert\"\n >\n {getLearnerFacingStripeMessage({\n message: alacarte.paymentDecline.message,\n code: alacarte.paymentDecline.code ?? undefined,\n })}\n </Alert>\n )}\n\n {alacarte.couponError && (\n <Alert\n variant=\"danger\"\n icon={ErrorIcon}\n dismissible\n onClose={alacarte.clearCouponError}\n className=\"mb-3\"\n data-testid=\"coupon-error-alert\"\n >\n {alacarte.couponError}\n </Alert>\n )}\n\n {showPriceChangedAlert && (\n <PriceChangedAlert\n kind={priceChangedKind}\n onDismiss={() => setDismissedPriceChange(true)}\n className=\"d-none d-lg-flex mb-3\"\n />\n )}\n\n {!alacarte.priceAccepted && !alacarte.priceChanged && isAlacarteReady && alacarte.line?.amountDue && (\n <Alert variant=\"info\" className=\"mb-3\" data-testid=\"price-accept-notice\">\n {formatMessage(messages.priceChangedNotice, {\n amount: alacarte.line.amountDue.amount.toFixed(2),\n currency: alacarte.line.amountDue.currency,\n })}\n </Alert>\n )}\n\n {showForm && (\n <>\n {showValidationBanner && (\n <Alert variant=\"danger\" icon={ErrorIcon} className=\"mb-3\">\n {formatMessage(messages.validationBanner)}\n </Alert>\n )}\n {c.phase === 'failed' && (\n <Alert variant=\"danger\" icon={ErrorIcon} className=\"mb-3\">\n {failedMessage\n || formatMessage(messages.paymentProcessingDescription)}\n </Alert>\n )}\n {appliedCouponCode && appliedDiscount && dismissedCouponAlert !== appliedCouponCode && (\n <Alert\n variant=\"success\"\n icon={CheckCircle}\n dismissible\n closeLabel={formatMessage(messages.dismiss)}\n onClose={() => setDismissedCouponAlert(appliedCouponCode)}\n className=\"coupon-applied-alert\"\n data-testid=\"coupon-applied-alert\"\n >\n <span aria-hidden=\"true\">🎉 </span>\n {formatMessage(messages.couponAppliedAlert)}\n </Alert>\n )}\n {alacarte.removedCouponCode && (() => {\n const removedCode = alacarte.removedCouponCode;\n const removedText = formatMessage(\n messages.couponRemovedAlert,\n { code: removedCode },\n );\n // Bold the interpolated code without baking markup into the\n // translation string — find it in the formatted sentence.\n const codeIndex = removedText.indexOf(removedCode);\n return (\n <Alert\n variant=\"success\"\n icon={CheckCircle}\n dismissible\n closeLabel={formatMessage(messages.dismiss)}\n onClose={alacarte.clearRemovedCouponCode}\n className=\"coupon-removed-alert\"\n data-testid=\"coupon-removed-alert\"\n >\n {codeIndex === -1 ? removedText : (\n <>\n {removedText.slice(0, codeIndex)}\n <strong>{removedCode}</strong>\n {removedText.slice(codeIndex + removedCode.length)}\n </>\n )}\n </Alert>\n );\n })()}\n <PaymentForm\n billing={c.billing}\n setField={c.setField}\n numberMountRef={c.numberMountRef}\n expiryMountRef={c.expiryMountRef}\n cvcMountRef={c.cvcMountRef}\n cardError={c.cardError}\n cardFieldStates={c.cardFieldStates}\n stripeReady={c.stripeReady}\n sessionReady={c.sessionReady}\n submitting={\n isAlacarteReady\n ? (alacarte.placingOrder || alacarte.awaitingPlacedOrder)\n : c.processingSubscription\n }\n onPlaceOrder={\n isAlacarteReady\n ? () => {\n alacarte.placeOrder({\n billing: {\n ...c.billing,\n // Country is required on tCheckoutPlaceOrder (two-letter ISO).\n // Prefer the form selection; fall back to gate geolocation.\n country: c.billing.country || c.userCountry || '',\n },\n confirmCardPayment: c.confirmCardPayment,\n });\n }\n : c.placeOrder\n }\n onValidationError={setShowValidationBanner}\n trialEnd={selectedCycle === 'monthly' ? displayEnd : undefined}\n priceToShow={null}\n cycleToShow={selectedCycle === 'monthly' ? 'monthly' : 'annual'}\n userCountry={c.userCountry}\n geolocationUrl={props.geolocationUrl}\n alacarteLine={alacarte.line}\n stripe={c.stripe}\n expressCountry={c.billing.country || c.userCountry || 'US'}\n onExpressPayment={isAlacarteReady ? handleExpressPayment : undefined}\n paypalClientId={paypalClientId}\n onPaypalCreateOrder={isAlacarteReady ? handlePaypalCreateOrder : undefined}\n onPaypalApprove={isAlacarteReady ? alacarte.approvePaypalOrder : undefined}\n onPaypalCancel={isAlacarteReady ? alacarte.cancelPaypalOrder : undefined}\n />\n </>\n )}\n\n {c.phase === 'success' && (\n <SuccessScreen\n subscriptionBiId={c.subscriptionDetails?.biId || ''}\n cardLast4={c.subscriptionDetails?.cardLast4 || ''}\n purchaseDate={displayStart}\n courseLabel={courseLabel}\n onFindCourse={handleStartCourse}\n />\n )}\n\n {c.phase === 'blocked' && (\n <BlockedScreen detail={c.lastComment} />\n )}\n </div>\n </Col>\n\n {/* ── RIGHT — swaps to EnrollmentSummary on success ── */}\n <Col xs={12} lg={5} xxl={3} className=\"payment__summary\">\n {c.phase === 'success' ? (\n <EnrollmentSummary\n course={c.course}\n onStartCourse={handleStartCourse}\n />\n ) : (\n <CartSummary\n defaultCycle={selectedCycle}\n onCycleChange={c.processingSubscription ? undefined : c.setCycle}\n course={courseForSummary}\n alacarteLine={alacarte.line}\n programDetail={alacarteProgramDetail}\n programName={alacarte.ownedProductName}\n promoCode={isAlacarteReady ? {\n value: promoCodeValue,\n onChange: (next) => {\n setPromoCodeValue(next);\n if (alacarte.couponError) alacarte.clearCouponError();\n },\n onApply: () => alacarte.applyCoupon(promoCodeValue),\n onRemove: () => {\n alacarte.removeCoupon();\n setPromoCodeValue('');\n setAdvertisedOffer(null);\n },\n appliedCode: appliedCouponCode,\n discount: appliedDiscount,\n offer: !appliedCouponCode ? advertisedOffer : null,\n error: alacarte.couponError,\n isApplying: alacarte.couponApplying,\n disabled: alacarte.placingOrder,\n } : null}\n />\n )}\n </Col>\n </Row>\n </Col>\n </Row>\n </>\n );\n};\n\nexport default Checkout;\n"]}
|
|
@@ -15,11 +15,14 @@ export interface ExpressCheckoutProps {
|
|
|
15
15
|
* Must resolve on success or reject on failure.
|
|
16
16
|
*/
|
|
17
17
|
onPaymentAuthorized: (paymentMethodId: string, walletCountry?: string) => Promise<void>;
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
/** PayPal JS SDK client id — PayPal stays disabled without it. */
|
|
19
|
+
paypalClientId?: string | null;
|
|
20
|
+
/** PayPal `createOrder`: places the order with PayPal and resolves its id. */
|
|
21
|
+
onPaypalCreateOrder?: () => Promise<string>;
|
|
22
|
+
/** PayPal `onApprove`: captures the approved PayPal order. */
|
|
23
|
+
onPaypalApprove?: (paypalOrderId: string) => Promise<void>;
|
|
24
|
+
/** PayPal `onCancel` / `onError`: abandons the unapproved PayPal order. */
|
|
25
|
+
onPaypalCancel?: (paypalOrderId: string) => Promise<void>;
|
|
23
26
|
disabled?: boolean;
|
|
24
27
|
}
|
|
25
28
|
/**
|
|
@@ -11,6 +11,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
11
11
|
import { useEffect, useRef, useState } from 'react';
|
|
12
12
|
import { useIntl } from '@openedx/frontend-base';
|
|
13
13
|
import { PayPalWordmark } from '../BrandMarks/BrandMarks';
|
|
14
|
+
import { loadPaypal } from '../../utils/paypal';
|
|
14
15
|
import messages from './Messages';
|
|
15
16
|
/**
|
|
16
17
|
* Express checkout: PayPal (local) | Apple Pay | Google Pay.
|
|
@@ -20,7 +21,7 @@ import messages from './Messages';
|
|
|
20
21
|
* stacks / overflows in this narrow column. `always` keeps the Shopify-like
|
|
21
22
|
* show-even-without-a-saved-card behaviour.
|
|
22
23
|
*/
|
|
23
|
-
const ExpressCheckout = ({ stripe, totalAmountCents, currency, onPaymentAuthorized,
|
|
24
|
+
const ExpressCheckout = ({ stripe, totalAmountCents, currency, onPaymentAuthorized, paypalClientId, onPaypalCreateOrder, onPaypalApprove, onPaypalCancel, disabled, }) => {
|
|
24
25
|
const { formatMessage } = useIntl();
|
|
25
26
|
const appleMountRef = useRef(null);
|
|
26
27
|
const googleMountRef = useRef(null);
|
|
@@ -29,12 +30,18 @@ const ExpressCheckout = ({ stripe, totalAmountCents, currency, onPaymentAuthoriz
|
|
|
29
30
|
const appleElementRef = useRef(null);
|
|
30
31
|
const googleElementRef = useRef(null);
|
|
31
32
|
const onPaymentAuthorizedRef = useRef(onPaymentAuthorized);
|
|
33
|
+
const paypalMountRef = useRef(null);
|
|
34
|
+
const paypalHandlersRef = useRef({ onPaypalCreateOrder, onPaypalApprove, onPaypalCancel });
|
|
35
|
+
// PayPal order created but not yet approved — cancelled if the buttons error out.
|
|
36
|
+
const openPaypalOrderRef = useRef(null);
|
|
32
37
|
const [appleReady, setAppleReady] = useState(false);
|
|
33
38
|
const [googleReady, setGoogleReady] = useState(false);
|
|
34
39
|
const [appleVisible, setAppleVisible] = useState(false);
|
|
35
40
|
const [googleVisible, setGoogleVisible] = useState(false);
|
|
36
41
|
const [walletError, setWalletError] = useState(null);
|
|
42
|
+
const [paypalRendered, setPaypalRendered] = useState(false);
|
|
37
43
|
const hasAmount = !!totalAmountCents && !!currency;
|
|
44
|
+
const paypalEnabled = !!paypalClientId && hasAmount && !!onPaypalCreateOrder && !!onPaypalApprove;
|
|
38
45
|
// Keep slots in the grid until ready so Stripe measures a full column width.
|
|
39
46
|
const showAppleSlot = !appleReady || appleVisible;
|
|
40
47
|
const showGoogleSlot = !googleReady || googleVisible;
|
|
@@ -42,6 +49,80 @@ const ExpressCheckout = ({ stripe, totalAmountCents, currency, onPaymentAuthoriz
|
|
|
42
49
|
useEffect(() => {
|
|
43
50
|
onPaymentAuthorizedRef.current = onPaymentAuthorized;
|
|
44
51
|
}, [onPaymentAuthorized]);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
paypalHandlersRef.current = { onPaypalCreateOrder, onPaypalApprove, onPaypalCancel };
|
|
54
|
+
}, [onPaypalCreateOrder, onPaypalApprove, onPaypalCancel]);
|
|
55
|
+
// PayPal buttons: tCheckoutPlaceOrder(PAYPAL) on click, capture on approve,
|
|
56
|
+
// cancel when the learner closes the PayPal window.
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
const mountNode = paypalMountRef.current;
|
|
59
|
+
if (!paypalEnabled || !paypalClientId || !currency || !mountNode) {
|
|
60
|
+
setPaypalRendered(false);
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
let cancelled = false;
|
|
64
|
+
const cancelOpenOrder = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
const orderId = openPaypalOrderRef.current;
|
|
67
|
+
openPaypalOrderRef.current = null;
|
|
68
|
+
if (orderId)
|
|
69
|
+
yield ((_b = (_a = paypalHandlersRef.current).onPaypalCancel) === null || _b === void 0 ? void 0 : _b.call(_a, orderId));
|
|
70
|
+
});
|
|
71
|
+
loadPaypal(paypalClientId, currency)
|
|
72
|
+
.then((paypal) => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
+
if (cancelled)
|
|
74
|
+
return;
|
|
75
|
+
const buttons = paypal.Buttons({
|
|
76
|
+
fundingSource: paypal.FUNDING.PAYPAL,
|
|
77
|
+
style: {
|
|
78
|
+
layout: 'horizontal', color: 'gold', shape: 'rect', label: 'paypal', height: 48, tagline: false,
|
|
79
|
+
},
|
|
80
|
+
createOrder: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
+
setWalletError(null);
|
|
82
|
+
const orderId = yield paypalHandlersRef.current.onPaypalCreateOrder();
|
|
83
|
+
openPaypalOrderRef.current = orderId;
|
|
84
|
+
return orderId;
|
|
85
|
+
}),
|
|
86
|
+
onApprove: (_a) => __awaiter(void 0, [_a], void 0, function* ({ orderID }) {
|
|
87
|
+
openPaypalOrderRef.current = null;
|
|
88
|
+
try {
|
|
89
|
+
yield paypalHandlersRef.current.onPaypalApprove(orderID);
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
// The checkout page already shows the capture error.
|
|
93
|
+
console.warn('[ExpressCheckout] PayPal capture failed', err);
|
|
94
|
+
}
|
|
95
|
+
}),
|
|
96
|
+
onCancel: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
+
yield cancelOpenOrder();
|
|
98
|
+
}),
|
|
99
|
+
onError: (err) => {
|
|
100
|
+
console.warn('[ExpressCheckout] PayPal error', err);
|
|
101
|
+
// createOrder failures are already shown by the checkout page.
|
|
102
|
+
if (openPaypalOrderRef.current) {
|
|
103
|
+
setWalletError(formatMessage(messages.paypalError));
|
|
104
|
+
cancelOpenOrder().catch(() => { });
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
if (!buttons.isEligible())
|
|
109
|
+
return;
|
|
110
|
+
yield buttons.render(mountNode);
|
|
111
|
+
if (!cancelled)
|
|
112
|
+
setPaypalRendered(true);
|
|
113
|
+
}))
|
|
114
|
+
.catch((err) => {
|
|
115
|
+
console.warn('[ExpressCheckout] PayPal SDK unavailable', err);
|
|
116
|
+
if (!cancelled)
|
|
117
|
+
setPaypalRendered(false);
|
|
118
|
+
});
|
|
119
|
+
return () => {
|
|
120
|
+
cancelled = true;
|
|
121
|
+
mountNode.innerHTML = '';
|
|
122
|
+
setPaypalRendered(false);
|
|
123
|
+
};
|
|
124
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
125
|
+
}, [paypalEnabled, paypalClientId, currency]);
|
|
45
126
|
useEffect(() => {
|
|
46
127
|
if (!stripe
|
|
47
128
|
|| !totalAmountCents
|
|
@@ -221,11 +302,7 @@ const ExpressCheckout = ({ stripe, totalAmountCents, currency, onPaymentAuthoriz
|
|
|
221
302
|
return 'express-checkout__wallet express-checkout__wallet--unavailable';
|
|
222
303
|
return 'express-checkout__wallet';
|
|
223
304
|
};
|
|
224
|
-
return (_jsxs("div", { className: `express-checkout${disabled ? ' express-checkout--disabled' : ''}`, children: [_jsx("h3", { className: "express-checkout__heading", children: formatMessage(messages.heading) }), _jsxs("div", { className: "express-checkout__buttons", style: { gridTemplateColumns: `repeat(${columnCount}, minmax(0, 1fr))` }, children: [_jsx("button", { type: "button", disabled:
|
|
225
|
-
// PayPal collects buyer details on its own page.
|
|
226
|
-
console.log('paypal clicked');
|
|
227
|
-
onPayPalClick === null || onPayPalClick === void 0 ? void 0 : onPayPalClick();
|
|
228
|
-
}, children: _jsx(PayPalWordmark, {}) }), _jsx("div", { ref: appleMountRef, className: walletClassName(appleReady, appleVisible), "aria-hidden": appleReady && !appleVisible, "aria-label": formatMessage(messages.applePay) }), _jsx("div", { ref: googleMountRef, className: walletClassName(googleReady, googleVisible), "aria-hidden": googleReady && !googleVisible, "aria-label": formatMessage(messages.googlePay) })] }), walletError && (_jsx("p", { className: "express-checkout__error", role: "alert", children: walletError }))] }));
|
|
305
|
+
return (_jsxs("div", { className: `express-checkout${disabled ? ' express-checkout--disabled' : ''}`, children: [_jsx("h3", { className: "express-checkout__heading", children: formatMessage(messages.heading) }), _jsxs("div", { className: "express-checkout__buttons", style: { gridTemplateColumns: `repeat(${columnCount}, minmax(0, 1fr))` }, children: [_jsxs("div", { className: "express-checkout__paypal", children: [_jsx("div", { ref: paypalMountRef, className: paypalRendered ? undefined : 'express-checkout__paypal-mount--pending', "aria-label": formatMessage(messages.paypal) }), !paypalRendered && (_jsx("button", { type: "button", disabled: true, "aria-label": formatMessage(messages.paypal), className: "express-checkout__button express-checkout__button--paypal", children: _jsx(PayPalWordmark, {}) }))] }), _jsx("div", { ref: appleMountRef, className: walletClassName(appleReady, appleVisible), "aria-hidden": appleReady && !appleVisible, "aria-label": formatMessage(messages.applePay) }), _jsx("div", { ref: googleMountRef, className: walletClassName(googleReady, googleVisible), "aria-hidden": googleReady && !googleVisible, "aria-label": formatMessage(messages.googlePay) })] }), walletError && (_jsx("p", { className: "express-checkout__error", role: "alert", children: walletError }))] }));
|
|
229
306
|
};
|
|
230
307
|
export default ExpressCheckout;
|
|
231
308
|
//# sourceMappingURL=ExpressCheckout.js.map
|
|
@@ -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;AAQjD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,QAAQ,MAAM,YAAY,CAAC;AA2BlC;;;;;;;GAOG;AACH,MAAM,eAAe,GAAmC,CAAC,EACvD,MAAM,EACN,gBAAgB,EAChB,QAAQ,EACR,mBAAmB,EACnB,aAAa,EACb,QAAQ,GACT,EAAE,EAAE;IACH,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,EAAE,CAAC;IACpC,MAAM,aAAa,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAC;IAC1D,MAAM,cAAc,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAC;IAC3D,MAAM,gBAAgB,GAAG,MAAM,CAA4B,IAAI,CAAC,CAAC;IACjE,MAAM,iBAAiB,GAAG,MAAM,CAA4B,IAAI,CAAC,CAAC;IAClE,MAAM,eAAe,GAAG,MAAM,CAA2B,IAAI,CAAC,CAAC;IAC/D,MAAM,gBAAgB,GAAG,MAAM,CA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,CAAC,QAAQ,CAAC,MAAM,CAAC,EAC1C,SAAS,EAAC,2DAA2D,EACrE,OAAO,EAAE,GAAG,EAAE;4BACZ,iDAAiD;4BACjD,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;4BAC9B,aAAa,aAAb,aAAa,uBAAb,aAAa,EAAI,CAAC;wBACpB,CAAC,YAED,KAAC,cAAc,KAAG,GACX,EAGT,cACE,GAAG,EAAE,aAAa,EAClB,SAAS,EAAE,eAAe,CAAC,UAAU,EAAE,YAAY,CAAC,iBACvC,UAAU,IAAI,CAAC,YAAY,gBAC5B,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAC5C,EACF,cACE,GAAG,EAAE,cAAc,EACnB,SAAS,EAAE,eAAe,CAAC,WAAW,EAAE,aAAa,CAAC,iBACzC,WAAW,IAAI,CAAC,aAAa,gBAC9B,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC,GAC7C,IACE,EACL,WAAW,IAAI,CACd,YAAG,SAAS,EAAC,yBAAyB,EAAC,IAAI,EAAC,OAAO,YAChD,WAAW,GACV,CACL,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 type {\n ExpressCheckoutConfirmEvent,\n ExpressCheckoutReadyEvent,\n StripeElementsLike,\n StripeElementLike,\n StripeLike,\n} from '../../types';\nimport { PayPalWordmark } from '../BrandMarks/BrandMarks';\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 /**\n * PayPal does not use the card billing form. Called directly — country,\n * postal code, and state are not checked.\n */\n onPayPalClick?: () => void,\n disabled?: boolean,\n}\n\ntype WalletSlot = 'apple' | 'google';\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 onPayPalClick,\n disabled,\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\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\n const hasAmount = !!totalAmountCents && !!currency;\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\n useEffect(() => {\n onPaymentAuthorizedRef.current = onPaymentAuthorized;\n }, [onPaymentAuthorized]);\n\n useEffect(() => {\n if (\n !stripe\n || !totalAmountCents\n || !currency\n || !appleMountRef.current\n || !googleMountRef.current\n ) {\n console.log('[ExpressCheckout] skip mount', {\n hasStripe: !!stripe,\n totalAmountCents,\n currency,\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 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})`, {\n applePay: !!methods?.applePay,\n googlePay: !!methods?.googlePay,\n raw: methods ?? null,\n });\n setVisible(visible);\n setReady(true);\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 // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [stripe, currency, hasAmount]);\n\n useEffect(() => {\n if (!totalAmountCents || !currency) return;\n const update = { amount: totalAmountCents, currency: currency.toLowerCase() };\n try {\n appleElementsRef.current?.update?.(update);\n googleElementsRef.current?.update?.(update);\n } catch {\n // Safe to ignore mid-sheet updates.\n }\n }, [totalAmountCents, currency]);\n\n const walletClassName = (ready: boolean, visible: boolean) => {\n if (!ready) return 'express-checkout__wallet express-checkout__wallet--pending';\n if (!visible) return 'express-checkout__wallet express-checkout__wallet--unavailable';\n return 'express-checkout__wallet';\n };\n\n return (\n <div className={`express-checkout${disabled ? ' express-checkout--disabled' : ''}`}>\n <h3 className=\"express-checkout__heading\">\n {formatMessage(messages.heading)}\n </h3>\n <div\n className=\"express-checkout__buttons\"\n style={{ gridTemplateColumns: `repeat(${columnCount}, minmax(0, 1fr))` }}\n >\n <button\n type=\"button\"\n disabled={disabled || !onPayPalClick}\n aria-label={formatMessage(messages.paypal)}\n className=\"express-checkout__button express-checkout__button--paypal\"\n onClick={() => {\n // PayPal collects buyer details on its own page.\n console.log('paypal clicked');\n onPayPalClick?.();\n }}\n >\n <PayPalWordmark />\n </button>\n\n {/* Always in the DOM so remounts can find the nodes; CSS hides unavailable. */}\n <div\n ref={appleMountRef}\n className={walletClassName(appleReady, appleVisible)}\n aria-hidden={appleReady && !appleVisible}\n aria-label={formatMessage(messages.applePay)}\n />\n <div\n ref={googleMountRef}\n className={walletClassName(googleReady, googleVisible)}\n aria-hidden={googleReady && !googleVisible}\n aria-label={formatMessage(messages.googlePay)}\n />\n </div>\n {walletError && (\n <p className=\"express-checkout__error\" role=\"alert\">\n {walletError}\n </p>\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;AAQjD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,QAAQ,MAAM,YAAY,CAAC;AA8BlC;;;;;;;GAOG;AACH,MAAM,eAAe,GAAmC,CAAC,EACvD,MAAM,EACN,gBAAgB,EAChB,QAAQ,EACR,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,QAAQ,GACT,EAAE,EAAE;IACH,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,EAAE,CAAC;IACpC,MAAM,aAAa,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAC;IAC1D,MAAM,cAAc,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAC;IAC3D,MAAM,gBAAgB,GAAG,MAAM,CAA4B,IAAI,CAAC,CAAC;IACjE,MAAM,iBAAiB,GAAG,MAAM,CAA4B,IAAI,CAAC,CAAC;IAClE,MAAM,eAAe,GAAG,MAAM,CAA2B,IAAI,CAAC,CAAC;IAC/D,MAAM,gBAAgB,GAAG,MAAM,CAA2B,IAAI,CAAC,CAAC;IAChE,MAAM,sBAAsB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAC3D,MAAM,cAAc,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAC;IAC3D,MAAM,iBAAiB,GAAG,MAAM,CAAC,EAAE,mBAAmB,EAA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AC,IAAI,EAAC,OAAO,YAChD,WAAW,GACV,CACL,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 type {\n ExpressCheckoutConfirmEvent,\n ExpressCheckoutReadyEvent,\n StripeElementsLike,\n StripeElementLike,\n StripeLike,\n} from '../../types';\nimport { PayPalWordmark } from '../BrandMarks/BrandMarks';\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 /** 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 disabled?: boolean,\n}\n\ntype WalletSlot = 'apple' | 'google';\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 paypalClientId,\n onPaypalCreateOrder,\n onPaypalApprove,\n onPaypalCancel,\n disabled,\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 paypalMountRef = useRef<HTMLDivElement | null>(null);\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\n const hasAmount = !!totalAmountCents && !!currency;\n const paypalEnabled = !!paypalClientId && hasAmount && !!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\n useEffect(() => {\n onPaymentAuthorizedRef.current = onPaymentAuthorized;\n }, [onPaymentAuthorized]);\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 setPaypalRendered(false);\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', color: 'gold', shape: 'rect', label: 'paypal', height: 48, 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()) return;\n await buttons.render(mountNode);\n if (!cancelled) setPaypalRendered(true);\n })\n .catch((err) => {\n console.warn('[ExpressCheckout] PayPal SDK unavailable', err);\n if (!cancelled) setPaypalRendered(false);\n });\n\n return () => {\n cancelled = true;\n mountNode.innerHTML = '';\n setPaypalRendered(false);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [paypalEnabled, paypalClientId, currency]);\n\n useEffect(() => {\n if (\n !stripe\n || !totalAmountCents\n || !currency\n || !appleMountRef.current\n || !googleMountRef.current\n ) {\n console.log('[ExpressCheckout] skip mount', {\n hasStripe: !!stripe,\n totalAmountCents,\n currency,\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 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})`, {\n applePay: !!methods?.applePay,\n googlePay: !!methods?.googlePay,\n raw: methods ?? null,\n });\n setVisible(visible);\n setReady(true);\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 // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [stripe, currency, hasAmount]);\n\n useEffect(() => {\n if (!totalAmountCents || !currency) return;\n const update = { amount: totalAmountCents, currency: currency.toLowerCase() };\n try {\n appleElementsRef.current?.update?.(update);\n googleElementsRef.current?.update?.(update);\n } catch {\n // Safe to ignore mid-sheet updates.\n }\n }, [totalAmountCents, currency]);\n\n const walletClassName = (ready: boolean, visible: boolean) => {\n if (!ready) return 'express-checkout__wallet express-checkout__wallet--pending';\n if (!visible) return 'express-checkout__wallet express-checkout__wallet--unavailable';\n return 'express-checkout__wallet';\n };\n\n return (\n <div className={`express-checkout${disabled ? ' express-checkout--disabled' : ''}`}>\n <h3 className=\"express-checkout__heading\">\n {formatMessage(messages.heading)}\n </h3>\n <div\n className=\"express-checkout__buttons\"\n style={{ gridTemplateColumns: `repeat(${columnCount}, minmax(0, 1fr))` }}\n >\n <div className=\"express-checkout__paypal\">\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 aria-label={formatMessage(messages.paypal)}\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 <div\n ref={appleMountRef}\n className={walletClassName(appleReady, appleVisible)}\n aria-hidden={appleReady && !appleVisible}\n aria-label={formatMessage(messages.applePay)}\n />\n <div\n ref={googleMountRef}\n className={walletClassName(googleReady, googleVisible)}\n aria-hidden={googleReady && !googleVisible}\n aria-label={formatMessage(messages.googlePay)}\n />\n </div>\n {walletError && (\n <p className=\"express-checkout__error\" role=\"alert\">\n {walletError}\n </p>\n )}\n </div>\n );\n};\n\nexport default ExpressCheckout;\n"]}
|