@movmo_app/payments 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +10 -10
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +134 -2
- package/dist/index.es.js +1267 -1021
- package/dist/index.es.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -17,6 +17,21 @@ declare interface CardFieldFocus {
|
|
|
17
17
|
cvv: boolean;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* The failure sources that can arise while the hook boots: fetching the
|
|
22
|
+
* tokenization session, loading the Spreedly iframe script, or registering
|
|
23
|
+
* handlers / calling `spreedly.init` (the latter two are Spreedly-side, so
|
|
24
|
+
* they're tagged `spreedly-script`). The bare rejection reason doesn't identify
|
|
25
|
+
* which step failed, so each is wrapped in an `InitError` carrying its source —
|
|
26
|
+
* letting `MovmoCardForm` forward the right `PaymentErrorSource` to the
|
|
27
|
+
* manager's `onError`.
|
|
28
|
+
*
|
|
29
|
+
* Declared as a slice of `PaymentErrorSource` via `Extract` so a rename or
|
|
30
|
+
* removal of either literal in `types.ts` is caught here at compile time rather
|
|
31
|
+
* than silently drifting from the forwarded value in `MovmoCardForm`.
|
|
32
|
+
*/
|
|
33
|
+
declare type CardFieldsInitErrorSource = Extract<PaymentErrorSource, 'tokenization-session' | 'spreedly-script'>;
|
|
34
|
+
|
|
20
35
|
declare interface CardFieldValidity {
|
|
21
36
|
/** True only when the card-number field has a complete, length-valid value. */
|
|
22
37
|
number: boolean;
|
|
@@ -126,12 +141,20 @@ export declare interface CreateMovmoAuthFetchOptions {
|
|
|
126
141
|
readCookie?: (name: string) => string | null;
|
|
127
142
|
}
|
|
128
143
|
|
|
144
|
+
/**
|
|
145
|
+
* The cardholder/zip subset of {@link UpdatePaymentMethodPatch} that the Edit
|
|
146
|
+
* flow (MOVMO-381) can mutate. Derived via `Pick` so it stays in sync if the
|
|
147
|
+
* editable field set grows — shared by the modal, the manager, and
|
|
148
|
+
* `useUpdatePaymentMethod` so the patch shape isn't restated in three places.
|
|
149
|
+
*/
|
|
150
|
+
declare type EditablePaymentMethodFields = Pick<UpdatePaymentMethodPatch, 'cardholderName' | 'zip'>;
|
|
151
|
+
|
|
129
152
|
export declare const getPaymentsConfig: () => InternalPaymentsConfig;
|
|
130
153
|
|
|
131
154
|
/* Excluded from this release type: InternalPaymentsConfig */
|
|
132
155
|
|
|
133
156
|
export declare const MovmoCardForm: {
|
|
134
|
-
({ userId, onSuccess, onError, isDefault, className, defaultCardholderName, defaultCardholderFirstName, defaultCardholderLastName, autoSave, formId, hideInternalSaveButton, onCanSubmitChange, onSavingChange, autoFocus, }: MovmoCardFormProps): JSX_2.Element;
|
|
157
|
+
({ userId, onSuccess, onError, onErrorDetail, isDefault, className, defaultCardholderName, defaultCardholderFirstName, defaultCardholderLastName, autoSave, formId, hideInternalSaveButton, onCanSubmitChange, onSavingChange, autoFocus, }: MovmoCardFormProps): JSX_2.Element;
|
|
135
158
|
displayName: string;
|
|
136
159
|
};
|
|
137
160
|
|
|
@@ -139,6 +162,14 @@ export declare interface MovmoCardFormProps {
|
|
|
139
162
|
userId: string;
|
|
140
163
|
onSuccess: (paymentMethod: PaymentMethodSummary) => void;
|
|
141
164
|
onError: (error: string) => void;
|
|
165
|
+
/**
|
|
166
|
+
* Optional structured-error sink for SDK observability. Fires alongside the
|
|
167
|
+
* string `onError` (which still drives the banner) with the originating
|
|
168
|
+
* `source` — `save-from-token`, `card-tokenize`, `tokenization-session`, or
|
|
169
|
+
* `spreedly-script` — so the parent (`PaymentMethodsManager`) can forward it
|
|
170
|
+
* to telemetry without losing the failure kind.
|
|
171
|
+
*/
|
|
172
|
+
onErrorDetail?: (error: PaymentManagerError) => void;
|
|
142
173
|
isDefault?: boolean;
|
|
143
174
|
className?: string;
|
|
144
175
|
/**
|
|
@@ -192,6 +223,39 @@ export declare interface MovmoCardFormProps {
|
|
|
192
223
|
autoFocus?: 'number' | 'cvv';
|
|
193
224
|
}
|
|
194
225
|
|
|
226
|
+
/**
|
|
227
|
+
* Identifies which SDK-internal operation produced an error surfaced to the
|
|
228
|
+
* user. Lets a consumer route `PaymentMethodsManager`'s `onError` to telemetry
|
|
229
|
+
* (Sentry, console) or UI gates (e.g. mute a Book button) per failure kind.
|
|
230
|
+
*
|
|
231
|
+
* - `tokenization-session` — `GET /v1/payments/tokenization-session` failed.
|
|
232
|
+
* - `spreedly-script` — the Spreedly Hosted Fields iframe script failed to load or init.
|
|
233
|
+
* - `card-tokenize` — Spreedly rejected the card while tokenizing. NOTE: this
|
|
234
|
+
* covers both ordinary inline field validation (a mistyped
|
|
235
|
+
* or incomplete card number / CVV) and genuine vault-internal
|
|
236
|
+
* tokenize failures, so it is high-volume and driven by normal
|
|
237
|
+
* user typos. Treat it as a signal for UI/UX work, not as an
|
|
238
|
+
* alertable error rate on its own.
|
|
239
|
+
* - `save-from-token` — `POST /v1/users/.../payment-methods/from-token` failed.
|
|
240
|
+
* - `list` — `GET /v1/users/.../payment-methods` failed.
|
|
241
|
+
* - `set-default` — the set-default PUT failed.
|
|
242
|
+
* - `update` — the edit-card (cardholder/zip) PUT failed.
|
|
243
|
+
* - `delete` — the delete request failed.
|
|
244
|
+
*/
|
|
245
|
+
export declare type PaymentErrorSource = 'tokenization-session' | 'card-tokenize' | 'save-from-token' | 'list' | 'delete' | 'set-default' | 'update' | 'spreedly-script';
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Structured error surfaced by `PaymentMethodsManager`'s `onError` callback.
|
|
249
|
+
* `message` is the same user-facing string rendered in the SDK's error banner;
|
|
250
|
+
* `cause` carries the original `Error`/rejection where available so consumers
|
|
251
|
+
* can forward it to `Sentry.captureException`.
|
|
252
|
+
*/
|
|
253
|
+
export declare interface PaymentManagerError {
|
|
254
|
+
source: PaymentErrorSource;
|
|
255
|
+
message: string;
|
|
256
|
+
cause?: unknown;
|
|
257
|
+
}
|
|
258
|
+
|
|
195
259
|
/**
|
|
196
260
|
* Compact preview of a single saved card: brand icon + label. Used by
|
|
197
261
|
* consumers (e.g. flights-ui's collapsed checkout drawer) to show the
|
|
@@ -224,7 +288,7 @@ export declare interface PaymentMethodPreviewProps {
|
|
|
224
288
|
}
|
|
225
289
|
|
|
226
290
|
export declare const PaymentMethodsManager: {
|
|
227
|
-
({ userId, defaultCardholderName, defaultCardholderFirstName, defaultCardholderLastName, selectedId, onSelect, onChange, paymentTypeSelector, autoSaveFirstCard, selectionSetsDefault, showDefaultBadge, collapsible, cardLabelFormat, className, }: PaymentMethodsManagerProps): JSX_2.Element;
|
|
291
|
+
({ userId, defaultCardholderName, defaultCardholderFirstName, defaultCardholderLastName, selectedId, onSelect, onChange, onError, paymentTypeSelector, autoSaveFirstCard, selectionSetsDefault, showDefaultBadge, collapsible, cardLabelFormat, className, }: PaymentMethodsManagerProps): JSX_2.Element;
|
|
228
292
|
displayName: string;
|
|
229
293
|
};
|
|
230
294
|
|
|
@@ -245,6 +309,16 @@ export declare interface PaymentMethodsManagerProps {
|
|
|
245
309
|
onSelect?: (method: PaymentMethodSummary) => void;
|
|
246
310
|
/** Fires when the list state changes (add, delete, set-default). */
|
|
247
311
|
onChange?: (items: PaymentMethodSummary[]) => void;
|
|
312
|
+
/**
|
|
313
|
+
* SDK-level observability hook. Fires whenever the manager surfaces a failure
|
|
314
|
+
* to the user, with a discriminated `source`: `list` (load), the add-card
|
|
315
|
+
* paths (`tokenization-session`, `spreedly-script`, `card-tokenize`,
|
|
316
|
+
* `save-from-token`), `set-default`, `update` (edit), or `delete`. `message`
|
|
317
|
+
* matches the rendered banner copy; `cause` carries the original error where
|
|
318
|
+
* available. Wire it to telemetry (e.g. `Sentry.captureException`) and/or UI
|
|
319
|
+
* gates. Additive and non-intrusive — errors are still rendered in-SDK.
|
|
320
|
+
*/
|
|
321
|
+
onError?: (error: PaymentManagerError) => void;
|
|
248
322
|
/**
|
|
249
323
|
* Show the Credit card / PayPal / GooglePay / Klarna / ACH radios above
|
|
250
324
|
* the card-capture form. Only Credit card is functional today; the others
|
|
@@ -296,6 +370,22 @@ export declare interface PaymentMethodSummary {
|
|
|
296
370
|
expMonth: number;
|
|
297
371
|
expYear: number;
|
|
298
372
|
isDefault: boolean;
|
|
373
|
+
/**
|
|
374
|
+
* Which vault the row lives in. monolith-api returns this on every row
|
|
375
|
+
* post-MOVMO-381. Only `'spreedly'` rows accept cardholder/zip metadata
|
|
376
|
+
* edits — Stripe rows are immutable on those fields and the backend rejects
|
|
377
|
+
* the patch (4xx). The Edit menu item in PaymentMethodsManager is gated on
|
|
378
|
+
* this value.
|
|
379
|
+
*
|
|
380
|
+
* Optional so the UI doesn't crash on pre-MOVMO-381 monolith deployments
|
|
381
|
+
* that haven't shipped the new field yet — those rows behave as if
|
|
382
|
+
* Edit isn't available.
|
|
383
|
+
*/
|
|
384
|
+
vault?: 'stripe' | 'spreedly';
|
|
385
|
+
/** Current cardholder name (MOVMO-381). Empty/absent for legacy rows. */
|
|
386
|
+
cardholderName?: string;
|
|
387
|
+
/** Current billing ZIP (MOVMO-381). Empty/absent for legacy rows. */
|
|
388
|
+
zip?: string;
|
|
299
389
|
}
|
|
300
390
|
|
|
301
391
|
export declare interface PaymentsConfig {
|
|
@@ -319,6 +409,14 @@ export declare interface PaymentsConfig {
|
|
|
319
409
|
|
|
320
410
|
export declare const setPaymentsConfig: (config: Partial<PaymentsConfig>) => void;
|
|
321
411
|
|
|
412
|
+
export declare interface UpdatePaymentMethodPatch {
|
|
413
|
+
isDefault?: boolean;
|
|
414
|
+
/** MOVMO-381 — editable on Spreedly rows only; monolith-api rejects (4xx) Stripe rows. */
|
|
415
|
+
cardholderName?: string;
|
|
416
|
+
/** MOVMO-381 — editable on Spreedly rows only; monolith-api rejects (4xx) Stripe rows. */
|
|
417
|
+
zip?: string;
|
|
418
|
+
}
|
|
419
|
+
|
|
322
420
|
/**
|
|
323
421
|
* Calls `DELETE /v1/users/:userId/payment-methods/:methodId`.
|
|
324
422
|
*
|
|
@@ -370,6 +468,19 @@ export declare interface UseMovmoCardFieldsOptions {
|
|
|
370
468
|
export declare interface UseMovmoCardFieldsResult {
|
|
371
469
|
status: 'idle' | 'loading' | 'ready' | 'error';
|
|
372
470
|
error: string | null;
|
|
471
|
+
/**
|
|
472
|
+
* When `status === 'error'` from a boot failure, identifies whether the
|
|
473
|
+
* tokenization-session fetch or the Spreedly script load / init was at fault.
|
|
474
|
+
* `null` otherwise (field-validation/tokenize errors are reported via
|
|
475
|
+
* `onFieldErrors`).
|
|
476
|
+
*/
|
|
477
|
+
errorSource: CardFieldsInitErrorSource | null;
|
|
478
|
+
/**
|
|
479
|
+
* The original rejection / thrown value behind a boot failure (the
|
|
480
|
+
* `InitError`'s `cause`), so consumers can forward it to
|
|
481
|
+
* `Sentry.captureException`. `null` when not in a boot-error state.
|
|
482
|
+
*/
|
|
483
|
+
errorCause: unknown;
|
|
373
484
|
tokenize: (data: CardholderTokenizeData) => void;
|
|
374
485
|
/** Latest validity snapshot — also pushed via `onValidityChange`. */
|
|
375
486
|
validity: CardFieldValidity;
|
|
@@ -407,6 +518,27 @@ export declare interface UseSetDefaultPaymentMethodResult {
|
|
|
407
518
|
|
|
408
519
|
export declare type UseSetDefaultPaymentMethodStatus = 'idle' | 'pending' | 'error';
|
|
409
520
|
|
|
521
|
+
/**
|
|
522
|
+
* Calls `PUT /v1/users/:userId/payment-methods/:methodId` with the
|
|
523
|
+
* cardholder-name + zip subset (MOVMO-381). The backend forwards to Spreedly
|
|
524
|
+
* for vault-backed rows and rejects the request (4xx) for Stripe-backed rows;
|
|
525
|
+
* the resulting `Error` carries the server's message so callers can surface it
|
|
526
|
+
* in the modal.
|
|
527
|
+
*
|
|
528
|
+
* Follows the same idle→pending→idle/error contract as
|
|
529
|
+
* `useSetDefaultPaymentMethod` (throws on failure so optimistic-update
|
|
530
|
+
* consumers can roll back), with a `(methodId, patch)` signature.
|
|
531
|
+
*/
|
|
532
|
+
export declare const useUpdatePaymentMethod: (userId: string) => UseUpdatePaymentMethodResult;
|
|
533
|
+
|
|
534
|
+
export declare interface UseUpdatePaymentMethodResult {
|
|
535
|
+
updatePaymentMethod: (methodId: string, patch: EditablePaymentMethodFields) => Promise<void>;
|
|
536
|
+
status: UseUpdatePaymentMethodStatus;
|
|
537
|
+
error: string | null;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
export declare type UseUpdatePaymentMethodStatus = 'idle' | 'pending' | 'error';
|
|
541
|
+
|
|
410
542
|
/**
|
|
411
543
|
* Fetches a user's saved payment methods from monolith-api.
|
|
412
544
|
*
|