@movmo/express-checkout-button 1.11.1 → 1.13.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.md +93 -23
- package/dist/dts/MovmoCheckoutButton.d.ts +33 -1
- package/dist/dts/MovmoCheckoutOverlay.d.ts +17 -0
- package/dist/dts/api.d.ts +17 -1
- package/dist/dts/index.d.ts +3 -2
- 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 +8 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +68 -2
- package/dist/index.es.js +2 -2
- package/dist/index.es.js.map +1 -1
- package/package.json +17 -4
- package/dist/index.cjs.js +0 -8
- package/dist/index.cjs.js.map +0 -1
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ function MyBookingPage() {
|
|
|
34
34
|
<MovmoCheckoutButton
|
|
35
35
|
iataCode="PR"
|
|
36
36
|
apiKey="your-movmo-api-key"
|
|
37
|
-
providerID="
|
|
37
|
+
providerID="duffel"
|
|
38
38
|
flightOfferID="offer-123-456-789"
|
|
39
39
|
isProd={false} // Set to true for production environment
|
|
40
40
|
/>
|
|
@@ -56,7 +56,7 @@ import { MovmoCheckoutButton } from '@movmo/express-checkout-button';
|
|
|
56
56
|
import '@movmo/express-checkout-button/dist/index.css';
|
|
57
57
|
|
|
58
58
|
function MyBookingPage() {
|
|
59
|
-
// Flight offer data retrieved from your booking system (
|
|
59
|
+
// Flight offer data retrieved from your booking system (e.g. Darwin, Dohop)
|
|
60
60
|
const flightOffer = {
|
|
61
61
|
// Your raw flight offer data from the provider
|
|
62
62
|
};
|
|
@@ -68,7 +68,7 @@ function MyBookingPage() {
|
|
|
68
68
|
<MovmoCheckoutButton
|
|
69
69
|
iataCode="AA"
|
|
70
70
|
apiKey="your-movmo-api-key"
|
|
71
|
-
providerID="
|
|
71
|
+
providerID="darwin"
|
|
72
72
|
flightOffer={flightOffer}
|
|
73
73
|
isProd={false} // Set to true for production environment
|
|
74
74
|
/>
|
|
@@ -85,25 +85,58 @@ export default MyBookingPage;
|
|
|
85
85
|
| --------------- | ------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
86
86
|
| `iataCode` | string | Yes | The IATA code for the airline |
|
|
87
87
|
| `apiKey` | string | Yes | Your Movmo API key |
|
|
88
|
-
| `providerID` | string | Yes | The provider identifier
|
|
88
|
+
| `providerID` | string | Yes | The provider identifier: one of "darwin", "duffel", "dohop", or the sandbox provider id Movmo gives you at onboarding for testing |
|
|
89
89
|
| `flightOffer` | object | No\* | The raw flight offer data object from the provider. Required if `flightOfferID` is not provided |
|
|
90
90
|
| `flightOfferID` | string | No\* | The ID of a pre-saved flight offer. Required if `flightOffer` is not provided |
|
|
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 |
|
|
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 |
|
|
94
96
|
|
|
95
97
|
\*Note: Either `flightOffer` or `flightOfferID` must be provided, but not both.
|
|
96
98
|
|
|
99
|
+
### Handling errors
|
|
100
|
+
|
|
101
|
+
```jsx
|
|
102
|
+
<MovmoCheckoutButton
|
|
103
|
+
{...props}
|
|
104
|
+
onError={(error) => {
|
|
105
|
+
// Show your own error toast, or fall back to your native checkout.
|
|
106
|
+
showToast(`Checkout unavailable: ${error.message}`);
|
|
107
|
+
}}
|
|
108
|
+
/>
|
|
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
|
+
|
|
97
130
|
## Provider Options
|
|
98
131
|
|
|
99
132
|
The `providerID` prop accepts provider identifiers as strings. Common providers include:
|
|
100
133
|
|
|
101
134
|
```jsx
|
|
102
135
|
// Common provider IDs
|
|
103
|
-
'
|
|
104
|
-
'
|
|
105
|
-
'duffel'; // For Duffel flight data
|
|
106
|
-
//
|
|
136
|
+
'darwin'; // For Darwin flight data (raw PSS offer JSON via `flightOffer`)
|
|
137
|
+
'dohop'; // For Dohop flight data (raw offer JSON via `flightOffer`)
|
|
138
|
+
'duffel'; // For Duffel flight data (offer id via `flightOfferID` — no raw offer save)
|
|
139
|
+
// Testing: use the sandbox provider id Movmo gives you at onboarding
|
|
107
140
|
```
|
|
108
141
|
|
|
109
142
|
## Environment Configuration
|
|
@@ -121,25 +154,18 @@ The `isProd` prop controls which Movmo endpoints are used:
|
|
|
121
154
|
|
|
122
155
|
## Vanilla JS / `<script>` tag (no React required)
|
|
123
156
|
|
|
124
|
-
The package also ships a self-contained UMD bundle (`dist/express-checkout.umd.js
|
|
125
|
-
|
|
126
|
-
`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`:
|
|
127
160
|
|
|
128
161
|
```html
|
|
129
162
|
<div id="movmo-checkout"></div>
|
|
130
|
-
|
|
131
|
-
can't alter the script (generate the hash from the pinned file, e.g.
|
|
132
|
-
`openssl dgst -sha384 -binary express-checkout.umd.js | openssl base64 -A`): -->
|
|
133
|
-
<script
|
|
134
|
-
src="https://unpkg.com/@movmo/express-checkout-button@1.11.0/dist/express-checkout.umd.js"
|
|
135
|
-
integrity="sha384-<hash-of-the-pinned-file>"
|
|
136
|
-
crossorigin="anonymous"
|
|
137
|
-
></script>
|
|
163
|
+
<script src="https://cdn.e2e.movmo.io/sdk/express-checkout/v1/express-checkout.js"></script>
|
|
138
164
|
<script>
|
|
139
165
|
var handle = window.MovmoExpressCheckout.mount('#movmo-checkout', {
|
|
140
166
|
iataCode: 'AA',
|
|
141
167
|
apiKey: 'your-movmo-api-key',
|
|
142
|
-
providerID: '
|
|
168
|
+
providerID: 'darwin',
|
|
143
169
|
flightOffer: rawOffer,
|
|
144
170
|
// isProd: true — add when you go live
|
|
145
171
|
});
|
|
@@ -148,8 +174,38 @@ the package's `unpkg` field) for host pages without React or a bundler. It defin
|
|
|
148
174
|
```
|
|
149
175
|
|
|
150
176
|
`mount(target, options)` accepts a CSS selector or an Element (it throws a clear error when a
|
|
151
|
-
selector matches nothing) and takes the same options as the React component's props
|
|
152
|
-
|
|
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.
|
|
153
209
|
|
|
154
210
|
## Internal / QA traffic flagging
|
|
155
211
|
|
|
@@ -225,6 +281,20 @@ for the button, `.my-wrapper button > span` for the Movmo badge — which is sta
|
|
|
225
281
|
The package has no runtime HTTP dependency: the offer-save call uses the platform `fetch`. If your
|
|
226
282
|
project relied on the transitive `axios` install that older versions pulled in, declare it yourself.
|
|
227
283
|
|
|
284
|
+
### Tree-shaking (`sideEffects`)
|
|
285
|
+
|
|
286
|
+
`package.json` declares `"sideEffects": ["**/*.css"]` — everything except CSS is claimed
|
|
287
|
+
side-effect-free for bundlers that tree-shake unused code. This is accurate even though
|
|
288
|
+
`MovmoCheckoutOverlay` registers module-level `window` listeners (guarded by
|
|
289
|
+
`typeof window !== 'undefined'`) for back-button cleanup and refresh rehydration: the ESM/CJS
|
|
290
|
+
build (`dist/index.es.js` / `dist/index.cjs`) is a single, non-splittable module, not a set of
|
|
291
|
+
independently importable files a bundler could pick apart. A consumer either imports something
|
|
292
|
+
from this package (in which case the whole module — listeners included — loads and runs, exactly
|
|
293
|
+
as intended) or doesn't import it at all (in which case there's nothing to tree-shake in the first
|
|
294
|
+
place). There is no importable subset of this package whose side effects a bundler could silently
|
|
295
|
+
drop while still using another part of it, which is the only way a `sideEffects` flag like this
|
|
296
|
+
one causes real bugs.
|
|
297
|
+
|
|
228
298
|
## Development
|
|
229
299
|
|
|
230
300
|
### Running Storybook
|
|
@@ -252,7 +322,7 @@ npm run build
|
|
|
252
322
|
The Storybook includes several examples:
|
|
253
323
|
|
|
254
324
|
1. **With Pre-saved Offer ID**: Example using a pre-saved flight offer ID
|
|
255
|
-
2. **With Raw Flight Offer**: Example with raw
|
|
325
|
+
2. **With Raw Flight Offer**: Example with raw PSS flight offer data (e.g. Darwin) that will be saved on button click
|
|
256
326
|
3. **Production Environment**: Example configured for production environment
|
|
257
327
|
4. **Minimal With Offer ID**: Minimal configuration example with just the required props
|
|
258
328
|
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { MovmoCheckoutExitInfo } from './MovmoCheckoutOverlay';
|
|
2
|
+
import { MovmoBookingCompleteInfo, MovmoCheckoutExitInfo } from './MovmoCheckoutOverlay';
|
|
3
|
+
/**
|
|
4
|
+
* A user-facing failure the button could not recover from on its own (MOVMO-673).
|
|
5
|
+
* `stage` is `'save_offer'` — the click-time raw-offer save failed (CORS from an
|
|
6
|
+
* unregistered origin, a 4xx/5xx from the proxy, or a timeout) — or `'missing_offer'`
|
|
7
|
+
* — neither `flightOfferID` nor `flightOffer` was provided. `status` is the HTTP
|
|
8
|
+
* status when the failure was a non-2xx response; it is omitted for network errors,
|
|
9
|
+
* timeouts, and the `missing_offer` stage. `message` prefers the backend's own JSON
|
|
10
|
+
* `message`/`error` field, falling back to a generic error string.
|
|
11
|
+
*/
|
|
12
|
+
export type MovmoCheckoutError = {
|
|
13
|
+
stage: 'save_offer' | 'missing_offer';
|
|
14
|
+
status?: number;
|
|
15
|
+
message: string;
|
|
16
|
+
};
|
|
3
17
|
export interface MovmoCheckoutButtonProps {
|
|
4
18
|
iataCode: string;
|
|
5
19
|
apiKey: string;
|
|
@@ -22,5 +36,23 @@ export interface MovmoCheckoutButtonProps {
|
|
|
22
36
|
* the checkout.
|
|
23
37
|
*/
|
|
24
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;
|
|
48
|
+
/**
|
|
49
|
+
* Fires when the button hits a failure it cannot recover from on its own — the
|
|
50
|
+
* click-time offer save failed, or neither `flightOfferID` nor `flightOffer` was
|
|
51
|
+
* provided. The button already logs a `console.warn` and emits the matching
|
|
52
|
+
* analytics event either way; this is for the partner page to react (e.g. show
|
|
53
|
+
* its own error toast, or fall back to its native checkout). Additive — omitting
|
|
54
|
+
* it preserves the console-only behavior.
|
|
55
|
+
*/
|
|
56
|
+
onError?: (error: MovmoCheckoutError) => void;
|
|
25
57
|
}
|
|
26
58
|
export declare const MovmoCheckoutButton: React.FC<MovmoCheckoutButtonProps>;
|
|
@@ -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/api.d.ts
CHANGED
|
@@ -9,4 +9,20 @@ export interface ApiClient {
|
|
|
9
9
|
post<T>(path: string, body: unknown): Promise<T>;
|
|
10
10
|
}
|
|
11
11
|
export declare const createApiClient: (apiKey: string, airlineRef: string, isProd?: boolean) => ApiClient;
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Discriminated result of {@link saveProviderOffer} (MOVMO-673). Replaces the earlier
|
|
14
|
+
* `string | null` contract so the button (and, via `onError`, the partner page) can
|
|
15
|
+
* surface WHY a save failed — an HTTP status when the response was non-2xx, and a
|
|
16
|
+
* message that prefers the backend's own JSON `message`/`error` field over a generic
|
|
17
|
+
* fetch/timeout string.
|
|
18
|
+
*/
|
|
19
|
+
export type SaveOfferResult = {
|
|
20
|
+
ok: true;
|
|
21
|
+
offerId: string;
|
|
22
|
+
} | {
|
|
23
|
+
ok: false;
|
|
24
|
+
status?: number;
|
|
25
|
+
message: string;
|
|
26
|
+
cause?: unknown;
|
|
27
|
+
};
|
|
28
|
+
export declare const saveProviderOffer: (providerID: string, rawOffer: object, client: ApiClient) => Promise<SaveOfferResult>;
|
package/dist/dts/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import './index.css';
|
|
2
2
|
export { MovmoCheckoutButton } from './MovmoCheckoutButton';
|
|
3
|
-
export type { MovmoCheckoutButtonProps } from './MovmoCheckoutButton';
|
|
4
|
-
export type {
|
|
3
|
+
export type { MovmoCheckoutButtonProps, MovmoCheckoutError } from './MovmoCheckoutButton';
|
|
4
|
+
export type { SaveOfferResult } from './api';
|
|
5
|
+
export type { MovmoBookingCompleteInfo, MovmoCheckoutExitInfo, MovmoCheckoutOverlayOptions, } from './MovmoCheckoutOverlay';
|
|
5
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.
|