@edx/frontend-app-alacarte-checkout 1.14.0 → 1.16.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/README.rst +144 -0
- package/dist/components/Checkout/Checkout.js +5 -1
- package/dist/components/Checkout/Checkout.js.map +1 -1
- package/dist/components/ExpressCheckout/ExpressCheckout.d.ts +9 -1
- package/dist/components/ExpressCheckout/ExpressCheckout.js +177 -49
- 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.js +4 -1
- package/dist/components/PaymentForm/PaymentForm.js.map +1 -1
- package/dist/constants.d.ts +14 -1
- package/dist/constants.js +9 -4
- package/dist/constants.js.map +1 -1
- package/dist/data/hooks/useCheckout.js +2 -2
- package/dist/data/hooks/useCheckout.js.map +1 -1
- package/dist/routes.js +21 -2
- package/dist/routes.js.map +1 -1
- package/dist/styles/components/expressCheckout.scss +43 -17
- package/dist/types.d.ts +56 -9
- package/dist/types.js.map +1 -1
- package/dist/utils/DevBypassAuthService.d.ts +42 -0
- package/dist/utils/DevBypassAuthService.js +82 -0
- package/dist/utils/DevBypassAuthService.js.map +1 -0
- package/dist/utils/cartApi.js +12 -9
- package/dist/utils/cartApi.js.map +1 -1
- package/dist/utils/provision.js +2 -2
- package/dist/utils/provision.js.map +1 -1
- package/dist/utils/queries.d.ts +1 -1
- package/dist/utils/queries.js +2 -2
- package/dist/utils/queries.js.map +1 -1
- package/package.json +4 -1
package/README.rst
CHANGED
|
@@ -92,6 +92,150 @@ Bind mounts are used instead of symlinks because Node resolves symlinks to
|
|
|
92
92
|
their real paths, which breaks hoisted dependency resolution. When you are
|
|
93
93
|
done, unmount with ``sudo umount packages/frontend-base``.
|
|
94
94
|
|
|
95
|
+
Testing Apple Pay and Google Pay
|
|
96
|
+
================================
|
|
97
|
+
|
|
98
|
+
Wallets require a **trusted HTTPS** origin. Plain ``http://localhost`` will
|
|
99
|
+
not show Apple Pay / Google Pay. For local work use mkcert HTTPS, then an
|
|
100
|
+
ngrok tunnel when you need Apple Pay domain verification.
|
|
101
|
+
|
|
102
|
+
What you need
|
|
103
|
+
-------------
|
|
104
|
+
|
|
105
|
+
- macOS with `mkcert`_ (``brew install mkcert nss``)
|
|
106
|
+
- `ngrok`_ (recent agent; run ``ngrok update`` if auth fails with ERR_NGROK_121)
|
|
107
|
+
- Stripe **test** publishable key in ``site.config.dev.https.tsx``
|
|
108
|
+
- A card in Apple Wallet (Safari / Apple Pay) and/or Google Pay (Chrome)
|
|
109
|
+
- Optional: a product URL such as
|
|
110
|
+
``/aca-checkout?program_uid=<uid>``
|
|
111
|
+
|
|
112
|
+
.. _mkcert: https://github.com/FiloSottile/mkcert
|
|
113
|
+
.. _ngrok: https://ngrok.com/download
|
|
114
|
+
|
|
115
|
+
1. Generate and trust local certificates
|
|
116
|
+
----------------------------------------
|
|
117
|
+
|
|
118
|
+
.. code-block:: sh
|
|
119
|
+
|
|
120
|
+
# One-time: install the mkcert CA into the system trust store
|
|
121
|
+
mkcert -install
|
|
122
|
+
|
|
123
|
+
# Per repo: write certs into .certs/ (gitignored)
|
|
124
|
+
npm run certs:generate
|
|
125
|
+
|
|
126
|
+
This creates:
|
|
127
|
+
|
|
128
|
+
- ``.certs/localhost+2.pem``
|
|
129
|
+
- ``.certs/localhost+2-key.pem``
|
|
130
|
+
|
|
131
|
+
covering ``localhost``, ``127.0.0.1``, and ``::1``. The browser must show a
|
|
132
|
+
normal lock on ``https://localhost:1996`` (not “Not Secure”). If it still
|
|
133
|
+
warns, re-run ``mkcert -install``, regenerate certs, fully quit the browser,
|
|
134
|
+
and reopen.
|
|
135
|
+
|
|
136
|
+
Do **not** open the LAN IP from the webpack banner
|
|
137
|
+
(``https://192.168.x.x:1996``) — that host is not on the certificate.
|
|
138
|
+
|
|
139
|
+
2. Start the HTTPS dev server
|
|
140
|
+
-----------------------------
|
|
141
|
+
|
|
142
|
+
.. code-block:: sh
|
|
143
|
+
|
|
144
|
+
npm run dev:https
|
|
145
|
+
|
|
146
|
+
This uses ``site.config.dev.https.tsx``, which:
|
|
147
|
+
|
|
148
|
+
- Serves over HTTPS with the mkcert files above
|
|
149
|
+
- Sets ``DEV_MOCK_SESSION`` so Viax tokens work without the LMS session
|
|
150
|
+
endpoint (CORS breaks on ``https://localhost`` / ngrok)
|
|
151
|
+
- Uses ``DevBypassAuthService`` so the shell does not call
|
|
152
|
+
``http://localhost:18000/login_refresh`` (which would hang or redirect
|
|
153
|
+
when Django is down or the origin is ngrok)
|
|
154
|
+
|
|
155
|
+
App URL (example)::
|
|
156
|
+
|
|
157
|
+
https://localhost:1996/aca-checkout?program_uid=<uid>
|
|
158
|
+
|
|
159
|
+
Google Pay can often be exercised on this URL in **Chrome**. Apple Pay on
|
|
160
|
+
``localhost`` is usually blocked until the domain is registered with Stripe;
|
|
161
|
+
use the tunnel steps below for Apple Pay.
|
|
162
|
+
|
|
163
|
+
3. Tunnel with ngrok (required for Apple Pay)
|
|
164
|
+
---------------------------------------------
|
|
165
|
+
|
|
166
|
+
``localhost`` cannot be registered as an Apple Pay domain in Stripe. Expose
|
|
167
|
+
the HTTPS app with ngrok (keep ``npm run dev:https`` running):
|
|
168
|
+
|
|
169
|
+
.. code-block:: sh
|
|
170
|
+
|
|
171
|
+
npm run dev:tunnel
|
|
172
|
+
# equivalent: ngrok http https://localhost:1996
|
|
173
|
+
|
|
174
|
+
Copy the **https** forwarding host only, e.g.
|
|
175
|
+
``abc123.ngrok-free.app`` (no ``https://``, no path, no port).
|
|
176
|
+
|
|
177
|
+
If you see ``ERR_NGROK_3004``, the tunnel is hitting HTTP while the app
|
|
178
|
+
speaks HTTPS — use ``ngrok http https://localhost:1996`` (already wired in
|
|
179
|
+
``dev:tunnel``).
|
|
180
|
+
|
|
181
|
+
Free ngrok URLs change every restart; you must re-register each new host in
|
|
182
|
+
Stripe (or use a reserved ngrok domain).
|
|
183
|
+
|
|
184
|
+
4. Register the domain in Stripe
|
|
185
|
+
--------------------------------
|
|
186
|
+
|
|
187
|
+
1. Open Stripe Dashboard → **Test mode** →
|
|
188
|
+
`Payment method domains`_
|
|
189
|
+
2. **Add a new domain** → paste the ngrok host
|
|
190
|
+
(``abc123.ngrok-free.app``)
|
|
191
|
+
3. Save
|
|
192
|
+
|
|
193
|
+
.. _Payment method domains: https://dashboard.stripe.com/test/settings/payment_method_domains
|
|
194
|
+
|
|
195
|
+
Then open checkout on the **ngrok** origin, not localhost::
|
|
196
|
+
|
|
197
|
+
https://abc123.ngrok-free.app/aca-checkout?program_uid=<uid>
|
|
198
|
+
|
|
199
|
+
5. Which browser for which wallet
|
|
200
|
+
---------------------------------
|
|
201
|
+
|
|
202
|
+
+------------------+----------------------------------------------------------+
|
|
203
|
+
| Wallet | Where to test |
|
|
204
|
+
+==================+==========================================================+
|
|
205
|
+
| Google Pay | Chrome (signed into a Google account). Can work on |
|
|
206
|
+
| | ``https://localhost`` once the cert is trusted. |
|
|
207
|
+
+------------------+----------------------------------------------------------+
|
|
208
|
+
| Apple Pay | Safari (Mac/iPhone) with a card in Wallet. Use the |
|
|
209
|
+
| | **registered ngrok** HTTPS URL. Chrome on macOS can |
|
|
210
|
+
| | also show Apple Pay when the domain is registered and |
|
|
211
|
+
| | ``applePay: 'always'`` is set (this app does). |
|
|
212
|
+
+------------------+----------------------------------------------------------+
|
|
213
|
+
| PayPal button | Always rendered (placeholder / disabled in express UI). |
|
|
214
|
+
+------------------+----------------------------------------------------------+
|
|
215
|
+
|
|
216
|
+
Express checkout mounts Apple Pay and Google Pay as separate Stripe Express
|
|
217
|
+
Checkout Elements in one row (PayPal | Apple Pay | Google Pay). Console
|
|
218
|
+
logs::
|
|
219
|
+
|
|
220
|
+
[ExpressCheckout] ready (apple) { applePay: true/false, … }
|
|
221
|
+
[ExpressCheckout] ready (google) { googlePay: true/false, … }
|
|
222
|
+
|
|
223
|
+
6. Checklist when buttons are missing
|
|
224
|
+
-------------------------------------
|
|
225
|
+
|
|
226
|
+
1. Padlock is clean (trusted HTTPS), URL is ``localhost`` or your ngrok host
|
|
227
|
+
— not a LAN IP.
|
|
228
|
+
2. ``npm run dev:https`` is running (not plain ``npm run dev``).
|
|
229
|
+
3. For Apple Pay: ngrok host is registered in Stripe **test** Payment method
|
|
230
|
+
domains and matches the URL bar exactly.
|
|
231
|
+
4. Browser matches the wallet (Safari ≈ Apple Pay, Chrome ≈ Google Pay).
|
|
232
|
+
5. ``DEV_MOCK_SESSION_RESPONSE`` tokens in ``site.config.dev.https.tsx`` are
|
|
233
|
+
not expired (refresh from a real session when Viax calls start failing).
|
|
234
|
+
6. You are not redirected to ``http://localhost:18000/dashboard`` — that means
|
|
235
|
+
LMS cookie auth ran; ``dev:https`` should use ``DevBypassAuthService``.
|
|
236
|
+
7. Hard-refresh after cert or config changes; fully quit Chrome if it cached
|
|
237
|
+
an old certificate warning.
|
|
238
|
+
|
|
95
239
|
Making Your New Project's README File
|
|
96
240
|
=====================================
|
|
97
241
|
|
|
@@ -99,8 +99,12 @@ const Checkout = (_a) => {
|
|
|
99
99
|
if (!c.stripe)
|
|
100
100
|
throw new Error('Stripe not loaded');
|
|
101
101
|
const stripeInstance = c.stripe;
|
|
102
|
+
const country = (c.billing.country || walletCountry || c.userCountry || '').trim().toUpperCase();
|
|
103
|
+
if (!country) {
|
|
104
|
+
throw new Error('Please select a country before using Apple Pay or Google Pay.');
|
|
105
|
+
}
|
|
102
106
|
yield alacarte.placeOrderAsync({
|
|
103
|
-
billing: Object.assign(Object.assign({}, c.billing), { country
|
|
107
|
+
billing: Object.assign(Object.assign({}, c.billing), { country }),
|
|
104
108
|
confirmCardPayment: (clientSecret) => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
109
|
yield confirmPaymentWithMethodId({
|
|
106
110
|
stripe: stripeInstance,
|
|
@@ -1 +1 @@
|
|
|
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C,WAAW,IACV,YAAY,EAAE,aAAa,EAC3B,aAAa,EAAE,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAChE,MAAM,EAAE,gBAAgB,EACxB,YAAY,EAAE,QAAQ,CAAC,IAAI,EAC3B,aAAa,EAAE,qBAAqB,EACpC,WAAW,EAAE,QAAQ,CAAC,gBAAgB,EACtC,SAAS,EAAE,eAAe,CAAC,CAAC,CAAC;4CAC3B,KAAK,EAAE,cAAc;4CACrB,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE;gDACjB,iBAAiB,CAAC,IAAI,CAAC,CAAC;gDACxB,IAAI,QAAQ,CAAC,WAAW;oDAAE,QAAQ,CAAC,gBAAgB,EAAE,CAAC;4CACxD,CAAC;4CACD,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,cAAc,CAAC;4CACnD,QAAQ,EAAE,GAAG,EAAE;gDACb,QAAQ,CAAC,YAAY,EAAE,CAAC;gDACxB,iBAAiB,CAAC,EAAE,CAAC,CAAC;gDACtB,kBAAkB,CAAC,IAAI,CAAC,CAAC;4CAC3B,CAAC;4CACD,WAAW,EAAE,iBAAiB;4CAC9B,QAAQ,EAAE,eAAe;4CACzB,KAAK,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC,eAAe,CAAC,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 AlacarteNotice from '../AlacarteNotice/AlacarteNotice';\nimport AlacarteConfirmation from '../AlacarteConfirmation/AlacarteConfirmation';\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({ apiUrl: props.apiUrl, edxSessionUrl: props.edxSessionUrl });\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 // 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 stay on CartSummary\n // via discountName 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\n await alacarte.placeOrderAsync({\n billing: {\n ...c.billing,\n country: c.billing.country || walletCountry || c.userCountry || '',\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 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\n return (\n <>\n {alacarteDebug}\n <Row className=\"checkout__container bg-light-200\">\n <CountryUnavailableModal\n isOpen={isBillingCountryBlocked}\n homeUrl={homeUrl}\n />\n <Col xs={12} className=\"d-lg-none\">\n <h1 className=\"font-weight-bold text-primary-900\">Checkout</h1>\n </Col>\n\n <Col xs={12} className={isAlreadyOwned ? 'checkout__owned-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 {isAlreadyOwned && (\n <Alert\n variant=\"danger\"\n icon={ErrorIcon}\n className=\"checkout__already-owned-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 && (\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 {!alacarte.priceAccepted && 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 code: appliedCouponCode,\n percent: appliedDiscount.percent,\n })}\n </Alert>\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 />\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"]}
|
|
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,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AC;4CACxD,CAAC;4CACD,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,cAAc,CAAC;4CACnD,QAAQ,EAAE,GAAG,EAAE;gDACb,QAAQ,CAAC,YAAY,EAAE,CAAC;gDACxB,iBAAiB,CAAC,EAAE,CAAC,CAAC;gDACtB,kBAAkB,CAAC,IAAI,CAAC,CAAC;4CAC3B,CAAC;4CACD,WAAW,EAAE,iBAAiB;4CAC9B,QAAQ,EAAE,eAAe;4CACzB,KAAK,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC,eAAe,CAAC,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 AlacarteNotice from '../AlacarteNotice/AlacarteNotice';\nimport AlacarteConfirmation from '../AlacarteConfirmation/AlacarteConfirmation';\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({ apiUrl: props.apiUrl, edxSessionUrl: props.edxSessionUrl });\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 // 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 stay on CartSummary\n // via discountName 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 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\n return (\n <>\n {alacarteDebug}\n <Row className=\"checkout__container bg-light-200\">\n <CountryUnavailableModal\n isOpen={isBillingCountryBlocked}\n homeUrl={homeUrl}\n />\n <Col xs={12} className=\"d-lg-none\">\n <h1 className=\"font-weight-bold text-primary-900\">Checkout</h1>\n </Col>\n\n <Col xs={12} className={isAlreadyOwned ? 'checkout__owned-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 {isAlreadyOwned && (\n <Alert\n variant=\"danger\"\n icon={ErrorIcon}\n className=\"checkout__already-owned-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 && (\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 {!alacarte.priceAccepted && 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 code: appliedCouponCode,\n percent: appliedDiscount.percent,\n })}\n </Alert>\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 />\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"]}
|
|
@@ -7,7 +7,7 @@ export interface ExpressCheckoutProps {
|
|
|
7
7
|
totalAmountCents: number | null;
|
|
8
8
|
/** ISO 4217 currency code, e.g. 'USD'. */
|
|
9
9
|
currency: string | null;
|
|
10
|
-
/** Two-letter country code for
|
|
10
|
+
/** Two-letter country code (kept for API stability). */
|
|
11
11
|
country: string;
|
|
12
12
|
/**
|
|
13
13
|
* Called when the user authorises a wallet payment (Apple Pay / Google Pay).
|
|
@@ -17,5 +17,13 @@ export interface ExpressCheckoutProps {
|
|
|
17
17
|
onPaymentAuthorized: (paymentMethodId: string, walletCountry?: string) => Promise<void>;
|
|
18
18
|
disabled?: boolean;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Express checkout: PayPal (local) | Apple Pay | Google Pay.
|
|
22
|
+
*
|
|
23
|
+
* Apple and Google each get their own Express Checkout Element (one wallet per
|
|
24
|
+
* mount) so we can lay them out in equal columns. A single ECE with both wallets
|
|
25
|
+
* stacks / overflows in this narrow column. `always` keeps the Shopify-like
|
|
26
|
+
* show-even-without-a-saved-card behaviour.
|
|
27
|
+
*/
|
|
20
28
|
declare const ExpressCheckout: React.FC<ExpressCheckoutProps>;
|
|
21
29
|
export default ExpressCheckout;
|
|
@@ -12,76 +12,204 @@ import { useEffect, useRef, useState } from 'react';
|
|
|
12
12
|
import { useIntl } from '@openedx/frontend-base';
|
|
13
13
|
import { PayPalWordmark } from '../BrandMarks/BrandMarks';
|
|
14
14
|
import messages from './Messages';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Express checkout: PayPal (local) | Apple Pay | Google Pay.
|
|
17
|
+
*
|
|
18
|
+
* Apple and Google each get their own Express Checkout Element (one wallet per
|
|
19
|
+
* mount) so we can lay them out in equal columns. A single ECE with both wallets
|
|
20
|
+
* stacks / overflows in this narrow column. `always` keeps the Shopify-like
|
|
21
|
+
* show-even-without-a-saved-card behaviour.
|
|
22
|
+
*/
|
|
23
|
+
const ExpressCheckout = ({ stripe, totalAmountCents, currency, onPaymentAuthorized, disabled, }) => {
|
|
18
24
|
const { formatMessage } = useIntl();
|
|
19
|
-
const
|
|
25
|
+
const appleMountRef = useRef(null);
|
|
26
|
+
const googleMountRef = useRef(null);
|
|
27
|
+
const appleElementsRef = useRef(null);
|
|
28
|
+
const googleElementsRef = useRef(null);
|
|
29
|
+
const appleElementRef = useRef(null);
|
|
30
|
+
const googleElementRef = useRef(null);
|
|
20
31
|
const onPaymentAuthorizedRef = useRef(onPaymentAuthorized);
|
|
21
|
-
const [
|
|
22
|
-
|
|
32
|
+
const [appleReady, setAppleReady] = useState(false);
|
|
33
|
+
const [googleReady, setGoogleReady] = useState(false);
|
|
34
|
+
const [appleVisible, setAppleVisible] = useState(false);
|
|
35
|
+
const [googleVisible, setGoogleVisible] = useState(false);
|
|
36
|
+
const [walletError, setWalletError] = useState(null);
|
|
37
|
+
const hasAmount = !!totalAmountCents && !!currency;
|
|
38
|
+
// Keep slots in the grid until ready so Stripe measures a full column width.
|
|
39
|
+
const showAppleSlot = !appleReady || appleVisible;
|
|
40
|
+
const showGoogleSlot = !googleReady || googleVisible;
|
|
41
|
+
const columnCount = 1 + (showAppleSlot ? 1 : 0) + (showGoogleSlot ? 1 : 0);
|
|
23
42
|
useEffect(() => {
|
|
24
43
|
onPaymentAuthorizedRef.current = onPaymentAuthorized;
|
|
25
44
|
}, [onPaymentAuthorized]);
|
|
26
|
-
// Create the Stripe PaymentRequest and check availability.
|
|
27
|
-
// We use our own custom-styled buttons (not Stripe's paymentRequestButton)
|
|
28
|
-
// so we always show Apple Pay / Google Pay branding — never the Link button.
|
|
29
45
|
useEffect(() => {
|
|
30
|
-
if (!stripe
|
|
31
|
-
|
|
46
|
+
if (!stripe
|
|
47
|
+
|| !totalAmountCents
|
|
48
|
+
|| !currency
|
|
49
|
+
|| !appleMountRef.current
|
|
50
|
+
|| !googleMountRef.current) {
|
|
51
|
+
console.log('[ExpressCheckout] skip mount', {
|
|
52
|
+
hasStripe: !!stripe,
|
|
53
|
+
totalAmountCents,
|
|
54
|
+
currency,
|
|
55
|
+
hasAppleMount: !!appleMountRef.current,
|
|
56
|
+
hasGoogleMount: !!googleMountRef.current,
|
|
57
|
+
});
|
|
58
|
+
setAppleReady(false);
|
|
59
|
+
setGoogleReady(false);
|
|
60
|
+
setAppleVisible(false);
|
|
61
|
+
setGoogleVisible(false);
|
|
62
|
+
setWalletError(null);
|
|
32
63
|
return undefined;
|
|
33
64
|
}
|
|
34
|
-
|
|
35
|
-
|
|
65
|
+
console.log('[ExpressCheckout] mounting wallet slots', { totalAmountCents, currency });
|
|
66
|
+
setAppleReady(false);
|
|
67
|
+
setGoogleReady(false);
|
|
68
|
+
setAppleVisible(false);
|
|
69
|
+
setGoogleVisible(false);
|
|
70
|
+
const sharedElementsOpts = {
|
|
71
|
+
mode: 'payment',
|
|
72
|
+
amount: totalAmountCents,
|
|
36
73
|
currency: currency.toLowerCase(),
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
74
|
+
paymentMethodCreation: 'manual',
|
|
75
|
+
appearance: {
|
|
76
|
+
variables: { borderRadius: '12px' },
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
const bindWallet = (slot, elements, expressElement, mountNode, setReady, setVisible) => {
|
|
80
|
+
expressElement.on('ready', (event) => {
|
|
81
|
+
const methods = event.availablePaymentMethods;
|
|
82
|
+
const visible = slot === 'apple' ? !!(methods === null || methods === void 0 ? void 0 : methods.applePay) : !!(methods === null || methods === void 0 ? void 0 : methods.googlePay);
|
|
83
|
+
console.log(`[ExpressCheckout] ready (${slot})`, {
|
|
84
|
+
applePay: !!(methods === null || methods === void 0 ? void 0 : methods.applePay),
|
|
85
|
+
googlePay: !!(methods === null || methods === void 0 ? void 0 : methods.googlePay),
|
|
86
|
+
raw: methods !== null && methods !== void 0 ? methods : null,
|
|
87
|
+
});
|
|
88
|
+
setVisible(visible);
|
|
89
|
+
setReady(true);
|
|
90
|
+
});
|
|
91
|
+
expressElement.on('confirm', (event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
|
+
var _a, _b, _c, _d;
|
|
93
|
+
setWalletError(null);
|
|
94
|
+
if (!elements.submit) {
|
|
95
|
+
event.paymentFailed({ reason: 'fail' });
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const walletLabel = formatMessage(slot === 'apple' ? messages.applePay : messages.googlePay);
|
|
99
|
+
try {
|
|
100
|
+
const { error: submitError } = yield elements.submit();
|
|
101
|
+
if (submitError) {
|
|
102
|
+
setWalletError(submitError.message || formatMessage(messages.walletUnavailable, {
|
|
103
|
+
wallet: walletLabel,
|
|
104
|
+
}));
|
|
105
|
+
event.paymentFailed({ reason: 'fail' });
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const { paymentMethod, error } = yield stripe.createPaymentMethod({ elements });
|
|
109
|
+
if (error || !(paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.id)) {
|
|
110
|
+
setWalletError((error === null || error === void 0 ? void 0 : error.message) || formatMessage(messages.walletUnavailable, {
|
|
111
|
+
wallet: walletLabel,
|
|
112
|
+
}));
|
|
113
|
+
event.paymentFailed({ reason: 'fail' });
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const walletCountry = ((_b = (_a = event.billingDetails) === null || _a === void 0 ? void 0 : _a.address) === null || _b === void 0 ? void 0 : _b.country)
|
|
117
|
+
|| ((_d = (_c = paymentMethod.billing_details) === null || _c === void 0 ? void 0 : _c.address) === null || _d === void 0 ? void 0 : _d.country);
|
|
118
|
+
yield onPaymentAuthorizedRef.current(paymentMethod.id, walletCountry);
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
console.warn(`[ExpressCheckout] confirm failed (${slot})`, err);
|
|
122
|
+
setWalletError(formatMessage(messages.walletUnavailable, { wallet: walletLabel }));
|
|
123
|
+
event.paymentFailed({ reason: 'fail' });
|
|
124
|
+
}
|
|
125
|
+
}));
|
|
126
|
+
expressElement.mount(mountNode);
|
|
127
|
+
};
|
|
128
|
+
const appleElements = stripe.elements(sharedElementsOpts);
|
|
129
|
+
const googleElements = stripe.elements(sharedElementsOpts);
|
|
130
|
+
appleElementsRef.current = appleElements;
|
|
131
|
+
googleElementsRef.current = googleElements;
|
|
132
|
+
const appleElement = appleElements.create('expressCheckout', {
|
|
133
|
+
buttonHeight: 48,
|
|
134
|
+
emailRequired: true,
|
|
135
|
+
billingAddressRequired: true,
|
|
136
|
+
paymentMethodOrder: ['applePay'],
|
|
137
|
+
buttonType: { applePay: 'plain' },
|
|
138
|
+
buttonTheme: { applePay: 'black' },
|
|
139
|
+
paymentMethods: {
|
|
140
|
+
applePay: 'always',
|
|
141
|
+
googlePay: 'never',
|
|
142
|
+
link: 'never',
|
|
143
|
+
paypal: 'never',
|
|
144
|
+
amazonPay: 'never',
|
|
145
|
+
klarna: 'never',
|
|
146
|
+
},
|
|
147
|
+
layout: { maxColumns: 1, maxRows: 0, overflow: 'never' },
|
|
148
|
+
});
|
|
149
|
+
appleElementRef.current = appleElement;
|
|
150
|
+
const googleElement = googleElements.create('expressCheckout', {
|
|
151
|
+
buttonHeight: 48,
|
|
152
|
+
emailRequired: true,
|
|
153
|
+
billingAddressRequired: true,
|
|
154
|
+
paymentMethodOrder: ['googlePay'],
|
|
155
|
+
buttonType: { googlePay: 'plain' },
|
|
156
|
+
buttonTheme: { googlePay: 'black' },
|
|
157
|
+
paymentMethods: {
|
|
158
|
+
applePay: 'never',
|
|
159
|
+
googlePay: 'always',
|
|
160
|
+
link: 'never',
|
|
161
|
+
paypal: 'never',
|
|
162
|
+
amazonPay: 'never',
|
|
163
|
+
klarna: 'never',
|
|
164
|
+
},
|
|
165
|
+
layout: { maxColumns: 1, maxRows: 0, overflow: 'never' },
|
|
40
166
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
167
|
+
googleElementRef.current = googleElement;
|
|
168
|
+
bindWallet('apple', appleElements, appleElement, appleMountRef.current, setAppleReady, setAppleVisible);
|
|
169
|
+
bindWallet('google', googleElements, googleElement, googleMountRef.current, setGoogleReady, setGoogleVisible);
|
|
170
|
+
return () => {
|
|
171
|
+
var _a, _b, _c, _d;
|
|
44
172
|
try {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
173
|
+
(_a = appleElement.unmount) === null || _a === void 0 ? void 0 : _a.call(appleElement);
|
|
174
|
+
(_b = appleElement.destroy) === null || _b === void 0 ? void 0 : _b.call(appleElement);
|
|
175
|
+
(_c = googleElement.unmount) === null || _c === void 0 ? void 0 : _c.call(googleElement);
|
|
176
|
+
(_d = googleElement.destroy) === null || _d === void 0 ? void 0 : _d.call(googleElement);
|
|
48
177
|
}
|
|
49
|
-
catch (
|
|
50
|
-
|
|
178
|
+
catch (_e) {
|
|
179
|
+
// Elements may already be gone.
|
|
51
180
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return () => {
|
|
61
|
-
cancelled = true;
|
|
62
|
-
paymentRequestRef.current = null;
|
|
181
|
+
appleElementRef.current = null;
|
|
182
|
+
googleElementRef.current = null;
|
|
183
|
+
appleElementsRef.current = null;
|
|
184
|
+
googleElementsRef.current = null;
|
|
185
|
+
setAppleReady(false);
|
|
186
|
+
setGoogleReady(false);
|
|
187
|
+
setAppleVisible(false);
|
|
188
|
+
setGoogleVisible(false);
|
|
63
189
|
};
|
|
64
190
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
65
|
-
}, [stripe, currency,
|
|
66
|
-
// Update the payment request total when the amount changes (e.g. coupon applied).
|
|
191
|
+
}, [stripe, currency, hasAmount]);
|
|
67
192
|
useEffect(() => {
|
|
68
|
-
|
|
193
|
+
var _a, _b, _c, _d;
|
|
194
|
+
if (!totalAmountCents || !currency)
|
|
69
195
|
return;
|
|
196
|
+
const update = { amount: totalAmountCents, currency: currency.toLowerCase() };
|
|
70
197
|
try {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
});
|
|
198
|
+
(_b = (_a = appleElementsRef.current) === null || _a === void 0 ? void 0 : _a.update) === null || _b === void 0 ? void 0 : _b.call(_a, update);
|
|
199
|
+
(_d = (_c = googleElementsRef.current) === null || _c === void 0 ? void 0 : _c.update) === null || _d === void 0 ? void 0 : _d.call(_c, update);
|
|
74
200
|
}
|
|
75
|
-
catch (
|
|
76
|
-
//
|
|
201
|
+
catch (_e) {
|
|
202
|
+
// Safe to ignore mid-sheet updates.
|
|
77
203
|
}
|
|
78
|
-
}, [totalAmountCents]);
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
204
|
+
}, [totalAmountCents, currency]);
|
|
205
|
+
const walletClassName = (ready, visible) => {
|
|
206
|
+
if (!ready)
|
|
207
|
+
return 'express-checkout__wallet express-checkout__wallet--pending';
|
|
208
|
+
if (!visible)
|
|
209
|
+
return 'express-checkout__wallet express-checkout__wallet--unavailable';
|
|
210
|
+
return 'express-checkout__wallet';
|
|
82
211
|
};
|
|
83
|
-
|
|
84
|
-
return (_jsxs("div", { className: "express-checkout", children: [_jsx("h3", { className: "express-checkout__heading", children: formatMessage(messages.heading) }), _jsxs("div", { className: "express-checkout__buttons", children: [_jsx("button", { type: "button", disabled: true, "aria-label": formatMessage(messages.paypal), className: "express-checkout__button express-checkout__button--paypal", children: _jsx(PayPalWordmark, {}) }), _jsxs("button", { type: "button", disabled: buttonsDisabled, onClick: handleWalletClick, "aria-label": formatMessage(messages.applePay), className: "express-checkout__button express-checkout__button--apple-pay", children: [_jsx(AppleLogo, {}), "Pay"] }), _jsxs("button", { type: "button", disabled: buttonsDisabled, onClick: handleWalletClick, "aria-label": formatMessage(messages.googlePay), className: "express-checkout__button express-checkout__button--google-pay", children: [_jsx(GooglePayIcon, {}), "Pay"] })] })] }));
|
|
212
|
+
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: 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 }))] }));
|
|
85
213
|
};
|
|
86
214
|
export default ExpressCheckout;
|
|
87
215
|
//# sourceMappingURL=ExpressCheckout.js.map
|