@mainmoneyapp/js-checkout 0.1.1 → 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
@@ -1,9 +1,10 @@
1
- import { OperationType, Country, Provider, AmountLimit, FeeSimulation, PartnerFee, CheckoutLocale, PaymentMethod, FeeBearer, StatusPayload, CheckoutTheme, MessageCatalog, Session } from '@mainmoneyapp/js-core';
1
+ import { OperationType, Country, Provider, AmountLimit, FeeSimulation, PartnerFee, CheckoutLocale, PaymentMethod, FeeBearer, StatusPayload, CheckoutTheme, ColorScheme, MessageCatalog, ColorSchemeSource, Session, CheckoutVariant } from '@mainmoneyapp/js-core';
2
+ export { CheckoutVariant, ColorScheme, ColorSchemeSource } from '@mainmoneyapp/js-core';
2
3
  import { MerchantHttp } from '@mainmoneyapp/js-http';
3
4
 
4
5
  /** Headless checkout wizard. */
5
6
 
6
- type CheckoutStep = "country" | "details" | "overview" | "confirming" | "polling" | "ongoing" | "terminal";
7
+ type CheckoutStep = "country" | "details" | "overview" | "confirming" | "polling" | "ongoing" | "terminal" | "error";
7
8
  type BalanceCheck = {
8
9
  ok: boolean;
9
10
  message?: string;
@@ -16,14 +17,43 @@ type CreateCheckoutOptions = {
16
17
  locale?: CheckoutLocale;
17
18
  messages?: Partial<MessageCatalog>;
18
19
  theme?: Partial<CheckoutTheme>;
20
+ /**
21
+ * `light`, `dark` or `auto` (default: follows `prefers-color-scheme` live). May also be a host-owned signal
22
+ * (`{ get, subscribe }`); the widget follows it until `close()`.
23
+ */
24
+ colorScheme?: ColorScheme | ColorSchemeSource;
19
25
  reference?: string;
20
26
  amount?: string;
21
27
  /** Merchant fee added on top of `amount` (deposits; the merchant must be allowed to add fees). */
22
28
  fees?: string;
23
29
  lockAmount?: boolean;
30
+ /**
31
+ * Currency of `amount` (the cart/order currency). When set it never changes: a provider that accepts
32
+ * other currencies only changes the currency the customer pays in (`payCurrency`), through a quote.
33
+ * Defaults to the `currency` given to `createSession`.
34
+ */
24
35
  currency?: string;
36
+ /** Forbid choosing another pay currency; the customer always pays in `currency`. Defaults to the session's. */
25
37
  lockCurrency?: boolean;
38
+ /** Pre-fills the optional receipt address; the customer can still change it. */
39
+ customerEmail?: string;
40
+ /**
41
+ * Called when the customer presses Retry after a failed payment. Hosts that bind a payment to a server
42
+ * session (cart plugins) start a new session here. Without it the widget retries in place with a new
43
+ * reference and Idempotency-Key suffix.
44
+ */
45
+ onRetry?: () => void | Promise<void>;
46
+ /**
47
+ * Also send the reference as an `Idempotency-Key` header on deposits and payouts. Off by default: a custom header
48
+ * makes the browser preflight list it in `Access-Control-Allow-Headers`, and a merchant backend that does not
49
+ * allow it fails every payment with a CORS error. The `reference` in the body already makes the call idempotent;
50
+ * turn this on only when your backend allows the header (or forwards it to the aggregator).
51
+ */
52
+ idempotencyHeader?: boolean;
53
+ /** Polling interval; defaults to 1000 ms. */
26
54
  pollIntervalMs?: number;
55
+ /** After this long without a terminal status the widget flags `slow` (default 30000 ms) but keeps polling. */
56
+ slowNoticeAfterMs?: number;
27
57
  onPartnerFee?: (ctx: CheckoutSnapshot) => Promise<PartnerFee | null>;
28
58
  onValidateBalance?: (ctx: CheckoutSnapshot) => Promise<BalanceCheck>;
29
59
  http?: MerchantHttp;
@@ -40,9 +70,17 @@ type CheckoutSnapshot = {
40
70
  customerName: string | null;
41
71
  amount: string;
42
72
  lockAmount: boolean;
73
+ /** Currency of `amount` (cart currency). */
43
74
  currency: string;
44
75
  lockCurrency: boolean;
76
+ /** True when the host fixed the amount currency (cart currency); only `payCurrency` can change then. */
77
+ currencyFixed: boolean;
78
+ /** Currency the customer pays in; differs from `currency` only when a quote converts between them. */
79
+ payCurrency: string;
80
+ /** Currencies the selected provider accepts (what `payCurrency` can be). */
45
81
  availableCurrencies: string[];
82
+ /** True when the backend has no conversion between `currency` and `payCurrency`. */
83
+ quoteUnavailable: boolean;
46
84
  limits?: AmountLimit;
47
85
  fees?: FeeSimulation;
48
86
  partnerFee: PartnerFee | null;
@@ -57,7 +95,17 @@ type CheckoutSnapshot = {
57
95
  canPay: boolean;
58
96
  error?: string;
59
97
  status?: StatusPayload;
98
+ /** True once polling has run longer than `slowNoticeAfterMs` without a terminal status. */
99
+ slow: boolean;
100
+ /** True while status polling cannot reach the server; polling keeps retrying until it can. */
101
+ connectionLost: boolean;
102
+ /** True once the first status poll succeeded, i.e. the status endpoint is reachable. */
103
+ pollConfirmed: boolean;
60
104
  theme: CheckoutTheme;
105
+ /** Selected palette (`auto` resolves through `prefers-color-scheme` in CSS). */
106
+ colorScheme: ColorScheme;
107
+ /** `colorScheme` with `auto` resolved through `matchMedia("(prefers-color-scheme: dark)")`, kept live. */
108
+ resolvedColorScheme: "light" | "dark";
61
109
  };
62
110
  type Checkout = {
63
111
  readonly t: (key: string, vars?: Record<string, string>) => string;
@@ -70,8 +118,12 @@ type Checkout = {
70
118
  setCustomerEmail(value: string): void;
71
119
  setMethod(method: PaymentMethod): void;
72
120
  setLocale(locale: CheckoutLocale): void;
121
+ /** Switch palette live: notifies subscribers; `mountCheckout` only flips `data-mm-theme` (no re-render, focus kept). */
122
+ setColorScheme(scheme: ColorScheme): void;
73
123
  matchProvider(): Promise<void>;
74
124
  setCurrency(code: string): Promise<void>;
125
+ /** After an error: start over (new session via `onRetry`, or a new attempt in place). */
126
+ retry(): Promise<void>;
75
127
  setAmount(amount: string): Promise<void>;
76
128
  goOverview(): Promise<void>;
77
129
  goBack(): void;
@@ -104,6 +156,8 @@ type MountOptions = {
104
156
  defaultCountry?: string;
105
157
  /** Footer links; only links with a URL are shown. */
106
158
  links?: FooterLinks;
159
+ /** `embedded` removes the card chrome (surface, padding, radius, shadow) for use inside a host modal or card. */
160
+ variant?: CheckoutVariant;
107
161
  };
108
162
  declare function mountCheckout(element: HTMLElement, checkout: Checkout, options?: MountOptions): () => void;
109
163
 
@@ -117,6 +171,12 @@ type PollOptions = {
117
171
  operation: string;
118
172
  intervalMs: number;
119
173
  signal?: AbortSignal;
174
+ /** Longest wait between attempts while the connection or the server is failing. Defaults to 10000 ms. */
175
+ maxBackoffMs?: number;
176
+ /** Fired when polling stops or resumes being able to reach the status endpoint (`true` = lost). */
177
+ onConnectionChange?: (lost: boolean) => void;
178
+ /** Fired after every poll that returned a decodable status. */
179
+ onResponse?: (status: StatusPayload) => void;
120
180
  };
121
181
  declare function pollStatus(options: PollOptions): Promise<StatusPayload>;
122
182