@orqex/checkout-js 0.0.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 +21 -0
- package/README.md +73 -0
- package/dist/chunk-4Q2JETLA.js +37 -0
- package/dist/chunk-4Q2JETLA.js.map +1 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.js +853 -0
- package/dist/index.js.map +1 -0
- package/dist/orqex.global.js +3 -0
- package/dist/orqex.global.js.map +1 -0
- package/dist/protocol.d.ts +43 -0
- package/dist/protocol.js +3 -0
- package/dist/protocol.js.map +1 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present Axa Zara LLC
|
|
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
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @orqex/checkout-js
|
|
2
|
+
|
|
3
|
+
Client-side SDK to integrate Orqex payments on your own site.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i @orqex/checkout-js
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or via CDN (UMD global `Orqex`):
|
|
12
|
+
|
|
13
|
+
```html
|
|
14
|
+
<script src="https://cdn.orqex.com/checkout-js/orqex.global.js"></script>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Your server mints a checkout with your secret key and returns its `public_id`
|
|
20
|
+
(via `@orqex/node` or `orchestrate-php`). In the browser:
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import { Orqex } from '@orqex/checkout-js';
|
|
24
|
+
|
|
25
|
+
const orqex = Orqex('pk_live_…'); // publishable key from the Orqex admin
|
|
26
|
+
|
|
27
|
+
// Embedded — hosted checkout in a sandboxed iframe (PCI stays with Orqex).
|
|
28
|
+
orqex.mount('#checkout', { publicId });
|
|
29
|
+
|
|
30
|
+
// Redirect — full-page navigation to the hosted checkout.
|
|
31
|
+
orqex.redirectToCheckout({ publicId });
|
|
32
|
+
|
|
33
|
+
// Lifecycle events (embedded mode):
|
|
34
|
+
orqex.on('success', ({ status }) => {/* … */});
|
|
35
|
+
orqex.on('error', ({ code, message }) => {/* … */});
|
|
36
|
+
orqex.on('redirect', ({ url }) => {/* the SDK also navigates top-level */});
|
|
37
|
+
orqex.on('close', ({ status }) => {/* … */});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`Orqex(pk, { checkoutBaseUrl })` overrides the hosted-checkout origin (staging
|
|
41
|
+
or self-hosted).
|
|
42
|
+
|
|
43
|
+
## Security
|
|
44
|
+
|
|
45
|
+
- Only a publishable key (`pk_…`) is accepted; never pass a secret key.
|
|
46
|
+
- The embedded iframe is `sandbox`ed and only trusts messages from the hosted
|
|
47
|
+
origin. Your site's origin must be authorised to embed your project.
|
|
48
|
+
|
|
49
|
+
## Headless
|
|
50
|
+
|
|
51
|
+
Run the engine in your own page and render your own UI from the `CheckoutView`:
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
const orqex = Orqex('pk_live_…', { apiBaseUrl: 'https://api.orqex.com' });
|
|
55
|
+
const checkout = orqex.createEngine({ publicId });
|
|
56
|
+
|
|
57
|
+
checkout.subscribe((view) => renderYourUI(view)); // view.kind: loading|form|processing|action|succeeded|failed|closed
|
|
58
|
+
await checkout.pay({ /* PayInput */ });
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Headless is for PAN-free methods (mobile money, redirect, OTP, phone-approval, QR). Raw card entry is not supported here — that is hosted (embedded/redirect) or a future hosted-fields component.
|
|
62
|
+
|
|
63
|
+
**Redirects.** When `view` is a redirect action, call `checkout.performRedirect()` (or navigate yourself). On return, re-create the engine and call `checkout.resumeFromRedirect()`. Or pass `autoResume: true` and the SDK persists `publicId` and resumes automatically:
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
const checkout = orqex.createEngine({ publicId, autoResume: true });
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`autoResume` uses `sessionStorage` and page-lifecycle events; leave it off if you manage routing yourself (SPA).
|
|
70
|
+
|
|
71
|
+
## Roadmap
|
|
72
|
+
|
|
73
|
+
- **Hosted card fields** — Phase 3, gated on demand.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
// src/protocol.ts
|
|
6
|
+
var ORQEX_PROTOCOL_VERSION = 1;
|
|
7
|
+
var KNOWN_TYPES = ["ready", "resize", "success", "error", "redirect", "close"];
|
|
8
|
+
function isEmbedMessage(data) {
|
|
9
|
+
if (data === null || typeof data !== "object") return false;
|
|
10
|
+
const record = data;
|
|
11
|
+
return record.__orqex === true && record.v === ORQEX_PROTOCOL_VERSION && typeof record.type === "string" && KNOWN_TYPES.includes(record.type);
|
|
12
|
+
}
|
|
13
|
+
function base(type) {
|
|
14
|
+
return { __orqex: true, v: ORQEX_PROTOCOL_VERSION, type };
|
|
15
|
+
}
|
|
16
|
+
function readyMessage() {
|
|
17
|
+
return base("ready");
|
|
18
|
+
}
|
|
19
|
+
function resizeMessage(height) {
|
|
20
|
+
return { ...base("resize"), height };
|
|
21
|
+
}
|
|
22
|
+
function successMessage(status) {
|
|
23
|
+
return { ...base("success"), status };
|
|
24
|
+
}
|
|
25
|
+
function errorMessage(code, message) {
|
|
26
|
+
return { ...base("error"), code, message };
|
|
27
|
+
}
|
|
28
|
+
function redirectMessage(url) {
|
|
29
|
+
return { ...base("redirect"), url };
|
|
30
|
+
}
|
|
31
|
+
function closeMessage(status) {
|
|
32
|
+
return { ...base("close"), status };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { ORQEX_PROTOCOL_VERSION, __publicField, closeMessage, errorMessage, isEmbedMessage, readyMessage, redirectMessage, resizeMessage, successMessage };
|
|
36
|
+
//# sourceMappingURL=chunk-4Q2JETLA.js.map
|
|
37
|
+
//# sourceMappingURL=chunk-4Q2JETLA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/protocol.ts"],"names":[],"mappings":";;;;;AASO,IAAM,sBAAA,GAAyB;AAqCtC,IAAM,cAA+C,CAAC,OAAA,EAAS,UAAU,SAAA,EAAW,OAAA,EAAS,YAAY,OAAO,CAAA;AAGzG,SAAS,eAAe,IAAA,EAAqC;AAClE,EAAA,IAAI,IAAA,KAAS,IAAA,IAAQ,OAAO,IAAA,KAAS,UAAU,OAAO,KAAA;AACtD,EAAA,MAAM,MAAA,GAAS,IAAA;AACf,EAAA,OACE,MAAA,CAAO,OAAA,KAAY,IAAA,IACnB,MAAA,CAAO,CAAA,KAAM,sBAAA,IACb,OAAO,MAAA,CAAO,IAAA,KAAS,QAAA,IACvB,WAAA,CAAY,QAAA,CAAS,OAAO,IAAwB,CAAA;AAExD;AAEA,SAAS,KAAiC,IAAA,EAAkB;AAE1D,EAAA,OAAO,EAAE,OAAA,EAAS,IAAA,EAAM,CAAA,EAAG,wBAAwB,IAAA,EAAK;AAC1D;AAEO,SAAS,YAAA,GAA6B;AAC3C,EAAA,OAAO,KAAK,OAAO,CAAA;AACrB;AACO,SAAS,cAAc,MAAA,EAA+B;AAC3D,EAAA,OAAO,EAAE,GAAG,IAAA,CAAK,QAAQ,GAAG,MAAA,EAAO;AACrC;AACO,SAAS,eAAe,MAAA,EAAgC;AAC7D,EAAA,OAAO,EAAE,GAAG,IAAA,CAAK,SAAS,GAAG,MAAA,EAAO;AACtC;AACO,SAAS,YAAA,CAAa,MAAc,OAAA,EAA+B;AACxE,EAAA,OAAO,EAAE,GAAG,IAAA,CAAK,OAAO,CAAA,EAAG,MAAM,OAAA,EAAQ;AAC3C;AACO,SAAS,gBAAgB,GAAA,EAA8B;AAC5D,EAAA,OAAO,EAAE,GAAG,IAAA,CAAK,UAAU,GAAG,GAAA,EAAI;AACpC;AACO,SAAS,aAAa,MAAA,EAA8B;AACzD,EAAA,OAAO,EAAE,GAAG,IAAA,CAAK,OAAO,GAAG,MAAA,EAAO;AACpC","file":"chunk-4Q2JETLA.js","sourcesContent":["/**\n * The embed postMessage protocol: the wire contract between the hosted checkout\n * (inside a sandboxed iframe) and the SDK running in the merchant's top window.\n *\n * Every message carries `__orqex: true` and `v` (version) so each side can\n * reject foreign or mis-versioned traffic. This module is the single source of\n * truth: `checkout-next` imports it to emit, `checkout-js` imports it to receive.\n */\n\nexport const ORQEX_PROTOCOL_VERSION = 1;\n\nexport type EmbedMessageType = 'ready' | 'resize' | 'success' | 'error' | 'redirect' | 'close';\n\ninterface Base<T extends EmbedMessageType> {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n __orqex: true;\n v: number;\n type: T;\n}\n\nexport type ReadyMessage = Base<'ready'>;\nexport interface ResizeMessage extends Base<'resize'> {\n height: number;\n}\nexport interface SuccessMessage extends Base<'success'> {\n status: string;\n}\nexport interface ErrorMessage extends Base<'error'> {\n code: string;\n message: string;\n}\nexport interface RedirectMessage extends Base<'redirect'> {\n url: string;\n}\nexport interface CloseMessage extends Base<'close'> {\n status: string;\n}\n\nexport type EmbedMessage =\n | ReadyMessage\n | ResizeMessage\n | SuccessMessage\n | ErrorMessage\n | RedirectMessage\n | CloseMessage;\n\nconst KNOWN_TYPES: ReadonlyArray<EmbedMessageType> = ['ready', 'resize', 'success', 'error', 'redirect', 'close'];\n\n/** Structural + version guard for messages arriving over postMessage. */\nexport function isEmbedMessage(data: unknown): data is EmbedMessage {\n if (data === null || typeof data !== 'object') return false;\n const record = data as Record<string, unknown>;\n return (\n record.__orqex === true &&\n record.v === ORQEX_PROTOCOL_VERSION &&\n typeof record.type === 'string' &&\n KNOWN_TYPES.includes(record.type as EmbedMessageType)\n );\n}\n\nfunction base<T extends EmbedMessageType>(type: T): Base<T> {\n // eslint-disable-next-line @typescript-eslint/naming-convention, id-length\n return { __orqex: true, v: ORQEX_PROTOCOL_VERSION, type };\n}\n\nexport function readyMessage(): ReadyMessage {\n return base('ready');\n}\nexport function resizeMessage(height: number): ResizeMessage {\n return { ...base('resize'), height };\n}\nexport function successMessage(status: string): SuccessMessage {\n return { ...base('success'), status };\n}\nexport function errorMessage(code: string, message: string): ErrorMessage {\n return { ...base('error'), code, message };\n}\nexport function redirectMessage(url: string): RedirectMessage {\n return { ...base('redirect'), url };\n}\nexport function closeMessage(status: string): CloseMessage {\n return { ...base('close'), status };\n}\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { CheckoutView, PayInput, AuthorizeInput, CountrySimplified } from '@orqex/checkout-engine';
|
|
2
|
+
export { AuthorizeInput, CheckoutView, CountrySimplified, PayInput } from '@orqex/checkout-engine';
|
|
3
|
+
import { EmbedMessage } from './protocol.js';
|
|
4
|
+
export { CloseMessage, EmbedMessageType, ErrorMessage, ORQEX_PROTOCOL_VERSION, ReadyMessage, RedirectMessage, ResizeMessage, SuccessMessage, closeMessage, errorMessage, isEmbedMessage, readyMessage, redirectMessage, resizeMessage, successMessage } from './protocol.js';
|
|
5
|
+
|
|
6
|
+
interface OrqexOptions {
|
|
7
|
+
/** Override the hosted-checkout origin (e.g. a staging or self-hosted deploy). */
|
|
8
|
+
checkoutBaseUrl?: string;
|
|
9
|
+
/** Override the API origin the headless engine calls (e.g. staging). */
|
|
10
|
+
apiBaseUrl?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Merchant-facing lifecycle events for embedded/redirect modes. */
|
|
14
|
+
type MerchantEvent = 'success' | 'error' | 'redirect' | 'close';
|
|
15
|
+
interface EventPayloads {
|
|
16
|
+
success: {
|
|
17
|
+
status: string;
|
|
18
|
+
};
|
|
19
|
+
error: {
|
|
20
|
+
code: string;
|
|
21
|
+
message: string;
|
|
22
|
+
};
|
|
23
|
+
redirect: {
|
|
24
|
+
url: string;
|
|
25
|
+
};
|
|
26
|
+
close: {
|
|
27
|
+
status: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface MountOptions {
|
|
32
|
+
publicId: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface CreateEngineOptions {
|
|
36
|
+
/** cs_… checkout handle minted server-side by the merchant. */
|
|
37
|
+
publicId: string;
|
|
38
|
+
/** BCP-47 locale for Accept-Language. Default navigator.language. */
|
|
39
|
+
locale?: string;
|
|
40
|
+
/**
|
|
41
|
+
* When true, the SDK persists publicId across a redirect and auto-resumes on
|
|
42
|
+
* return, and auto-performs redirect actions. Default false (fully manual).
|
|
43
|
+
*/
|
|
44
|
+
autoResume?: boolean;
|
|
45
|
+
}
|
|
46
|
+
/** Narrowed, browser-facing surface over CheckoutEngine. Cross-SDK contract. */
|
|
47
|
+
interface OrqexCheckout {
|
|
48
|
+
subscribe(fn: (view: CheckoutView) => void): () => void;
|
|
49
|
+
getView(): CheckoutView;
|
|
50
|
+
pay(input: PayInput): Promise<void>;
|
|
51
|
+
authorize(input: AuthorizeInput): Promise<void>;
|
|
52
|
+
poll(): Promise<void>;
|
|
53
|
+
selectCountry(country: string): Promise<void>;
|
|
54
|
+
selectCurrency(currency: string): Promise<void>;
|
|
55
|
+
listCountries(): Promise<CountrySimplified[]>;
|
|
56
|
+
/** Poll the current server state (call on return from an external redirect). */
|
|
57
|
+
resumeFromRedirect(): Promise<void>;
|
|
58
|
+
startPolling(): void;
|
|
59
|
+
stopPolling(): void;
|
|
60
|
+
/** Perform the pending redirect action; no-op if the current view is not one. */
|
|
61
|
+
performRedirect(): void;
|
|
62
|
+
destroy(): void;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface RedirectOptions {
|
|
66
|
+
/** cs_… checkout handle minted server-side by the merchant. */
|
|
67
|
+
publicId: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface OrqexInstance {
|
|
71
|
+
/** Embedded mode: hosted checkout in a sandboxed iframe. */
|
|
72
|
+
mount(target: string | HTMLElement, options: MountOptions): void;
|
|
73
|
+
/** Redirect mode: full-page navigation to the hosted checkout. */
|
|
74
|
+
redirectToCheckout(options: RedirectOptions): void;
|
|
75
|
+
/** Subscribe to a lifecycle event; returns a disposer. */
|
|
76
|
+
on<TEvent extends MerchantEvent>(event: TEvent, handler: (payload: EventPayloads[TEvent]) => void): () => void;
|
|
77
|
+
/** Tear down the embedded iframe and its listener (no-op in redirect mode). */
|
|
78
|
+
unmount(): void;
|
|
79
|
+
/** Headless mode: run the engine in this page and render your own UI. */
|
|
80
|
+
createEngine(options: CreateEngineOptions): OrqexCheckout;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* SDK entry point. `Orqex('pk_…')` validates the key, then exposes embedded,
|
|
84
|
+
* redirect, and headless (`createEngine`) modes over one event bus.
|
|
85
|
+
*/
|
|
86
|
+
declare function Orqex(publishableKey: string, options?: OrqexOptions): OrqexInstance;
|
|
87
|
+
|
|
88
|
+
interface EmbedProjection {
|
|
89
|
+
message: EmbedMessage;
|
|
90
|
+
/** Dedup key so the host posts each terminal state at most once. */
|
|
91
|
+
key: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Pure mapping from the engine's projected view to an embed lifecycle message.
|
|
95
|
+
* Terminal views only; `redirect` is handled by the host's redirect override
|
|
96
|
+
* (a redirect action is not a terminal view). Returns null when there is
|
|
97
|
+
* nothing new to post or `key` equals `lastKey`.
|
|
98
|
+
*/
|
|
99
|
+
declare function projectEmbedMessage(view: CheckoutView, lastKey: string | null): EmbedProjection | null;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @orqex/checkout-js — client-side SDK for Orqex payments.
|
|
103
|
+
*
|
|
104
|
+
* Browser-host glue over the existing engine + hosted checkout. Never accepts a
|
|
105
|
+
* secret key; the publishable key (pk_) is public by design.
|
|
106
|
+
*/
|
|
107
|
+
declare const SDK_VERSION = "0.0.1";
|
|
108
|
+
|
|
109
|
+
export { type CreateEngineOptions, EmbedMessage, type EmbedProjection, type EventPayloads, type MerchantEvent, type MountOptions, Orqex, type OrqexCheckout, type OrqexInstance, type OrqexOptions, type RedirectOptions, SDK_VERSION, projectEmbedMessage };
|