@movmo/express-checkout-button 1.12.0 → 1.13.1
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.md +61 -13
- package/dist/dts/MovmoCheckoutButton.d.ts +10 -1
- package/dist/dts/MovmoCheckoutOverlay.d.ts +17 -0
- package/dist/dts/index.d.ts +1 -1
- package/dist/dts/umd.d.ts +3 -1
- package/dist/express-checkout.umd.js +5 -5
- package/dist/express-checkout.umd.js.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +28 -2
- package/dist/index.es.js +2 -2
- package/dist/index.es.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -91,6 +91,7 @@ export default MyBookingPage;
|
|
|
91
91
|
| `isProd` | boolean | No | Whether to use production endpoints (default: false). When true, uses production API and flights URLs; when false, uses e2e (testing) endpoints |
|
|
92
92
|
| `className` | string | No | Extra CSS classes merged onto the button element |
|
|
93
93
|
| `onExit` | function| No | `(info: MovmoCheckoutExitInfo) => void` — called when the checkout overlay hands control back to your page. `info.reason` is `'booking_confirmed'` (traveler clicked "Return to airline" after a successful booking — a booking-complete callback already fired for it), `'offer_unavailable'` (the offer expired/became unbookable), or `'search_again'` |
|
|
94
|
+
| `onBookingComplete` | function| No | `(info: MovmoBookingCompleteInfo) => void` — called once per booking while the traveler is still on Movmo's confirmation screen, before any later `onExit({ reason: 'booking_confirmed' })`. `info.bookingId` is Movmo's booking id; `info.airlinePnr` is the airline's own record locator (absent if the provider returned none); `info.airlineRef` is the airline IATA/company code, not the PNR. Does not re-fire after a page refresh inside the checkout, and is deduped so a replayed message for a booking already reported won't call it twice |
|
|
94
95
|
| `onError` | function| No | `(error: MovmoCheckoutError) => void` — called when the button hits a failure it can't recover from on its own: `{ stage: 'save_offer', status?, message }` when the click-time raw-offer save fails (a non-2xx response, a network error, or a timeout), or `{ stage: 'missing_offer', message }` when neither `flightOffer` nor `flightOfferID` was provided. `status` is the HTTP status code when the failure was a non-2xx response; it's omitted for network errors, timeouts, and the `missing_offer` stage. The button always logs a `console.warn` too, whether or not `onError` is provided |
|
|
95
96
|
|
|
96
97
|
\*Note: Either `flightOffer` or `flightOfferID` must be provided, but not both.
|
|
@@ -107,6 +108,25 @@ export default MyBookingPage;
|
|
|
107
108
|
/>
|
|
108
109
|
```
|
|
109
110
|
|
|
111
|
+
### Handling a completed booking
|
|
112
|
+
|
|
113
|
+
```jsx
|
|
114
|
+
<MovmoCheckoutButton
|
|
115
|
+
{...props}
|
|
116
|
+
onBookingComplete={(info) => {
|
|
117
|
+
// info.airlinePnr is the record locator the traveler quotes back to you —
|
|
118
|
+
// absent if the provider returned none.
|
|
119
|
+
saveConfirmation({ bookingId: info.bookingId, pnr: info.airlinePnr });
|
|
120
|
+
}}
|
|
121
|
+
/>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
The raw `MOVMO_BOOKING_COMPLETE` `postMessage` still works if you already listen for it
|
|
125
|
+
yourself — `onBookingComplete` is the preferred, typed way to get the same data. Either way,
|
|
126
|
+
the PNR never appears in the page URL: the parent's `replaceState` after a booking only ever
|
|
127
|
+
carries `bookingId`/`airlineRef`/`providerId`, so it can't leak into browser history, analytics
|
|
128
|
+
or tag-manager tools, session replay, or a server log/Referer on refresh.
|
|
129
|
+
|
|
110
130
|
## Provider Options
|
|
111
131
|
|
|
112
132
|
The `providerID` prop accepts provider identifiers as strings. Common providers include:
|
|
@@ -134,20 +154,13 @@ The `isProd` prop controls which Movmo endpoints are used:
|
|
|
134
154
|
|
|
135
155
|
## Vanilla JS / `<script>` tag (no React required)
|
|
136
156
|
|
|
137
|
-
The package also ships a self-contained UMD bundle (`dist/express-checkout.umd.js
|
|
138
|
-
|
|
139
|
-
`window.MovmoExpressCheckout`:
|
|
157
|
+
The package also ships a self-contained UMD bundle (`dist/express-checkout.umd.js`) for host
|
|
158
|
+
pages without React or a bundler — React, styling, and every dependency are bundled in, so
|
|
159
|
+
there is nothing else to include. It defines `window.MovmoExpressCheckout`:
|
|
140
160
|
|
|
141
161
|
```html
|
|
142
162
|
<div id="movmo-checkout"></div>
|
|
143
|
-
|
|
144
|
-
can't alter the script (generate the hash from the pinned file, e.g.
|
|
145
|
-
`openssl dgst -sha384 -binary express-checkout.umd.js | openssl base64 -A`): -->
|
|
146
|
-
<script
|
|
147
|
-
src="https://unpkg.com/@movmo/express-checkout-button@1.11.0/dist/express-checkout.umd.js"
|
|
148
|
-
integrity="sha384-<hash-of-the-pinned-file>"
|
|
149
|
-
crossorigin="anonymous"
|
|
150
|
-
></script>
|
|
163
|
+
<script src="https://cdn.e2e.movmo.io/sdk/express-checkout/v1/express-checkout.js"></script>
|
|
151
164
|
<script>
|
|
152
165
|
var handle = window.MovmoExpressCheckout.mount('#movmo-checkout', {
|
|
153
166
|
iataCode: 'AA',
|
|
@@ -161,8 +174,38 @@ the package's `unpkg` field) for host pages without React or a bundler. It defin
|
|
|
161
174
|
```
|
|
162
175
|
|
|
163
176
|
`mount(target, options)` accepts a CSS selector or an Element (it throws a clear error when a
|
|
164
|
-
selector matches nothing) and takes the same options as the React component's props
|
|
165
|
-
|
|
177
|
+
selector matches nothing) and takes the same options as the React component's props, including
|
|
178
|
+
`onExit`, `onError`, and `onBookingComplete` — all pass straight through. Calling `mount()`
|
|
179
|
+
again on the same element logs a warning and returns the existing handle instead of
|
|
180
|
+
double-rendering.
|
|
181
|
+
|
|
182
|
+
The `/v1/` URL above is a **mutable major-version alias** — it always serves the latest 1.x
|
|
183
|
+
release, so new releases apply automatically with no change on your side. Convenient for e2e
|
|
184
|
+
and demo pages, but not immutable — don't pin CI or production configs to it by name.
|
|
185
|
+
|
|
186
|
+
### Version pinning and Subresource Integrity
|
|
187
|
+
|
|
188
|
+
For production, pin an **exact, immutable version** and add Subresource Integrity so a CDN
|
|
189
|
+
compromise can't alter the script. Each release publishes a `.sri` sidecar next to the bundle —
|
|
190
|
+
fetch `https://cdn.e2e.movmo.io/sdk/express-checkout/{version}/express-checkout.js.sri` to get
|
|
191
|
+
the exact `integrity` value (or generate it yourself from the pinned file:
|
|
192
|
+
`openssl dgst -sha384 -binary express-checkout.js | openssl base64 -A`):
|
|
193
|
+
|
|
194
|
+
```html
|
|
195
|
+
<script
|
|
196
|
+
src="https://cdn.e2e.movmo.io/sdk/express-checkout/{version}/express-checkout.js"
|
|
197
|
+
integrity="sha384-<hash-from-the-.sri-sidecar>"
|
|
198
|
+
crossorigin="anonymous"
|
|
199
|
+
></script>
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
An SRI-pinned tag does not auto-update — you take new releases by updating the URL and hash
|
|
203
|
+
together.
|
|
204
|
+
|
|
205
|
+
`unpkg` is also declared in `package.json`
|
|
206
|
+
(`unpkg.com/@movmo/express-checkout-button@{version}/dist/express-checkout.umd.js`) as a
|
|
207
|
+
secondary path if you'd rather not depend on Movmo's own CDN, but the first-party URLs above
|
|
208
|
+
are the primary, documented way to load the script tag build.
|
|
166
209
|
|
|
167
210
|
## Internal / QA traffic flagging
|
|
168
211
|
|
|
@@ -252,6 +295,11 @@ place). There is no importable subset of this package whose side effects a bundl
|
|
|
252
295
|
drop while still using another part of it, which is the only way a `sideEffects` flag like this
|
|
253
296
|
one causes real bugs.
|
|
254
297
|
|
|
298
|
+
On refresh rehydration, the overlay reopens in the same environment (`isProd`) the button was
|
|
299
|
+
originally mounted with, never guessed from your page's hostname; a direct visit to a
|
|
300
|
+
`/movmo/checkout` URL that never went through that mount (so nothing was persisted) does not
|
|
301
|
+
reopen the overlay.
|
|
302
|
+
|
|
255
303
|
## Development
|
|
256
304
|
|
|
257
305
|
### Running Storybook
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { MovmoCheckoutExitInfo } from './MovmoCheckoutOverlay';
|
|
2
|
+
import { MovmoBookingCompleteInfo, MovmoCheckoutExitInfo } from './MovmoCheckoutOverlay';
|
|
3
3
|
/**
|
|
4
4
|
* A user-facing failure the button could not recover from on its own (MOVMO-673).
|
|
5
5
|
* `stage` is `'save_offer'` — the click-time raw-offer save failed (CORS from an
|
|
@@ -36,6 +36,15 @@ export interface MovmoCheckoutButtonProps {
|
|
|
36
36
|
* the checkout.
|
|
37
37
|
*/
|
|
38
38
|
onExit?: (info: MovmoCheckoutExitInfo) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Fires once per booking, while the traveler is still on Movmo's confirmation
|
|
41
|
+
* screen and before any `onExit({ reason: 'booking_confirmed' })` — that exit
|
|
42
|
+
* only fires later, if the traveler clicks "Return to airline". `info.airlinePnr`
|
|
43
|
+
* is the airline's own record locator (absent if the provider returned none);
|
|
44
|
+
* `info.airlineRef` is the airline IATA/company code, not the PNR. Like `onExit`,
|
|
45
|
+
* it does not re-fire after a page refresh inside the checkout.
|
|
46
|
+
*/
|
|
47
|
+
onBookingComplete?: (info: MovmoBookingCompleteInfo) => void;
|
|
39
48
|
/**
|
|
40
49
|
* Fires when the button hits a failure it cannot recover from on its own — the
|
|
41
50
|
* click-time offer save failed, or neither `flightOfferID` nor `flightOffer` was
|
|
@@ -3,6 +3,15 @@ import { MovmoExitReason } from '@movmo_app/types';
|
|
|
3
3
|
export interface MovmoCheckoutExitInfo {
|
|
4
4
|
reason: MovmoExitReason;
|
|
5
5
|
}
|
|
6
|
+
/** Passed to onBookingComplete when a booking is confirmed inside the checkout. */
|
|
7
|
+
export interface MovmoBookingCompleteInfo {
|
|
8
|
+
bookingId: string;
|
|
9
|
+
/** Record locator (PNR) in the airline's own reservation system. Absent if the provider returned none. */
|
|
10
|
+
airlinePnr?: string;
|
|
11
|
+
/** Airline IATA / company code — not the PNR. */
|
|
12
|
+
airlineRef?: string;
|
|
13
|
+
providerId?: string;
|
|
14
|
+
}
|
|
6
15
|
export interface MovmoCheckoutOverlayOptions {
|
|
7
16
|
/**
|
|
8
17
|
* Fires after an iframe-initiated exit (e.g. the traveler clicked
|
|
@@ -14,6 +23,14 @@ export interface MovmoCheckoutOverlayOptions {
|
|
|
14
23
|
* re-hydrated overlay falls back to the default close behavior.
|
|
15
24
|
*/
|
|
16
25
|
onExit?: (info: MovmoCheckoutExitInfo) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Fires once per booking, while the traveler is still on Movmo's
|
|
28
|
+
* confirmation screen and before any `onExit({ reason: 'booking_confirmed' })`
|
|
29
|
+
* — that exit only fires later, if the traveler clicks "Return to airline".
|
|
30
|
+
* Like `onExit`, it does not re-fire after a page refresh: a re-hydrated
|
|
31
|
+
* overlay has no way to know whether this already ran before the reload.
|
|
32
|
+
*/
|
|
33
|
+
onBookingComplete?: (info: MovmoBookingCompleteInfo) => void;
|
|
17
34
|
/**
|
|
18
35
|
* The partner page's URL + history.state captured by the button IMMEDIATELY
|
|
19
36
|
* before it pushed the /movmo/checkout entry. An iframe-initiated exit
|
package/dist/dts/index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import './index.css';
|
|
|
2
2
|
export { MovmoCheckoutButton } from './MovmoCheckoutButton';
|
|
3
3
|
export type { MovmoCheckoutButtonProps, MovmoCheckoutError } from './MovmoCheckoutButton';
|
|
4
4
|
export type { SaveOfferResult } from './api';
|
|
5
|
-
export type { MovmoCheckoutExitInfo, MovmoCheckoutOverlayOptions } from './MovmoCheckoutOverlay';
|
|
5
|
+
export type { MovmoBookingCompleteInfo, MovmoCheckoutExitInfo, MovmoCheckoutOverlayOptions, } from './MovmoCheckoutOverlay';
|
|
6
6
|
export type { MovmoExitReason } from '@movmo_app/types';
|
package/dist/dts/umd.d.ts
CHANGED
|
@@ -11,7 +11,9 @@ export interface MovmoMountHandle {
|
|
|
11
11
|
*
|
|
12
12
|
* @param target A CSS selector (resolved via `document.querySelector`) or an
|
|
13
13
|
* existing DOM element to mount into.
|
|
14
|
-
* @param options The same props accepted by the React `<MovmoCheckoutButton
|
|
14
|
+
* @param options The same props accepted by the React `<MovmoCheckoutButton>`,
|
|
15
|
+
* including `onExit`, `onError`, and `onBookingComplete` — all
|
|
16
|
+
* three pass straight through to the mounted component.
|
|
15
17
|
* @returns A handle whose `unmount()` removes the rendered button. Calling
|
|
16
18
|
* `mount()` again on an already-mounted element returns the SAME
|
|
17
19
|
* handle instead of creating a second root.
|