@flopay/js 1.20.8 → 1.20.9

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.
@@ -0,0 +1,37 @@
1
+ export interface PaymentMethodDescriptor {
2
+ id: string;
3
+ /** The payment method, e.g. `ideal`: an open string, never a closed list. */
4
+ method: string;
5
+ /** Where the method is placed: `card`, a provider's own group, `wallets` or `apms`. */
6
+ group: string;
7
+ /** The provider that serves it: an open string, which may be one the runtime has no adapter for. */
8
+ provider: string;
9
+ available: boolean;
10
+ /** Whether a payment made with it can be reused. Taken from the response, never guessed. */
11
+ reusable: boolean;
12
+ /** How the method reaches the buyer. `provider-frame` and `hosted-card` are the two card surfaces. */
13
+ presentation: 'button' | 'redirect' | 'provider-frame' | 'hosted-card';
14
+ /** Browser-safe settings for the provider's adapter. */
15
+ config: Readonly<Record<string, unknown>>;
16
+ }
17
+ export interface DescriptorRead {
18
+ /**
19
+ * Whether the response advertises its methods at all (an empty list included). `false` is a
20
+ * response that predates descriptors: the 1.x gateway reading stays in force.
21
+ */
22
+ advertised: boolean;
23
+ methods: PaymentMethodDescriptor[];
24
+ /** How many entries were malformed and left out. */
25
+ rejected: number;
26
+ }
27
+ /**
28
+ * The capability token the runtime sends when it reads a session, so the API only adds
29
+ * descriptors to the answers of a runtime that understands them (1.x answers stay unchanged).
30
+ */
31
+ export declare const PAYMENT_METHODS_CAPABILITY = "payment-methods-v1";
32
+ /**
33
+ * Reads the advertised methods from a session response, wrapped in `data` or flat. A response
34
+ * with no list is a 1.x answer. A list that is not a list advertises nothing, so it can never
35
+ * fall back to the 1.x gateways and hand a method to a provider the API did not name.
36
+ */
37
+ export declare function readPaymentMethodDescriptors(body: unknown): DescriptorRead;
@@ -0,0 +1,13 @@
1
+ export type JsonRecord = Record<string, unknown>;
2
+ export declare function isRecord(value: unknown): value is JsonRecord;
3
+ export declare function text(...values: unknown[]): string | undefined;
4
+ /** The record inside the API's `data` wrapper, or the body itself when it has none. */
5
+ export declare function dataOf(body: unknown): JsonRecord;
6
+ export declare function delay(ms: number): Promise<void>;
7
+ export declare function providerMessage(error: unknown, fallback: string): string;
8
+ export declare function pageGlobal(name: string): unknown;
9
+ /**
10
+ * Adds a provider's script to the page once and settles when it loads. A script still on the
11
+ * page is reused; one that failed or was removed is added again on the next mount.
12
+ */
13
+ export declare function loadScript(src: string, attributes?: Record<string, string>): Promise<void>;
@@ -0,0 +1,118 @@
1
+ import type { PaymentMethodDescriptor } from './method-descriptors.js';
2
+ /** One buyer attempt at one method, from the click to its one terminal outcome. */
3
+ export interface ProviderAttempt {
4
+ readonly method: string;
5
+ /** `POST …/intents` for the descriptor's provider and this method, with `request` merged in. */
6
+ createIntent(request?: Record<string, unknown>): Promise<Record<string, unknown>>;
7
+ /** Remembers `reference` so a redirect back to this page resumes this session. */
8
+ saveContinuation(reference: string): void;
9
+ /**
10
+ * The provider says the buyer paid: the attempt now waits for the backend to say so too. Only
11
+ * the backend's session completes the payment.
12
+ */
13
+ settle(): Promise<void>;
14
+ /**
15
+ * Hands the provider's approval to the backend (`POST …/process`) and ends the attempt with
16
+ * what the backend answers: a refusal is one `decline`, a payment still processing waits for
17
+ * the session, and only an accepted payment completes.
18
+ */
19
+ process(body: Record<string, unknown>, options?: {
20
+ declineMessage?: string;
21
+ }): Promise<void>;
22
+ decline(failure: {
23
+ message: string;
24
+ declineCode?: string;
25
+ }): void;
26
+ /** The buyer cancelled at the provider; `paymentMethodType` is the channel the provider names. */
27
+ cancel(details?: {
28
+ paymentMethodType?: string;
29
+ }): void;
30
+ fail(error: unknown): void;
31
+ /** Ends the attempt with no outcome: the buyer started another one, or a popup was blocked. */
32
+ abandon(): void;
33
+ /** Whether the attempt has ended, so a late callback can be told apart from a live one. */
34
+ readonly ended: boolean;
35
+ }
36
+ /** What the shared host gives an adapter. */
37
+ export interface ProviderServices {
38
+ readonly session: {
39
+ id: string;
40
+ token: string;
41
+ currency?: string;
42
+ amount?: number;
43
+ };
44
+ /** The descriptors this mount hands to this provider, in the order the API sent them. */
45
+ readonly methods: readonly PaymentMethodDescriptor[];
46
+ /** False once the mount is gone: nothing an adapter does afterwards reaches the merchant. */
47
+ active(): boolean;
48
+ /** Whether a new attempt could start now (none running and the session not paid). */
49
+ canAttempt(): boolean;
50
+ /** Starts an attempt, or `null` while another is running or the session is already paid. */
51
+ beginAttempt(method: string): ProviderAttempt | null;
52
+ }
53
+ /** A provider's own redirect return that keeps its own continuation (a 1.x return). */
54
+ interface OwnedProviderReturn {
55
+ /** The session the buyer left from, when this browser saved it before the redirect. */
56
+ resume: {
57
+ sessionId?: string;
58
+ nonce?: string;
59
+ } | null;
60
+ outcome: 'succeeded' | 'failed';
61
+ /** Forgets the continuation and takes the provider's parameters out of the address. */
62
+ consume(): void;
63
+ }
64
+ export interface MountedMethod {
65
+ destroy(): void;
66
+ }
67
+ export interface RuntimeProviderAdapter {
68
+ /** Matches `PaymentMethodDescriptor.provider`. */
69
+ readonly provider: string;
70
+ /** The query parameters this provider's redirect return carries: removed from every outlet. */
71
+ readonly returnParameters?: readonly string[];
72
+ /**
73
+ * Groups in which the provider draws all of its methods as one surface: those descriptors
74
+ * reach `mount` together, once, as `methods`.
75
+ */
76
+ readonly combinedGroups?: readonly string[];
77
+ /** The methods a 1.x session's gateway entry stands for, when the API sends no descriptors. */
78
+ legacyMethods?(gateways: Readonly<Record<string, unknown>>): PaymentMethodDescriptor[];
79
+ /** Loads the provider's SDK or probes the browser, once per mount, before anything renders. */
80
+ prepare?(services: ProviderServices): Promise<void>;
81
+ /** Whether this browser can use the method. It can only suppress a method, never add one. */
82
+ isSupported?(descriptor: PaymentMethodDescriptor, services: ProviderServices): boolean | Promise<boolean>;
83
+ mount(request: {
84
+ descriptor: PaymentMethodDescriptor;
85
+ /** Every descriptor this mount draws: `[descriptor]`, or a whole combined group. */
86
+ methods: readonly PaymentMethodDescriptor[];
87
+ host: HTMLElement;
88
+ services: ProviderServices;
89
+ /** The surface says whether the buyer can use it here (a wallet the device lacks cannot). */
90
+ setAvailable(available: boolean): void;
91
+ /** The surface could not be drawn: its place on the page goes. */
92
+ remove(): void;
93
+ }): MountedMethod | Promise<MountedMethod>;
94
+ /** Reads this provider's return out of the page's query, or `null` when it is not its own. */
95
+ readReturn?(query: URLSearchParams): {
96
+ /** Correlates the return with the continuation saved before the redirect. */
97
+ reference: string;
98
+ outcome: 'succeeded' | 'failed' | 'cancelled';
99
+ } | null;
100
+ /** A return the provider keeps its own continuation for, read once at mount. */
101
+ takeReturn?(): OwnedProviderReturn | null;
102
+ /** Whether the full checkout can take over a saved payment of this method that failed (1.x). */
103
+ recoversInFullCheckout?(method: string): boolean;
104
+ /**
105
+ * The failure a status read's `ACTION_REQUIRED` attempt stands for when the buyer must approve
106
+ * this provider's payment again, or `null` when the attempt is not this provider's.
107
+ */
108
+ reapproval?(attempt: Record<string, unknown>): Record<string, unknown> | null;
109
+ }
110
+ /** Registers an adapter; the function it returns removes it again. */
111
+ export declare function registerRuntimeProvider(adapter: RuntimeProviderAdapter): () => void;
112
+ /** The providers the runtime has an adapter for. */
113
+ export declare function registeredProviderIds(): string[];
114
+ /** The adapter registered for a provider, if any: an unknown provider has none to fall back to. */
115
+ export declare function providerAdapter(provider: string): RuntimeProviderAdapter | undefined;
116
+ /** Every registered adapter, in the order they registered. */
117
+ export declare function registeredAdapters(): RuntimeProviderAdapter[];
118
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { RuntimeProviderAdapter } from '../provider-registry.js';
2
+ export declare const builtInProviders: readonly RuntimeProviderAdapter[];
@@ -0,0 +1,2 @@
1
+ import type { RuntimeProviderAdapter } from '../provider-registry.js';
2
+ export declare const paypalAdapter: RuntimeProviderAdapter;
@@ -0,0 +1,2 @@
1
+ import type { RuntimeProviderAdapter } from '../provider-registry.js';
2
+ export declare const stripeAdapter: RuntimeProviderAdapter;
@@ -1,17 +1,19 @@
1
1
  import type { PaymentMethodGroupLayout } from '@flopay/shared';
2
2
  import { FloPayError } from '@flopay/shared';
3
3
  import type { CheckoutRuntimeEvent, CheckoutRuntimeLayout } from './checkout-runtime/contract.js';
4
- type JsonRecord = Record<string, unknown>;
4
+ import type { DescriptorRead } from './checkout-runtime/method-descriptors.js';
5
+ import type { JsonRecord } from './checkout-runtime/provider-kit.js';
5
6
  export declare function isCompleteStatus(status: unknown): boolean;
6
7
  /**
7
8
  * Whether the full checkout can take over a saved payment that failed recoverably (1.x): one
8
- * that names no payment method, a card, or a PayPal payment (whose order the API supplied).
9
+ * that names no payment method, a card, or a method whose provider says the full checkout can
10
+ * take it over.
9
11
  */
10
12
  export declare function fullCheckoutRecovers(method: string | undefined): boolean;
11
13
  /**
12
14
  * The failure a status read's `ACTION_REQUIRED` attempt stands for when the buyer must approve
13
- * a PayPal order again (1.x `resolveCheckoutSessionStatus`): `paypal_direct_required` with the
14
- * fresh order, which the full checkout then takes over. `null` for any other attempt.
15
+ * the provider's payment again (1.x `resolveCheckoutSessionStatus`), which the full checkout then
16
+ * takes over. `null` for any other attempt.
15
17
  */
16
18
  export declare function reapprovalFailure(attempt: Record<string, unknown>): Record<string, unknown> | null;
17
19
  /** One merchant outcome per payment: nothing reaches the merchant once the session is paid. */
@@ -29,34 +31,59 @@ export interface PaymentMethodsSession {
29
31
  token: string;
30
32
  currency?: string;
31
33
  amount?: number;
34
+ /** The 1.x gateway entries, read only when the API advertises no descriptors. */
32
35
  gateways?: JsonRecord;
36
+ /** The API's method advertisement, from the one descriptor reader. */
37
+ methods?: DescriptorRead;
33
38
  }
34
- /** A buyer the provider's redirect brought back to this page, read once at mount. */
35
- export interface RedirectReturn {
36
- redirectStatus: string | null;
39
+ /** A buyer a provider's redirect brought back to this page, read once at mount. */
40
+ export interface ProviderReturn {
41
+ provider?: string;
42
+ /** The method the buyer left with, when the continuation saved it. */
43
+ method?: string;
44
+ outcome: 'succeeded' | 'failed' | 'cancelled';
37
45
  /** The session this browser left from, saved before the redirect, when it matches. */
38
46
  resume: {
39
47
  sessionId?: string;
40
48
  nonce?: string;
41
49
  } | null;
50
+ consume(): void;
42
51
  }
43
- export declare function readRedirectReturn(): RedirectReturn | null;
52
+ export interface PageReturn {
53
+ /** The page's query with every provider's return parameters taken out, for the frame. */
54
+ query: string | undefined;
55
+ found: ProviderReturn | null;
56
+ }
57
+ /**
58
+ * Reads a provider's return from the page once, at mount, and takes every registered provider's
59
+ * return parameters out of the address before anything else can see them: the frame, telemetry
60
+ * and the merchant get the merchant's own parameters only, on every path.
61
+ */
62
+ export declare function takeProviderReturn(sessionId: string | undefined): PageReturn;
44
63
  /**
45
- * Settles a redirect return against the original session: the saved continuation is consumed
46
- * and the provider's parameters leave the address, so a later mount tells nothing again. Only
47
- * a session the backend reports complete is `complete`; a failed redirect is one `decline`.
64
+ * Settles a redirect return against the original session: the continuation is consumed, so a
65
+ * later mount tells nothing again. Only a session the backend reports complete is `complete`; a
66
+ * failed redirect is one `decline` and a cancelled one one `cancel`.
48
67
  */
49
- export declare function settleRedirectReturn(redirect: RedirectReturn, context: {
68
+ export declare function settleProviderReturn(found: ProviderReturn, context: {
50
69
  apiHost: string;
51
70
  session: PaymentMethodsSession;
52
71
  status: string | undefined;
53
72
  outcomes: Outcomes;
54
73
  active: () => boolean;
55
74
  }): void;
75
+ /**
76
+ * Whether Flo's hosted card form is the session's card surface: for a 1.x answer, and for an
77
+ * advertisement that selects `hosted-card` or names no card surface at all. A `provider-frame`
78
+ * card is never served by Flo's form instead: its provider's adapter mounts it, and a provider
79
+ * the runtime has no adapter for leaves the session with no card surface, as any other method of
80
+ * such a provider is left out, rather than with a card form the API did not offer.
81
+ */
82
+ export declare function hostedCardSelected(methods: DescriptorRead | undefined): boolean;
56
83
  export interface PaymentMethodsContext {
57
84
  container: HTMLElement;
58
- /** The card frame, which stands for the `card` group. */
59
- cardNode: HTMLElement;
85
+ /** Flo's hosted card frame, which stands for the `card` group; `null` for a provider's own. */
86
+ cardNode: HTMLElement | null;
60
87
  apiHost: string;
61
88
  session: PaymentMethodsSession;
62
89
  layout: CheckoutRuntimeLayout;
@@ -72,10 +99,9 @@ export interface PaymentMethodsSurface {
72
99
  destroy(): void;
73
100
  }
74
101
  /**
75
- * Mounts the session's PayPal, wallet and alternative payment method groups in the container.
76
- * The groups appear together once their providers have loaded and the layout is known, so the
77
- * buyer never sees them jump; a provider that cannot load or says the buyer cannot use it
78
- * leaves no group, and never takes the others or the card form down.
102
+ * Mounts the session's payment methods in the container. The groups appear together once their
103
+ * providers have loaded and the layout is known, so the buyer never sees them jump; a provider
104
+ * that cannot load, says the buyer cannot use a method or has no adapter leaves no method, and
105
+ * never takes the others or the card surface down.
79
106
  */
80
107
  export declare function mountPaymentMethods(context: PaymentMethodsContext): PaymentMethodsSurface;
81
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flopay/js",
3
- "version": "1.20.8",
3
+ "version": "1.20.9",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "publishConfig": {
@@ -31,7 +31,7 @@
31
31
  "dist"
32
32
  ],
33
33
  "dependencies": {
34
- "@flopay/shared": "1.20.8",
34
+ "@flopay/shared": "1.20.9",
35
35
  "@stripe/stripe-js": "^10.3.0"
36
36
  },
37
37
  "devDependencies": {