@movmo_app/payments 0.1.0 → 0.2.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.d.ts CHANGED
@@ -7,6 +7,13 @@ export declare interface CardFieldError {
7
7
  message: string;
8
8
  }
9
9
 
10
+ declare interface CardFieldValidity {
11
+ /** True only when the card-number field has a complete, length-valid value. */
12
+ number: boolean;
13
+ /** True only when the CVV field has a complete value (3 or 4 digits). */
14
+ cvv: boolean;
15
+ }
16
+
10
17
  export declare type CardFormStatus = 'idle' | 'loading' | 'ready' | 'tokenizing' | 'saving' | 'error';
11
18
 
12
19
  export declare interface CardholderTokenizeData {
@@ -25,7 +32,7 @@ export declare const getPaymentsConfig: () => InternalPaymentsConfig;
25
32
  /* Excluded from this release type: InternalPaymentsConfig */
26
33
 
27
34
  export declare const MovmoCardForm: {
28
- ({ userId, onSuccess, onError, isDefault, className, defaultCardholderFirstName, defaultCardholderLastName, }: MovmoCardFormProps): JSX_2.Element;
35
+ ({ userId, onSuccess, onError, isDefault, className, defaultCardholderName, defaultCardholderFirstName, defaultCardholderLastName, autoSave, formId, hideInternalSaveButton, onCanSubmitChange, }: MovmoCardFormProps): JSX_2.Element;
29
36
  displayName: string;
30
37
  };
31
38
 
@@ -36,13 +43,115 @@ export declare interface MovmoCardFormProps {
36
43
  isDefault?: boolean;
37
44
  className?: string;
38
45
  /**
39
- * Pre-fills the cardholder first-name input. Cardholders aren't always the
46
+ * Pre-fills the cardholder name input. Cardholders aren't always the
40
47
  * logged-in user (spouse card, corporate card), so the field remains
41
- * editable — pass `user.firstName` as a sensible default.
48
+ * editable — pass `user.fullName` as a sensible default.
49
+ */
50
+ defaultCardholderName?: string;
51
+ /**
52
+ * @deprecated Prefer `defaultCardholderName`. Concatenated with
53
+ * `defaultCardholderLastName` to seed the single cardholder name field.
42
54
  */
43
55
  defaultCardholderFirstName?: string;
44
- /** Pre-fills the cardholder last-name input. See `defaultCardholderFirstName`. */
56
+ /** @deprecated See `defaultCardholderFirstName`. */
45
57
  defaultCardholderLastName?: string;
58
+ /**
59
+ * When true, the form submits automatically the moment all fields are valid —
60
+ * no Save button is rendered. Matches the flights-ui "first card" auto-save UX.
61
+ * Defaults to `false`.
62
+ */
63
+ autoSave?: boolean;
64
+ /**
65
+ * HTML `id` for the underlying `<form>` element. Lets a parent (e.g. modal
66
+ * footer) wire its own submit button via `<button type="submit" form="...">`
67
+ * — useful when `hideInternalSaveButton` is true. Defaults to `movmo-card-form`.
68
+ */
69
+ formId?: string;
70
+ /**
71
+ * When true, the form omits its internal Save button. Use together with
72
+ * `formId` to drive submit from a parent (e.g. a modal footer's Save button).
73
+ */
74
+ hideInternalSaveButton?: boolean;
75
+ /**
76
+ * Fires whenever the "ready to submit" state changes (all fields valid +
77
+ * not in flight). Use to enable / disable an external Save button.
78
+ */
79
+ onCanSubmitChange?: (canSubmit: boolean) => void;
80
+ }
81
+
82
+ /**
83
+ * Compact preview of a single saved card: brand icon + "Brand last4".
84
+ * Used by consumers (e.g. flights-ui's collapsed checkout drawer) to show
85
+ * the currently-selected card outside the full `<PaymentMethodsManager />`
86
+ * list view. Keeps the brand-icon styling consistent with the expanded list.
87
+ */
88
+ export declare const PaymentMethodPreview: ({ method, trailing, onClick, className, }: PaymentMethodPreviewProps) => JSX_2.Element;
89
+
90
+ export declare interface PaymentMethodPreviewProps {
91
+ /**
92
+ * The card to render. Consumers typically derive this from
93
+ * `useUserPaymentMethods(userId)` — e.g. the selected card in a checkout
94
+ * drawer, or the default card on a summary line.
95
+ */
96
+ method: PaymentMethodSummary;
97
+ /** Trailing slot — flights-ui drops an expand-chevron button here. */
98
+ trailing?: React.ReactNode;
99
+ /** Whole-row click handler — typically toggles the drawer open. */
100
+ onClick?: () => void;
101
+ className?: string;
102
+ }
103
+
104
+ export declare const PaymentMethodsManager: {
105
+ ({ userId, defaultCardholderName, defaultCardholderFirstName, defaultCardholderLastName, selectedId, onSelect, onChange, paymentTypeSelector, autoSaveFirstCard, selectionSetsDefault, showDefaultBadge, className, }: PaymentMethodsManagerProps): JSX_2.Element;
106
+ displayName: string;
107
+ };
108
+
109
+ export declare interface PaymentMethodsManagerProps {
110
+ userId: string;
111
+ /**
112
+ * Pre-fill the single cardholder-name input in the add-card form.
113
+ * Falls back to `defaultCardholderFirstName + " " + defaultCardholderLastName`
114
+ * for backward compatibility with the legacy MovmoCardForm props.
115
+ */
116
+ defaultCardholderName?: string;
117
+ /** @deprecated Use `defaultCardholderName`. */
118
+ defaultCardholderFirstName?: string;
119
+ /** @deprecated Use `defaultCardholderName`. */
120
+ defaultCardholderLastName?: string;
121
+ /** Selection (opt-in). When `onSelect` is provided, each row renders a radio. */
122
+ selectedId?: string;
123
+ onSelect?: (method: PaymentMethodSummary) => void;
124
+ /** Fires when the list state changes (add, delete, set-default). */
125
+ onChange?: (items: PaymentMethodSummary[]) => void;
126
+ /**
127
+ * Show the Credit card / PayPal / GooglePay / Klarna / ACH radios above
128
+ * the card-capture form. Only Credit card is functional today; the others
129
+ * render as "Coming soon" to match the existing flights-ui design without
130
+ * dropping the visual cues. Defaults to `true`. accounts-ui can opt out
131
+ * by passing `false`.
132
+ */
133
+ paymentTypeSelector?: boolean;
134
+ /**
135
+ * When `true` AND the user has zero saved cards, the card form auto-submits
136
+ * the moment all fields are valid. Matches the flights-ui first-card UX.
137
+ * Defaults to `true`.
138
+ */
139
+ autoSaveFirstCard?: boolean;
140
+ /**
141
+ * When `true`, clicking a row both fires `onSelect` AND sets that method
142
+ * as the default (the flights-ui checkout model: "selected = default").
143
+ * Also hides the "Set as default" menu item since the row click already
144
+ * does it. Requires `onSelect` to be useful. Defaults to `false`.
145
+ */
146
+ selectionSetsDefault?: boolean;
147
+ /**
148
+ * Render the green "Default" pill on the default row. accounts-ui keeps
149
+ * this on; flights-ui passes `false` (the thick selected-border alone
150
+ * communicates default since `selectionSetsDefault` couples the two).
151
+ * Defaults to `true`.
152
+ */
153
+ showDefaultBadge?: boolean;
154
+ className?: string;
46
155
  }
47
156
 
48
157
  export declare interface PaymentMethodSummary {
@@ -56,10 +165,33 @@ export declare interface PaymentMethodSummary {
56
165
 
57
166
  export declare interface PaymentsConfig {
58
167
  baseUrl: string;
168
+ /**
169
+ * Base URL for Movmo's payment-icon assets (Visa / MC / Amex / Discover SVGs
170
+ * + PayPal / GooglePay / Klarna PNGs). Defaults to the e2e CDN; prod
171
+ * consumers should override at boot once a prod CDN is set up.
172
+ */
173
+ iconCdnBaseUrl?: string;
59
174
  }
60
175
 
61
176
  export declare const setPaymentsConfig: (config: Partial<PaymentsConfig>) => void;
62
177
 
178
+ /**
179
+ * Calls `DELETE /v1/users/:userId/payment-methods/:methodId`.
180
+ *
181
+ * The hook owns the network call + status; consumers own list state so they
182
+ * can apply optimistic updates / rollback at their layer. The returned promise
183
+ * resolves on success and rejects on failure so callers can roll back.
184
+ */
185
+ export declare const useDeletePaymentMethod: (userId: string) => UseDeletePaymentMethodResult;
186
+
187
+ export declare interface UseDeletePaymentMethodResult {
188
+ deletePaymentMethod: (methodId: string) => Promise<void>;
189
+ status: UseDeletePaymentMethodStatus;
190
+ error: string | null;
191
+ }
192
+
193
+ export declare type UseDeletePaymentMethodStatus = 'idle' | 'pending' | 'error';
194
+
63
195
  /**
64
196
  * Mounts PCI-safe card-capture fields into the DOM containers identified by
65
197
  * `numberEl` and `cvvEl`, fetches a signed tokenization session from
@@ -79,12 +211,70 @@ export declare interface UseMovmoCardFieldsOptions {
79
211
  cvvEl?: string;
80
212
  onCardTokenized?: (token: string) => void;
81
213
  onFieldErrors?: (errors: CardFieldError[]) => void;
214
+ /**
215
+ * Fires whenever per-field validity changes (number length valid, CVV length valid).
216
+ * Use to gate the save button at the form layer.
217
+ */
218
+ onValidityChange?: (validity: CardFieldValidity) => void;
219
+ /**
220
+ * Fires whenever the detected card brand changes (visa/master/american_express/discover/etc).
221
+ * Use to render the brand icon inline with the card-number field.
222
+ */
223
+ onBrandChange?: (brand: string | null) => void;
82
224
  }
83
225
 
84
226
  export declare interface UseMovmoCardFieldsResult {
85
227
  status: 'idle' | 'loading' | 'ready' | 'error';
86
228
  error: string | null;
87
229
  tokenize: (data: CardholderTokenizeData) => void;
230
+ /** Latest validity snapshot — also pushed via `onValidityChange`. */
231
+ validity: CardFieldValidity;
232
+ /** Latest detected brand (or null if unknown). */
233
+ brand: string | null;
234
+ /**
235
+ * Programmatically move keyboard focus into one of the Spreedly iframes.
236
+ * No-op when the hook is not in the `'ready'` state. Used to auto-advance
237
+ * focus from an outer form input (e.g. expiry) into a hosted field (CVV).
238
+ */
239
+ focusField: (field: 'number' | 'cvv') => void;
88
240
  }
89
241
 
242
+ /**
243
+ * Calls `PUT /v1/users/:userId/payment-methods/:methodId` with
244
+ * `{ isDefault: true }`. Server clears the previous default automatically.
245
+ *
246
+ * The hook owns the network call + status; consumers own list state so they
247
+ * can apply optimistic updates / rollback at their layer. The returned promise
248
+ * resolves on success and rejects on failure so callers can roll back.
249
+ */
250
+ export declare const useSetDefaultPaymentMethod: (userId: string) => UseSetDefaultPaymentMethodResult;
251
+
252
+ export declare interface UseSetDefaultPaymentMethodResult {
253
+ setDefault: (methodId: string) => Promise<void>;
254
+ status: UseSetDefaultPaymentMethodStatus;
255
+ error: string | null;
256
+ }
257
+
258
+ export declare type UseSetDefaultPaymentMethodStatus = 'idle' | 'pending' | 'error';
259
+
260
+ /**
261
+ * Fetches a user's saved payment methods from monolith-api.
262
+ *
263
+ * Auto-runs on mount and whenever `userId` changes. Cancels the in-flight
264
+ * request on unmount or refetch so consumers don't see stale results land
265
+ * after a navigation. Status mirrors `useMovmoCardFields`:
266
+ * `idle` → `loading` → `ready | error`.
267
+ */
268
+ export declare const useUserPaymentMethods: (userId: string) => UseUserPaymentMethodsResult;
269
+
270
+ export declare interface UseUserPaymentMethodsResult {
271
+ items: PaymentMethodSummary[];
272
+ status: UseUserPaymentMethodsStatus;
273
+ error: string | null;
274
+ /** Re-issues the GET request. Cancels any in-flight request first. */
275
+ refetch: () => void;
276
+ }
277
+
278
+ export declare type UseUserPaymentMethodsStatus = 'idle' | 'loading' | 'ready' | 'error';
279
+
90
280
  export { }