@mmpay/browser 0.0.0-stage → 1.3.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/.vscode/settings.json +33 -0
- package/README.md +489 -2
- package/dist/cjs/index.js +1770 -0
- package/dist/esm/api.d.ts +26 -0
- package/dist/esm/deprecated/api.d.ts +12 -0
- package/dist/esm/deprecated/showPaymentModal.d.ts +6 -0
- package/dist/esm/functions/api.d.ts +12 -0
- package/dist/esm/functions/showPaymentModal.d.ts +2 -0
- package/dist/esm/i18n.d.ts +13 -0
- package/dist/esm/index.d.ts +65 -0
- package/dist/esm/index.js +1768 -0
- package/dist/esm/logo.d.ts +5 -0
- package/dist/esm/stream.d.ts +46 -0
- package/dist/esm/styles.d.ts +5 -0
- package/dist/esm/templates.d.ts +6 -0
- package/dist/esm/types.d.ts +101 -0
- package/dist/esm/ui.d.ts +85 -0
- package/dist/mmpay-sdk.js +1776 -0
- package/package.json +45 -4
- package/rollup.config.ts +33 -0
- package/src/api.ts +121 -0
- package/src/i18n.ts +112 -0
- package/src/index.ts +490 -0
- package/src/logo.ts +5 -0
- package/src/stream.ts +214 -0
- package/src/styles.ts +206 -0
- package/src/types.ts +117 -0
- package/src/ui.ts +715 -0
- package/test/index.html +476 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ICancelPaymentRequestParams, ICancelPaymentResponse, ICreatePaymentRequestParams, ICreatePaymentResponse, ICreateTokenRequestParams, ICreateTokenResponse, IPaymentShowRequestParams, IPaymentShowResponse, IPollingRequest, IPollingResponse, IStreamTicketResponse } from './types';
|
|
2
|
+
export declare class MMPayApiError extends Error {
|
|
3
|
+
status: number;
|
|
4
|
+
constructor(message: string, status: number);
|
|
5
|
+
}
|
|
6
|
+
export declare class MMPayAPI {
|
|
7
|
+
private baseUrl;
|
|
8
|
+
private environment;
|
|
9
|
+
private publishableKey;
|
|
10
|
+
private tokenKey;
|
|
11
|
+
constructor(baseUrl: string, environment: 'sandbox' | 'production', publishableKey: string);
|
|
12
|
+
setToken(token: string | null): void;
|
|
13
|
+
getToken(): string | null;
|
|
14
|
+
private call;
|
|
15
|
+
createToken(payload: ICreateTokenRequestParams): Promise<ICreateTokenResponse>;
|
|
16
|
+
showPayment(payload: IPaymentShowRequestParams): Promise<IPaymentShowResponse>;
|
|
17
|
+
cancelPayment(payload: ICancelPaymentRequestParams): Promise<ICancelPaymentResponse>;
|
|
18
|
+
createPayment(payload: ICreatePaymentRequestParams): Promise<ICreatePaymentResponse>;
|
|
19
|
+
pollPayment(payload: IPollingRequest): Promise<IPollingResponse>;
|
|
20
|
+
/**
|
|
21
|
+
* A WebSocket handshake cannot carry the publishable key or session token,
|
|
22
|
+
* so the authenticated API issues a short-lived, single-use ticket for it.
|
|
23
|
+
*/
|
|
24
|
+
createStreamTicket(payload: IPollingRequest): Promise<IStreamTicketResponse>;
|
|
25
|
+
getStreamUrl(ticket: string): string;
|
|
26
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ICreatePaymentRequestParams, ICreatePaymentResponse, ICreateTokenRequestParams, ICreateTokenResponse } from '../types';
|
|
2
|
+
export declare class DeprecatedMMPayAPI {
|
|
3
|
+
private baseUrl;
|
|
4
|
+
private environment;
|
|
5
|
+
private publishableKey;
|
|
6
|
+
private tokenKey;
|
|
7
|
+
constructor(environment: 'sandbox' | 'production', publishableKey: string);
|
|
8
|
+
setToken(token: string | null): void;
|
|
9
|
+
private call;
|
|
10
|
+
createToken(payload: ICreateTokenRequestParams): Promise<ICreateTokenResponse>;
|
|
11
|
+
createPayment(payload: ICreatePaymentRequestParams): Promise<ICreatePaymentResponse>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ICreatePaymentRequestParams, IModalEventResult } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated This method is deprecated. Please migrate to the .pay() method.
|
|
4
|
+
*/
|
|
5
|
+
export declare function legacyShowPaymentModal(this: any, // Binds the parent MMPaySDK instance context
|
|
6
|
+
params: ICreatePaymentRequestParams, onComplete: (result: IModalEventResult) => void): Promise<void>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ICreatePaymentRequestParams, ICreatePaymentResponse, ICreateTokenRequestParams, ICreateTokenResponse } from '../types';
|
|
2
|
+
export declare class XMMPayAPI {
|
|
3
|
+
private baseUrl;
|
|
4
|
+
private environment;
|
|
5
|
+
private publishableKey;
|
|
6
|
+
private tokenKey;
|
|
7
|
+
constructor(environment: 'sandbox' | 'production', publishableKey: string);
|
|
8
|
+
setToken(token: string | null): void;
|
|
9
|
+
private call;
|
|
10
|
+
createToken(payload: ICreateTokenRequestParams): Promise<ICreateTokenResponse>;
|
|
11
|
+
createPayment(payload: ICreatePaymentRequestParams): Promise<ICreatePaymentResponse>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MMPayLanguage } from './types';
|
|
2
|
+
export declare function normalizeLanguage(value: unknown): MMPayLanguage | null;
|
|
3
|
+
/**
|
|
4
|
+
* A missing translation falls back to English so a screen can never render
|
|
5
|
+
* blank text, whichever language is selected.
|
|
6
|
+
*/
|
|
7
|
+
export declare function translate(language: MMPayLanguage, key: string, params?: Record<string, string>): string;
|
|
8
|
+
/**
|
|
9
|
+
* The shopper's own choice wins, then the merchant's configured language, then
|
|
10
|
+
* the browser language.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveInitialLanguage(preferred?: string): MMPayLanguage;
|
|
13
|
+
export declare function rememberLanguage(language: MMPayLanguage): void;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { MMPayAPI } from './api';
|
|
2
|
+
import { ICreatePaymentRequestParams, IModalEventResult, IPollingRequest, MMPayLanguage, SDKOptions } from './types';
|
|
3
|
+
import { MMPayUI, MMPayUIHandlers } from './ui';
|
|
4
|
+
export declare class MMPaySDK {
|
|
5
|
+
private POLL_INTERVAL_MS;
|
|
6
|
+
private TIMEOUT_SECONDS;
|
|
7
|
+
private readonly CACHE_KEY;
|
|
8
|
+
private environment;
|
|
9
|
+
private transport;
|
|
10
|
+
protected merchantName: string;
|
|
11
|
+
private onCompleteCallback;
|
|
12
|
+
private statusWatcher;
|
|
13
|
+
private countdownIntervalId;
|
|
14
|
+
private pendingApiResponse;
|
|
15
|
+
private pendingPaymentPayload;
|
|
16
|
+
private flowId;
|
|
17
|
+
private settled;
|
|
18
|
+
private cancelling;
|
|
19
|
+
private creating;
|
|
20
|
+
protected api: MMPayAPI;
|
|
21
|
+
protected ui: MMPayUI;
|
|
22
|
+
constructor(publishableKey: string, options?: SDKOptions);
|
|
23
|
+
/**
|
|
24
|
+
* Switches the modal language. Works at any time, including while a payment
|
|
25
|
+
* is on screen, and is remembered for the shopper's next visit.
|
|
26
|
+
*/
|
|
27
|
+
setLanguage(language: MMPayLanguage | 'my'): void;
|
|
28
|
+
getLanguage(): MMPayLanguage;
|
|
29
|
+
showPaymentModal(params: ICreatePaymentRequestParams, onComplete: (result: IModalEventResult) => void): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Spam guard: while the shopper has an order that is not paid, cancelled or
|
|
32
|
+
* expired, a new one is not created. The unfinished order is shown again
|
|
33
|
+
* instead. The server is asked first, so an order that finished in the
|
|
34
|
+
* meantime does not block a new one.
|
|
35
|
+
*/
|
|
36
|
+
private _showUnfinishedOrder;
|
|
37
|
+
pay(orderId: string, onComplete: (result: IModalEventResult) => void): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Starts a fresh flow. Anything still running from an earlier call is
|
|
40
|
+
* stopped, and its late responses are ignored through `flowId`.
|
|
41
|
+
*/
|
|
42
|
+
private _beginFlow;
|
|
43
|
+
/** Keeps the loading state up briefly so a fast response does not flicker. */
|
|
44
|
+
private _holdLoading;
|
|
45
|
+
private _showQr;
|
|
46
|
+
private _failFlow;
|
|
47
|
+
/**
|
|
48
|
+
* Single exit for every finished payment, whichever source reported it
|
|
49
|
+
* first (socket, polling or the countdown), so the result screen and the
|
|
50
|
+
* merchant callback fire exactly once.
|
|
51
|
+
*/
|
|
52
|
+
private _finish;
|
|
53
|
+
protected _getUiHandlers(): MMPayUIHandlers;
|
|
54
|
+
private _cancelPendingPayment;
|
|
55
|
+
protected _triggerEvent(eventData: IModalEventResult): void;
|
|
56
|
+
private _stopTimers;
|
|
57
|
+
protected _cleanup(): void;
|
|
58
|
+
protected _clearCache(): void;
|
|
59
|
+
private _readCache;
|
|
60
|
+
private _writeCache;
|
|
61
|
+
private _checkAndAutoResume;
|
|
62
|
+
private _resumePaymentState;
|
|
63
|
+
protected _startStatusWatch(payload: IPollingRequest): void;
|
|
64
|
+
protected _startCountdown(orderId: string, expireAt: number): void;
|
|
65
|
+
}
|