@movmo_app/payments 0.4.0 → 0.5.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/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;
@@ -139,7 +154,7 @@ export declare const getPaymentsConfig: () => InternalPaymentsConfig;
139
154
  /* Excluded from this release type: InternalPaymentsConfig */
140
155
 
141
156
  export declare const MovmoCardForm: {
142
- ({ 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;
143
158
  displayName: string;
144
159
  };
145
160
 
@@ -147,6 +162,14 @@ export declare interface MovmoCardFormProps {
147
162
  userId: string;
148
163
  onSuccess: (paymentMethod: PaymentMethodSummary) => void;
149
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;
150
173
  isDefault?: boolean;
151
174
  className?: string;
152
175
  /**
@@ -200,6 +223,39 @@ export declare interface MovmoCardFormProps {
200
223
  autoFocus?: 'number' | 'cvv';
201
224
  }
202
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
+
203
259
  /**
204
260
  * Compact preview of a single saved card: brand icon + label. Used by
205
261
  * consumers (e.g. flights-ui's collapsed checkout drawer) to show the
@@ -232,7 +288,7 @@ export declare interface PaymentMethodPreviewProps {
232
288
  }
233
289
 
234
290
  export declare const PaymentMethodsManager: {
235
- ({ 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;
236
292
  displayName: string;
237
293
  };
238
294
 
@@ -253,6 +309,16 @@ export declare interface PaymentMethodsManagerProps {
253
309
  onSelect?: (method: PaymentMethodSummary) => void;
254
310
  /** Fires when the list state changes (add, delete, set-default). */
255
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;
256
322
  /**
257
323
  * Show the Credit card / PayPal / GooglePay / Klarna / ACH radios above
258
324
  * the card-capture form. Only Credit card is functional today; the others
@@ -402,6 +468,19 @@ export declare interface UseMovmoCardFieldsOptions {
402
468
  export declare interface UseMovmoCardFieldsResult {
403
469
  status: 'idle' | 'loading' | 'ready' | 'error';
404
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;
405
484
  tokenize: (data: CardholderTokenizeData) => void;
406
485
  /** Latest validity snapshot — also pushed via `onValidityChange`. */
407
486
  validity: CardFieldValidity;