@mainmoneyapp/js-checkout 0.0.0-stage → 0.1.5

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MainMoney SARL
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,36 @@
1
- # Temporary Holding Version
1
+ # @mainmoneyapp/js-checkout
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Headless checkout and vanilla `mountCheckout`. Import
4
+ `@mainmoneyapp/js-checkout/styles.css`. See the [root README](../../README.md).
5
+
6
+ ## Layouts
7
+
8
+ `mountCheckout(element, checkout, options)` renders:
9
+
10
+ - **`form`** (default for `operation: "deposit"`): one page with Card / Mobile money /
11
+ MainMoney tabs, optional receipt email, dial-code dropdown plus local phone number,
12
+ fee box (Merchant receives / Processing fee / You pay), provider logos for the selected
13
+ country, a Pay button, an EN/FR toggle and footer links.
14
+ - **`wizard`** (default for payouts): the step-by-step flow. Force either with `layout`.
15
+
16
+ | Option | Purpose |
17
+ | --- | --- |
18
+ | `logoUrl` | Overrides the embedded MainMoney logo. |
19
+ | `layout` | `"form"` or `"wizard"`. |
20
+ | `defaultCountry` | ISO code preselected in the form (defaults to the first allowed country). |
21
+ | `links` | `{ privacy, terms, security, help }` URLs. Links without a URL are hidden. |
22
+
23
+ ## Where the data comes from
24
+
25
+ - Tabs: `payment_methods` from `/checkout-preferences` (falls back to mobile money only).
26
+ Card and MainMoney show a "coming soon" panel and a disabled Pay button until their
27
+ backends are integrated.
28
+ - Countries, flags and provider logos: `/countries` and `/providers`, already limited to
29
+ what the merchant may use.
30
+ - Fee box: `merchant_receives`, `processing_fee` and `total_to_pay` from `/fees/simulate`.
31
+ With `fee_bearer: "CUSTOMER"` the deposit is created with `total_to_pay` as the amount.
32
+ - The phone number is sent once as `<dial code><local number>`; typing `+243...` or `0...`
33
+ is handled.
34
+
35
+ Headless API additions: `pay()`, `setMethod()`, `setLocale()`, `setCustomerEmail()` and
36
+ `canPay` / `paymentMethods` / `feeBearer` on the snapshot.
@@ -0,0 +1,176 @@
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';
3
+ import { MerchantHttp } from '@mainmoneyapp/js-http';
4
+
5
+ /** Headless checkout wizard. */
6
+
7
+ type CheckoutStep = "country" | "details" | "overview" | "confirming" | "polling" | "ongoing" | "terminal" | "error";
8
+ type BalanceCheck = {
9
+ ok: boolean;
10
+ message?: string;
11
+ };
12
+ type CreateCheckoutOptions = {
13
+ operation: OperationType;
14
+ pollStatus?: boolean;
15
+ pollUrl?: string;
16
+ pollHeaders?: Record<string, string>;
17
+ locale?: CheckoutLocale;
18
+ messages?: Partial<MessageCatalog>;
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;
25
+ reference?: string;
26
+ amount?: string;
27
+ /** Merchant fee added on top of `amount` (deposits; the merchant must be allowed to add fees). */
28
+ fees?: string;
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
+ */
35
+ currency?: string;
36
+ /** Forbid choosing another pay currency; the customer always pays in `currency`. Defaults to the session's. */
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
+ /** Polling interval; defaults to 1000 ms. */
47
+ pollIntervalMs?: number;
48
+ /** After this long without a terminal status the widget flags `slow` (default 30000 ms) but keeps polling. */
49
+ slowNoticeAfterMs?: number;
50
+ onPartnerFee?: (ctx: CheckoutSnapshot) => Promise<PartnerFee | null>;
51
+ onValidateBalance?: (ctx: CheckoutSnapshot) => Promise<BalanceCheck>;
52
+ http?: MerchantHttp;
53
+ };
54
+ type CheckoutSnapshot = {
55
+ step: CheckoutStep;
56
+ operation: OperationType;
57
+ countries: Country[];
58
+ providers: Provider[];
59
+ selectedCountry?: Country;
60
+ selectedProvider?: Provider;
61
+ highlightedProviderCode?: string;
62
+ identifier: string;
63
+ customerName: string | null;
64
+ amount: string;
65
+ lockAmount: boolean;
66
+ /** Currency of `amount` (cart currency). */
67
+ currency: string;
68
+ lockCurrency: boolean;
69
+ /** True when the host fixed the amount currency (cart currency); only `payCurrency` can change then. */
70
+ currencyFixed: boolean;
71
+ /** Currency the customer pays in; differs from `currency` only when a quote converts between them. */
72
+ payCurrency: string;
73
+ /** Currencies the selected provider accepts (what `payCurrency` can be). */
74
+ availableCurrencies: string[];
75
+ /** True when the backend has no conversion between `currency` and `payCurrency`. */
76
+ quoteUnavailable: boolean;
77
+ limits?: AmountLimit;
78
+ fees?: FeeSimulation;
79
+ partnerFee: PartnerFee | null;
80
+ locale: CheckoutLocale;
81
+ /** Tabs enabled for the merchant (from checkout preferences); defaults to mobile money only. */
82
+ paymentMethods: PaymentMethod[];
83
+ activeMethod: PaymentMethod;
84
+ feeBearer: FeeBearer;
85
+ /** Optional address for the payment receipt. */
86
+ customerEmail: string;
87
+ /** True when the form is complete enough for `pay()`. Computed on every `getState()`. */
88
+ canPay: boolean;
89
+ error?: string;
90
+ status?: StatusPayload;
91
+ /** True once polling has run longer than `slowNoticeAfterMs` without a terminal status. */
92
+ slow: boolean;
93
+ /** True while status polling cannot reach the server; polling keeps retrying until it can. */
94
+ connectionLost: boolean;
95
+ /** True once the first status poll succeeded, i.e. the status endpoint is reachable. */
96
+ pollConfirmed: boolean;
97
+ theme: CheckoutTheme;
98
+ /** Selected palette (`auto` resolves through `prefers-color-scheme` in CSS). */
99
+ colorScheme: ColorScheme;
100
+ /** `colorScheme` with `auto` resolved through `matchMedia("(prefers-color-scheme: dark)")`, kept live. */
101
+ resolvedColorScheme: "light" | "dark";
102
+ };
103
+ type Checkout = {
104
+ readonly t: (key: string, vars?: Record<string, string>) => string;
105
+ getState(): CheckoutSnapshot;
106
+ subscribe(listener: (state: CheckoutSnapshot) => void): () => void;
107
+ loadCountries(): Promise<void>;
108
+ selectCountry(code: string): Promise<void>;
109
+ selectProvider(code: string): Promise<void>;
110
+ setIdentifier(value: string): void;
111
+ setCustomerEmail(value: string): void;
112
+ setMethod(method: PaymentMethod): void;
113
+ setLocale(locale: CheckoutLocale): void;
114
+ /** Switch palette live: notifies subscribers; `mountCheckout` only flips `data-mm-theme` (no re-render, focus kept). */
115
+ setColorScheme(scheme: ColorScheme): void;
116
+ matchProvider(): Promise<void>;
117
+ setCurrency(code: string): Promise<void>;
118
+ /** After an error: start over (new session via `onRetry`, or a new attempt in place). */
119
+ retry(): Promise<void>;
120
+ setAmount(amount: string): Promise<void>;
121
+ goOverview(): Promise<void>;
122
+ goBack(): void;
123
+ /** Single-form flow: resolve the provider, run merchant hooks, then confirm without an overview step. */
124
+ pay(): Promise<void>;
125
+ confirm(): Promise<void>;
126
+ close(): void;
127
+ };
128
+ /**
129
+ * Builds `<dialCode><national>` (digits only) from whatever the customer typed:
130
+ * `812345678`, `0812345678`, `+243812345678`, `00243812345678` all yield `243812345678`.
131
+ * A dial code is only stripped when enough digits remain, so a national number that
132
+ * merely starts with the same digits is left alone.
133
+ */
134
+ declare function toE164Digits(input: string, dialCode: string): string;
135
+ declare function createCheckout(session: Session, options: CreateCheckoutOptions): Checkout;
136
+
137
+ /** Single-form checkout layout: tabs, phone with dial code, fee box, provider logos, Pay button. */
138
+
139
+ type FooterLinkKey = "privacy" | "terms" | "security" | "help";
140
+ type FooterLinks = Partial<Record<FooterLinkKey, string>>;
141
+
142
+ /** Vanilla DOM mount for the checkout wizard. */
143
+
144
+ type MountOptions = {
145
+ logoUrl?: string;
146
+ /** `form` is the single-page checkout (default for deposits); `wizard` is the step-by-step flow (default for payouts). */
147
+ layout?: "form" | "wizard";
148
+ /** Country preselected in the form layout; defaults to the first allowed country. */
149
+ defaultCountry?: string;
150
+ /** Footer links; only links with a URL are shown. */
151
+ links?: FooterLinks;
152
+ /** `embedded` removes the card chrome (surface, padding, radius, shadow) for use inside a host modal or card. */
153
+ variant?: CheckoutVariant;
154
+ };
155
+ declare function mountCheckout(element: HTMLElement, checkout: Checkout, options?: MountOptions): () => void;
156
+
157
+ /** Poll a partner status URL with injected headers only. */
158
+
159
+ type PollOptions = {
160
+ pollUrl: string;
161
+ pollHeaders: Record<string, string>;
162
+ fetchImpl: typeof fetch;
163
+ reference: string;
164
+ operation: string;
165
+ intervalMs: number;
166
+ signal?: AbortSignal;
167
+ /** Longest wait between attempts while the connection or the server is failing. Defaults to 10000 ms. */
168
+ maxBackoffMs?: number;
169
+ /** Fired when polling stops or resumes being able to reach the status endpoint (`true` = lost). */
170
+ onConnectionChange?: (lost: boolean) => void;
171
+ /** Fired after every poll that returned a decodable status. */
172
+ onResponse?: (status: StatusPayload) => void;
173
+ };
174
+ declare function pollStatus(options: PollOptions): Promise<StatusPayload>;
175
+
176
+ export { type BalanceCheck, type Checkout, type CheckoutSnapshot, type CheckoutStep, type CreateCheckoutOptions, type MountOptions, type PollOptions, createCheckout, mountCheckout, pollStatus, toE164Digits };