@mainmoneyapp/js-checkout 0.0.0-stage → 0.1.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/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,123 @@
1
+ import { OperationType, Country, Provider, AmountLimit, FeeSimulation, PartnerFee, CheckoutLocale, PaymentMethod, FeeBearer, StatusPayload, CheckoutTheme, MessageCatalog, Session } from '@mainmoneyapp/js-core';
2
+ import { MerchantHttp } from '@mainmoneyapp/js-http';
3
+
4
+ /** Headless checkout wizard. */
5
+
6
+ type CheckoutStep = "country" | "details" | "overview" | "confirming" | "polling" | "ongoing" | "terminal";
7
+ type BalanceCheck = {
8
+ ok: boolean;
9
+ message?: string;
10
+ };
11
+ type CreateCheckoutOptions = {
12
+ operation: OperationType;
13
+ pollStatus?: boolean;
14
+ pollUrl?: string;
15
+ pollHeaders?: Record<string, string>;
16
+ locale?: CheckoutLocale;
17
+ messages?: Partial<MessageCatalog>;
18
+ theme?: Partial<CheckoutTheme>;
19
+ reference?: string;
20
+ amount?: string;
21
+ /** Merchant fee added on top of `amount` (deposits; the merchant must be allowed to add fees). */
22
+ fees?: string;
23
+ lockAmount?: boolean;
24
+ currency?: string;
25
+ lockCurrency?: boolean;
26
+ pollIntervalMs?: number;
27
+ onPartnerFee?: (ctx: CheckoutSnapshot) => Promise<PartnerFee | null>;
28
+ onValidateBalance?: (ctx: CheckoutSnapshot) => Promise<BalanceCheck>;
29
+ http?: MerchantHttp;
30
+ };
31
+ type CheckoutSnapshot = {
32
+ step: CheckoutStep;
33
+ operation: OperationType;
34
+ countries: Country[];
35
+ providers: Provider[];
36
+ selectedCountry?: Country;
37
+ selectedProvider?: Provider;
38
+ highlightedProviderCode?: string;
39
+ identifier: string;
40
+ customerName: string | null;
41
+ amount: string;
42
+ lockAmount: boolean;
43
+ currency: string;
44
+ lockCurrency: boolean;
45
+ availableCurrencies: string[];
46
+ limits?: AmountLimit;
47
+ fees?: FeeSimulation;
48
+ partnerFee: PartnerFee | null;
49
+ locale: CheckoutLocale;
50
+ /** Tabs enabled for the merchant (from checkout preferences); defaults to mobile money only. */
51
+ paymentMethods: PaymentMethod[];
52
+ activeMethod: PaymentMethod;
53
+ feeBearer: FeeBearer;
54
+ /** Optional address for the payment receipt. */
55
+ customerEmail: string;
56
+ /** True when the form is complete enough for `pay()`. Computed on every `getState()`. */
57
+ canPay: boolean;
58
+ error?: string;
59
+ status?: StatusPayload;
60
+ theme: CheckoutTheme;
61
+ };
62
+ type Checkout = {
63
+ readonly t: (key: string, vars?: Record<string, string>) => string;
64
+ getState(): CheckoutSnapshot;
65
+ subscribe(listener: (state: CheckoutSnapshot) => void): () => void;
66
+ loadCountries(): Promise<void>;
67
+ selectCountry(code: string): Promise<void>;
68
+ selectProvider(code: string): Promise<void>;
69
+ setIdentifier(value: string): void;
70
+ setCustomerEmail(value: string): void;
71
+ setMethod(method: PaymentMethod): void;
72
+ setLocale(locale: CheckoutLocale): void;
73
+ matchProvider(): Promise<void>;
74
+ setCurrency(code: string): Promise<void>;
75
+ setAmount(amount: string): Promise<void>;
76
+ goOverview(): Promise<void>;
77
+ goBack(): void;
78
+ /** Single-form flow: resolve the provider, run merchant hooks, then confirm without an overview step. */
79
+ pay(): Promise<void>;
80
+ confirm(): Promise<void>;
81
+ close(): void;
82
+ };
83
+ /**
84
+ * Builds `<dialCode><national>` (digits only) from whatever the customer typed:
85
+ * `812345678`, `0812345678`, `+243812345678`, `00243812345678` all yield `243812345678`.
86
+ * A dial code is only stripped when enough digits remain, so a national number that
87
+ * merely starts with the same digits is left alone.
88
+ */
89
+ declare function toE164Digits(input: string, dialCode: string): string;
90
+ declare function createCheckout(session: Session, options: CreateCheckoutOptions): Checkout;
91
+
92
+ /** Single-form checkout layout: tabs, phone with dial code, fee box, provider logos, Pay button. */
93
+
94
+ type FooterLinkKey = "privacy" | "terms" | "security" | "help";
95
+ type FooterLinks = Partial<Record<FooterLinkKey, string>>;
96
+
97
+ /** Vanilla DOM mount for the checkout wizard. */
98
+
99
+ type MountOptions = {
100
+ logoUrl?: string;
101
+ /** `form` is the single-page checkout (default for deposits); `wizard` is the step-by-step flow (default for payouts). */
102
+ layout?: "form" | "wizard";
103
+ /** Country preselected in the form layout; defaults to the first allowed country. */
104
+ defaultCountry?: string;
105
+ /** Footer links; only links with a URL are shown. */
106
+ links?: FooterLinks;
107
+ };
108
+ declare function mountCheckout(element: HTMLElement, checkout: Checkout, options?: MountOptions): () => void;
109
+
110
+ /** Poll a partner status URL with injected headers only. */
111
+
112
+ type PollOptions = {
113
+ pollUrl: string;
114
+ pollHeaders: Record<string, string>;
115
+ fetchImpl: typeof fetch;
116
+ reference: string;
117
+ operation: string;
118
+ intervalMs: number;
119
+ signal?: AbortSignal;
120
+ };
121
+ declare function pollStatus(options: PollOptions): Promise<StatusPayload>;
122
+
123
+ export { type BalanceCheck, type Checkout, type CheckoutSnapshot, type CheckoutStep, type CreateCheckoutOptions, type MountOptions, type PollOptions, createCheckout, mountCheckout, pollStatus, toE164Digits };