@integralscope/command-transfer-checkout-js 0.1.4 → 0.1.7-dev.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/README.md +96 -16
- package/dist/commandtransfer-checkout.js +17 -19
- package/dist/commandtransfer-checkout.umd.cjs +1 -1
- package/dist/constants.d.ts +7 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/iframe/IframeManager.d.ts.map +1 -1
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/url.d.ts +13 -1
- package/dist/url.d.ts.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ Your site never talks to the pay UI as source code. The SDK only opens Command T
|
|
|
33
33
|
|
|
34
34
|
## 1. Create the checkout on your server
|
|
35
35
|
|
|
36
|
-
When the customer is ready to pay, your backend creates a checkout
|
|
36
|
+
When the customer is ready to pay, your backend creates a checkout. This browser SDK never calls that API. Return only the public session to the browser:
|
|
37
37
|
|
|
38
38
|
```json
|
|
39
39
|
{
|
|
@@ -42,26 +42,54 @@ When the customer is ready to pay, your backend creates a checkout with your **s
|
|
|
42
42
|
}
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
Do not put the secret key in frontend env, HTML, or
|
|
45
|
+
Do not put the secret key in frontend env, HTML, or this package.
|
|
46
|
+
|
|
47
|
+
Development API (Command Transfer staging):
|
|
48
|
+
|
|
49
|
+
- Base URL: `https://ct-dev-api-482193062708.us-central1.run.app`
|
|
50
|
+
- Spec: [Swagger](https://ct-dev-api-482193062708.us-central1.run.app/swagger/index.html#/)
|
|
51
|
+
|
|
52
|
+
`POST /v1/checkout` requires `Authorization: Bearer sk_…` and `Idempotency-Key`. Amounts are **minor units**.
|
|
46
53
|
|
|
47
54
|
Example merchant endpoint:
|
|
48
55
|
|
|
49
56
|
```js
|
|
50
|
-
// server
|
|
57
|
+
// server only — never ship sk_ to the browser
|
|
58
|
+
const CT_API = process.env.COMMAND_TRANSFER_API_ORIGIN;
|
|
59
|
+
const CT_SECRET = process.env.COMMAND_TRANSFER_SECRET_KEY;
|
|
60
|
+
|
|
51
61
|
app.post("/api/checkout", async (req, res) => {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
const response = await fetch(`${CT_API}/v1/checkout`, {
|
|
63
|
+
method: "POST",
|
|
64
|
+
headers: {
|
|
65
|
+
Authorization: `Bearer ${CT_SECRET}`,
|
|
66
|
+
"Content-Type": "application/json",
|
|
67
|
+
"Idempotency-Key": crypto.randomUUID(),
|
|
68
|
+
},
|
|
69
|
+
body: JSON.stringify({
|
|
70
|
+
amount: 450000,
|
|
71
|
+
currency: "NGN",
|
|
72
|
+
customer_email: req.body.email,
|
|
73
|
+
reference: req.body.orderId,
|
|
74
|
+
}),
|
|
56
75
|
});
|
|
57
76
|
|
|
77
|
+
if (!response.ok) {
|
|
78
|
+
res.status(502).json({ error: "checkout_create_failed" });
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const session = await response.json();
|
|
83
|
+
|
|
58
84
|
res.json({
|
|
59
|
-
intentId: session.id,
|
|
85
|
+
intentId: session.intent.id,
|
|
60
86
|
clientToken: session.client_token,
|
|
61
87
|
});
|
|
62
88
|
});
|
|
63
89
|
```
|
|
64
90
|
|
|
91
|
+
Store `COMMAND_TRANSFER_SECRET_KEY` only on the server. Do not log `client_token`.
|
|
92
|
+
|
|
65
93
|
The browser then:
|
|
66
94
|
|
|
67
95
|
```js
|
|
@@ -76,6 +104,19 @@ const session = await fetch("/api/checkout", { method: "POST" }).then((r) =>
|
|
|
76
104
|
npm install @integralscope/command-transfer-checkout-js
|
|
77
105
|
```
|
|
78
106
|
|
|
107
|
+
### Release channels
|
|
108
|
+
|
|
109
|
+
| Channel | Install | What it is |
|
|
110
|
+
| -------- | ------- | ---------- |
|
|
111
|
+
| `latest` | `npm i @integralscope/command-transfer-checkout-js` | Released versions. What merchants should use. |
|
|
112
|
+
| `dev` | `npm i @integralscope/command-transfer-checkout-js@dev` | Every push to `main`, published as `X.Y.Z-dev.N`. Internal testing only. |
|
|
113
|
+
|
|
114
|
+
A prerelease version never satisfies a `^` or `~` range, so a plain install can
|
|
115
|
+
never resolve to a `dev` build — you have to ask for it by name.
|
|
116
|
+
|
|
117
|
+
There is one branch, `main`, and work on it is not a release. **Tagging `v*` is
|
|
118
|
+
what promotes a commit to production** and the only thing that moves `latest`.
|
|
119
|
+
|
|
79
120
|
Or a script tag:
|
|
80
121
|
|
|
81
122
|
```html
|
|
@@ -109,7 +150,7 @@ checkout.on("error", ({ code, message }) => {
|
|
|
109
150
|
});
|
|
110
151
|
```
|
|
111
152
|
|
|
112
|
-
The SDK opens Checkout Web
|
|
153
|
+
The SDK opens Checkout Web, where the customer pays by card or bank transfer. Do not collect card details on your site or send them through this SDK.
|
|
113
154
|
|
|
114
155
|
### Inline
|
|
115
156
|
|
|
@@ -153,7 +194,7 @@ On completion they land on `returnUrl` with query params:
|
|
|
153
194
|
|
|
154
195
|
| Param | Meaning |
|
|
155
196
|
| -------------- | -------------------------------------------- |
|
|
156
|
-
| `checkout_id` | The checkout you created |
|
|
197
|
+
| `checkout_id` | The checkout you have created |
|
|
157
198
|
| `reference` | Present when payment succeeded |
|
|
158
199
|
| `status` | `success` or an error code |
|
|
159
200
|
|
|
@@ -196,9 +237,9 @@ If the customer had not finished paying, this emits `cancel`.
|
|
|
196
237
|
After `success` or a redirect return:
|
|
197
238
|
|
|
198
239
|
1. Send `intentId` to your backend.
|
|
199
|
-
2.
|
|
200
|
-
3. Fulfill only when status is `SUCCEEDED`.
|
|
201
|
-
4. Ignore a
|
|
240
|
+
2. Your server calls `GET /v1/checkout/{intentID}` with `Authorization: Bearer sk_…`.
|
|
241
|
+
3. Fulfill only when `intent.status` is `SUCCEEDED`.
|
|
242
|
+
4. Ignore a browser `success` event that your API does not confirm.
|
|
202
243
|
|
|
203
244
|
```js
|
|
204
245
|
checkout.on("success", async ({ intentId }) => {
|
|
@@ -214,6 +255,18 @@ checkout.on("success", async ({ intentId }) => {
|
|
|
214
255
|
});
|
|
215
256
|
```
|
|
216
257
|
|
|
258
|
+
Server confirm (same secret, never from this SDK):
|
|
259
|
+
|
|
260
|
+
```js
|
|
261
|
+
const response = await fetch(`${CT_API}/v1/checkout/${intentId}`, {
|
|
262
|
+
headers: { Authorization: `Bearer ${CT_SECRET}` },
|
|
263
|
+
});
|
|
264
|
+
const checkout = await response.json();
|
|
265
|
+
const paid = checkout.intent?.status === "SUCCEEDED";
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Do not call `/v1/checkout/.../client` or card-attempt routes from the merchant page. Those use the payer `ctc_…` token and belong on Command Transfer Checkout Web, not in this SDK.
|
|
269
|
+
|
|
217
270
|
## Config
|
|
218
271
|
|
|
219
272
|
| Field | Required | Notes |
|
|
@@ -223,6 +276,7 @@ checkout.on("success", async ({ intentId }) => {
|
|
|
223
276
|
| `mode` | no | `inline` (default), `modal`, or `redirect` |
|
|
224
277
|
| `container` | no | Used by `start()` when `mode` is `inline` |
|
|
225
278
|
| `returnUrl` | no | Redirect return URL. Ignored for inline/modal. |
|
|
279
|
+
| `checkoutOrigin` | no | Override the hosted checkout origin. Defaults to production — see below. |
|
|
226
280
|
|
|
227
281
|
## Events
|
|
228
282
|
|
|
@@ -235,7 +289,9 @@ checkout.on("success", async ({ intentId }) => {
|
|
|
235
289
|
|
|
236
290
|
## Checkout origin
|
|
237
291
|
|
|
238
|
-
Merchants do not pass a checkout URL.
|
|
292
|
+
Merchants do not pass a checkout URL. Every published build of this SDK — stable
|
|
293
|
+
and prerelease alike — bakes in Command Transfer’s **production** Checkout Web
|
|
294
|
+
origin, so the normal case needs no configuration:
|
|
239
295
|
|
|
240
296
|
```js
|
|
241
297
|
new Checkout({
|
|
@@ -246,9 +302,33 @@ new Checkout({
|
|
|
246
302
|
|
|
247
303
|
If you set a Content-Security-Policy on your site, allow Command Transfer’s checkout origin in `frame-src`.
|
|
248
304
|
|
|
305
|
+
### Pointing a non-production app elsewhere
|
|
306
|
+
|
|
307
|
+
Internal and staging apps override the origin at runtime, rather than installing
|
|
308
|
+
a differently-built package:
|
|
309
|
+
|
|
310
|
+
```js
|
|
311
|
+
new Checkout({
|
|
312
|
+
intentId: session.intentId,
|
|
313
|
+
clientToken: session.clientToken,
|
|
314
|
+
checkoutOrigin: "https://ct-dev-checkout.web.app", // non-production only
|
|
315
|
+
});
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
The override is validated exactly like the baked value: it must be `https` and
|
|
319
|
+
carry no credentials, and only loopback (`http://localhost:5173`) may use plain
|
|
320
|
+
`http`, for a checkout app running on your machine. Anything else throws before
|
|
321
|
+
a frame is created.
|
|
322
|
+
|
|
323
|
+
This is why there is no separate “development build” of the package: the channel
|
|
324
|
+
you install decides which **code** you get, and `checkoutOrigin` decides which
|
|
325
|
+
**backend** it talks to. The two are independent on purpose — it means no build
|
|
326
|
+
wired to a non-production backend can ever reach a merchant.
|
|
327
|
+
|
|
249
328
|
## Rules
|
|
250
329
|
|
|
251
|
-
- Secret API keys stay on your server.
|
|
330
|
+
- Secret API keys (`sk_…`) stay on your server. This package must not receive them.
|
|
252
331
|
- `clientToken` is a payer capability for that checkout. Do not log it, put it in query strings, or persist it in `localStorage`.
|
|
253
|
-
- `success` in the browser is UX only. Fulfill from server-side
|
|
332
|
+
- `success` in the browser is UX only. Fulfill from server-side `GET /v1/checkout/{intentID}` when status is `SUCCEEDED`.
|
|
254
333
|
- Do not load checkout from your own storefront.
|
|
334
|
+
- Do not call Command Transfer admin, auth, or business APIs from the browser.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class d {
|
|
2
2
|
constructor() {
|
|
3
3
|
this.listeners = /* @__PURE__ */ new Map();
|
|
4
4
|
}
|
|
@@ -26,7 +26,7 @@ const s = "commandtransfer.checkout", u = "ctc_";
|
|
|
26
26
|
function m(r) {
|
|
27
27
|
return r?.trim() || "";
|
|
28
28
|
}
|
|
29
|
-
const
|
|
29
|
+
const f = m(
|
|
30
30
|
"https://ct-dev-checkout.web.app"
|
|
31
31
|
), g = /* @__PURE__ */ new Set([
|
|
32
32
|
"checkout.ready",
|
|
@@ -148,9 +148,10 @@ class y {
|
|
|
148
148
|
"allow-forms",
|
|
149
149
|
"allow-popups",
|
|
150
150
|
"allow-popups-to-escape-sandbox",
|
|
151
|
+
"allow-modals",
|
|
151
152
|
"allow-top-navigation-by-user-activation"
|
|
152
153
|
].join(" ")
|
|
153
|
-
), e.style.width = "100%", e.style.height = "
|
|
154
|
+
), e.style.width = "100%", e.style.height = "720px", e.style.border = "0", e.style.display = "block", e.style.background = "#f3f0ff", e.style.borderRadius = this.presentation === "modal" ? "16px" : "0", e;
|
|
154
155
|
}
|
|
155
156
|
mountModal(e) {
|
|
156
157
|
const t = document.createElement("div");
|
|
@@ -206,11 +207,11 @@ function b(r) {
|
|
|
206
207
|
return e ? e.startsWith("#") || e.startsWith(".") || e.startsWith("[") ? document.querySelector(e) : document.getElementById(e) ?? document.querySelector(e) : null;
|
|
207
208
|
}
|
|
208
209
|
const v = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
209
|
-
function
|
|
210
|
+
function a(r) {
|
|
210
211
|
return r.replace(/^\[|\]$/g, "").toLowerCase();
|
|
211
212
|
}
|
|
212
|
-
function
|
|
213
|
-
const e =
|
|
213
|
+
function h(r) {
|
|
214
|
+
const e = a(r);
|
|
214
215
|
return e === "localhost" || e === "127.0.0.1" || e === "::1";
|
|
215
216
|
}
|
|
216
217
|
function E(r) {
|
|
@@ -223,8 +224,8 @@ function E(r) {
|
|
|
223
224
|
return n === 10 || n === 127 || n === 192 && i === 168 || n === 172 && i >= 16 && i <= 31;
|
|
224
225
|
}
|
|
225
226
|
function I(r) {
|
|
226
|
-
const e =
|
|
227
|
-
return
|
|
227
|
+
const e = a(r);
|
|
228
|
+
return h(e) || E(e) ? !0 : e.endsWith(".local") || e.endsWith(".test") || e.endsWith(".localhost");
|
|
228
229
|
}
|
|
229
230
|
function C(r) {
|
|
230
231
|
const e = r.trim();
|
|
@@ -242,7 +243,7 @@ function x(r) {
|
|
|
242
243
|
throw new Error("clientToken is invalid.");
|
|
243
244
|
return t;
|
|
244
245
|
}
|
|
245
|
-
function
|
|
246
|
+
function l(r, e, t) {
|
|
246
247
|
let n;
|
|
247
248
|
try {
|
|
248
249
|
n = new URL(r);
|
|
@@ -255,17 +256,14 @@ function d(r, e, t) {
|
|
|
255
256
|
return n;
|
|
256
257
|
throw new Error(`${e} must be an https URL.`);
|
|
257
258
|
}
|
|
258
|
-
function M() {
|
|
259
|
-
|
|
259
|
+
function M(r) {
|
|
260
|
+
const e = r?.trim() || f;
|
|
261
|
+
if (!e)
|
|
260
262
|
throw new Error("checkout origin is not configured.");
|
|
261
|
-
return
|
|
262
|
-
a,
|
|
263
|
-
"checkout origin",
|
|
264
|
-
l
|
|
265
|
-
).origin;
|
|
263
|
+
return l(e, "checkout origin", h).origin;
|
|
266
264
|
}
|
|
267
265
|
function O(r, e) {
|
|
268
|
-
return
|
|
266
|
+
return l(r, e, I).toString();
|
|
269
267
|
}
|
|
270
268
|
function U(r) {
|
|
271
269
|
const e = encodeURIComponent(r.intentId), t = new URL(`/pay/${e}`, r.checkoutOrigin);
|
|
@@ -276,7 +274,7 @@ function L(r) {
|
|
|
276
274
|
throw new Error("Checkout config is required.");
|
|
277
275
|
if (!r.intentId?.trim())
|
|
278
276
|
throw new Error("intentId is required.");
|
|
279
|
-
const e = C(r.intentId), t = x(r.clientToken ?? ""), n = M(), i = r.mode ?? "inline";
|
|
277
|
+
const e = C(r.intentId), t = x(r.clientToken ?? ""), n = M(r.checkoutOrigin), i = r.mode ?? "inline";
|
|
280
278
|
if (i !== "inline" && i !== "modal" && i !== "redirect")
|
|
281
279
|
throw new Error('mode must be "inline", "modal", or "redirect".');
|
|
282
280
|
const o = r.returnUrl ? O(r.returnUrl, "returnUrl") : void 0;
|
|
@@ -290,7 +288,7 @@ function L(r) {
|
|
|
290
288
|
}
|
|
291
289
|
class T {
|
|
292
290
|
constructor(e) {
|
|
293
|
-
this.events = new
|
|
291
|
+
this.events = new d(), this.iframeManager = null, this.mounted = !1, this.settled = !1, this.handleMessage = (t) => {
|
|
294
292
|
switch (t.type) {
|
|
295
293
|
case "checkout.ready":
|
|
296
294
|
this.events.emit("ready", { intentId: t.checkoutId });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(s,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(s=typeof globalThis<"u"?globalThis:s||self,u(s.CommandTransferCheckout={}))})(this,(function(s){"use strict";class u{constructor(){this.listeners=new Map}on(e,t){let n=this.listeners.get(e);return n||(n=new Set,this.listeners.set(e,n)),n.add(t),()=>{n?.delete(t)}}emit(e,t){const n=this.listeners.get(e);n&&[...n].forEach(o=>{try{o(t)}catch(i){console.error(`Checkout "${String(e)}" handler failed.`,i)}})}removeAllListeners(){this.listeners.clear()}}const c="commandtransfer.checkout",h="ctc_";function
|
|
1
|
+
(function(s,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(s=typeof globalThis<"u"?globalThis:s||self,u(s.CommandTransferCheckout={}))})(this,(function(s){"use strict";class u{constructor(){this.listeners=new Map}on(e,t){let n=this.listeners.get(e);return n||(n=new Set,this.listeners.set(e,n)),n.add(t),()=>{n?.delete(t)}}emit(e,t){const n=this.listeners.get(e);n&&[...n].forEach(o=>{try{o(t)}catch(i){console.error(`Checkout "${String(e)}" handler failed.`,i)}})}removeAllListeners(){this.listeners.clear()}}const c="commandtransfer.checkout",h="ctc_";function m(r){return r?.trim()||""}const g=m("https://ct-dev-checkout.web.app"),w=new Set(["checkout.ready","checkout.success","checkout.cancel","checkout.error","checkout.resize"]);function k(r){return!!r&&typeof r=="object"&&!Array.isArray(r)}function a(r,e){if(typeof r!="string")return null;const t=r.trim();return!t||t.length>e||/[\u0000-\u001f\u007f]/.test(t)?null:t}function p(r,e){if(!k(r)||r.source!==c)return null;const t=a(r.type,64);if(!t||!w.has(t))return null;const n=a(r.checkoutId,128);if(n!==e)return null;switch(t){case"checkout.ready":return{source:c,type:t,checkoutId:n};case"checkout.success":{const o=a(r.reference,128);return o?{source:c,type:t,checkoutId:n,reference:o}:null}case"checkout.cancel":return{source:c,type:t,checkoutId:n};case"checkout.error":{const o=a(r.code,64),i=a(r.message,280);return!o||!i?null:{source:c,type:t,checkoutId:n,code:o,message:i}}case"checkout.resize":{const o=typeof r.height=="number"?r.height:Number(r.height);return!Number.isFinite(o)||o<200||o>4e3?null:{source:c,type:t,checkoutId:n,height:Math.round(o)}}default:return null}}class y{constructor(e){this.sourceWindow=null,this.handleMessage=t=>{if(t.origin!==this.checkoutOrigin||!this.sourceWindow||t.source!==this.sourceWindow)return;const n=p(t.data,this.checkoutId);n&&this.onMessage(n)},this.checkoutId=e.checkoutId,this.checkoutOrigin=e.checkoutOrigin,this.onMessage=e.onMessage,window.addEventListener("message",this.handleMessage)}setSourceWindow(e){this.sourceWindow=e}destroy(){window.removeEventListener("message",this.handleMessage),this.sourceWindow=null}}class b{constructor(e){this.iframe=null,this.overlay=null,this.previousBodyOverflow=null,this.escapeListener=null,this.checkoutUrl=e.checkoutUrl,this.presentation=e.presentation,this.onCloseRequest=e.onCloseRequest,this.bridge=new y({checkoutId:e.checkoutId,checkoutOrigin:e.checkoutOrigin,onMessage:e.onMessage})}mount(e){if(this.iframe)throw new Error("Checkout iframe is already mounted.");const t=this.createIframe();this.presentation==="modal"?this.mountModal(t):e.appendChild(t),this.iframe=t,this.bridge.setSourceWindow(t.contentWindow),t.addEventListener("load",()=>{this.bridge.setSourceWindow(t.contentWindow)})}setHeight(e){this.iframe&&(this.iframe.style.height=`${Math.round(e)}px`)}destroy(){this.bridge.destroy(),this.iframe?.remove(),this.iframe=null,this.teardownModal()}createIframe(){const e=document.createElement("iframe");return e.src=this.checkoutUrl,e.title="Command Transfer checkout",e.setAttribute("allow","payment; clipboard-write; publickey-credentials-get"),e.setAttribute("referrerpolicy","no-referrer"),e.setAttribute("sandbox",["allow-scripts","allow-same-origin","allow-forms","allow-popups","allow-popups-to-escape-sandbox","allow-modals","allow-top-navigation-by-user-activation"].join(" ")),e.style.width="100%",e.style.height="720px",e.style.border="0",e.style.display="block",e.style.background="#f3f0ff",e.style.borderRadius=this.presentation==="modal"?"16px":"0",e}mountModal(e){const t=document.createElement("div");t.setAttribute("data-ct-checkout","overlay"),t.setAttribute("role","dialog"),t.setAttribute("aria-modal","true"),t.setAttribute("aria-label","Payment checkout"),t.style.cssText=["position:fixed","inset:0","z-index:2147483647","display:flex","align-items:center","justify-content:center","padding:24px 16px","background:rgba(15,12,41,0.55)"].join(";");const n=document.createElement("div");n.style.cssText=["position:relative","width:min(420px,100%)","max-height:calc(100vh - 48px)","overflow:auto","border-radius:16px","box-shadow:0 24px 64px rgba(15,12,41,0.28)"].join(";");const o=document.createElement("button");o.type="button",o.setAttribute("aria-label","Close checkout"),o.textContent="×",o.style.cssText=["position:absolute","top:8px","right:8px","z-index:1","width:32px","height:32px","border:0","border-radius:999px","background:#ffffff","color:#1e1654","font-size:22px","line-height:1","cursor:pointer","box-shadow:0 2px 8px rgba(15,12,41,0.16)"].join(";"),o.addEventListener("click",this.onCloseRequest),t.addEventListener("click",i=>{i.target===t&&this.onCloseRequest()}),this.escapeListener=i=>{i.key==="Escape"&&this.onCloseRequest()},window.addEventListener("keydown",this.escapeListener),this.previousBodyOverflow=document.body.style.overflow,document.body.style.overflow="hidden",n.append(o,e),t.appendChild(n),document.body.appendChild(t),this.overlay=t,o.focus()}teardownModal(){this.escapeListener&&(window.removeEventListener("keydown",this.escapeListener),this.escapeListener=null),this.overlay?.remove(),this.overlay=null,this.previousBodyOverflow!==null&&(document.body.style.overflow=this.previousBodyOverflow,this.previousBodyOverflow=null)}}function v(r){if(typeof r!="string")return r;const e=r.trim();return e?e.startsWith("#")||e.startsWith(".")||e.startsWith("[")?document.querySelector(e):document.getElementById(e)??document.querySelector(e):null}const C=/^[A-Za-z0-9._:-]{1,128}$/;function l(r){return r.replace(/^\[|\]$/g,"").toLowerCase()}function d(r){const e=l(r);return e==="localhost"||e==="127.0.0.1"||e==="::1"}function E(r){const e=r.split(".");if(e.length!==4)return!1;const t=e.map(i=>Number(i));if(t.some(i=>!Number.isInteger(i)||i<0||i>255))return!1;const[n,o]=t;return n===10||n===127||n===192&&o===168||n===172&&o>=16&&o<=31}function I(r){const e=l(r);return d(e)||E(e)?!0:e.endsWith(".local")||e.endsWith(".test")||e.endsWith(".localhost")}function x(r){const e=r.trim();if(!C.test(e))throw new Error("intentId is invalid.");return e}function M(r){const e=r.trim(),t=e.toLowerCase().startsWith("bearer ")?e.slice(7).trim():e;if(!t.toLowerCase().startsWith(h))throw new Error(`clientToken is invalid. Expected a token starting with ${h}.`);if(t.length>512||/\s/.test(t))throw new Error("clientToken is invalid.");return t}function f(r,e,t){let n;try{n=new URL(r)}catch{throw new Error(`${e} is not a valid URL.`)}if(n.username||n.password)throw new Error(`${e} must not include credentials.`);if(n.protocol==="https:"||n.protocol==="http:"&&t(n.hostname))return n;throw new Error(`${e} must be an https URL.`)}function O(r){const e=r?.trim()||g;if(!e)throw new Error("checkout origin is not configured.");return f(e,"checkout origin",d).origin}function U(r,e){return f(r,e,I).toString()}function T(r){const e=encodeURIComponent(r.intentId),t=new URL(`/pay/${e}`,r.checkoutOrigin);return r.mode==="redirect"?r.returnUrl&&t.searchParams.set("return_url",r.returnUrl):(t.searchParams.set("embed","1"),r.parentOrigin&&t.searchParams.set("origin",r.parentOrigin)),t.hash=`token=${encodeURIComponent(r.clientToken)}`,t.toString()}function L(r){if(!r||typeof r!="object")throw new Error("Checkout config is required.");if(!r.intentId?.trim())throw new Error("intentId is required.");const e=x(r.intentId),t=M(r.clientToken??""),n=O(r.checkoutOrigin),o=r.mode??"inline";if(o!=="inline"&&o!=="modal"&&o!=="redirect")throw new Error('mode must be "inline", "modal", or "redirect".');const i=r.returnUrl?U(r.returnUrl,"returnUrl"):void 0;return{intentId:e,clientToken:t,checkoutOrigin:n,mode:o,returnUrl:i}}class S{constructor(e){this.events=new u,this.iframeManager=null,this.mounted=!1,this.settled=!1,this.handleMessage=t=>{switch(t.type){case"checkout.ready":this.events.emit("ready",{intentId:t.checkoutId});break;case"checkout.success":this.settled=!0,this.events.emit("success",{intentId:t.checkoutId,reference:t.reference}),this.teardownFrame();break;case"checkout.cancel":this.settled=!0,this.events.emit("cancel",void 0),this.teardownFrame();break;case"checkout.error":this.settled=!0,this.events.emit("error",{code:t.code,message:t.message}),this.teardownFrame();break;case"checkout.resize":this.iframeManager?.setHeight(t.height);break}},this.config=L(e),this.containerOption=e.container}start(e){if(this.config.mode==="redirect"){this.redirect();return}if(this.config.mode==="modal"){this.open();return}this.mount(e??this.containerOption)}mount(e){this.mountFrame("inline",e??this.containerOption)}open(){this.mountFrame("modal",document.body)}redirect(){window.location.assign(this.getCheckoutUrl("redirect"))}on(e,t){return this.events.on(e,t)}close(){const e=this.mounted;this.teardownFrame(),e&&!this.settled&&(this.settled=!0,this.events.emit("cancel",void 0))}getCheckoutUrl(e){return T({intentId:this.config.intentId,clientToken:this.config.clientToken,checkoutOrigin:this.config.checkoutOrigin,mode:e,returnUrl:this.config.returnUrl,parentOrigin:e==="redirect"?void 0:window.location.origin})}mountFrame(e,t){if(this.mounted)throw new Error("Checkout is already mounted.");if(!t)throw new Error("Checkout container was not found.");const n=e==="modal"?document.body:v(t);if(!n)throw new Error("Checkout container was not found.");const o=this.getCheckoutUrl(e);this.iframeManager=new b({checkoutId:this.config.intentId,checkoutUrl:o,checkoutOrigin:this.config.checkoutOrigin,presentation:e,onMessage:this.handleMessage,onCloseRequest:()=>this.close()}),this.iframeManager.mount(n),this.mounted=!0}teardownFrame(){this.iframeManager?.destroy(),this.iframeManager=null,this.mounted=!1}}s.Checkout=S,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export declare const CHECKOUT_MESSAGE_SOURCE = "commandtransfer.checkout";
|
|
2
2
|
export declare const CLIENT_TOKEN_PREFIX = "ctc_";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Default hosted Checkout Web origin, baked in at build time from
|
|
5
|
+
* `VITE_CHECKOUT_ORIGIN`.
|
|
6
|
+
*
|
|
7
|
+
* Every published build — stable and prerelease alike — is built against
|
|
8
|
+
* PRODUCTION. Callers that need another environment pass
|
|
9
|
+
* `checkoutOrigin` to `new Checkout({ ... })` rather than installing a
|
|
10
|
+
* separately-built package.
|
|
6
11
|
*/
|
|
7
12
|
export declare const CHECKOUT_ORIGIN: string;
|
|
8
13
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAElE,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAM1C
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAElE,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAM1C;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,QAE3B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IframeManager.d.ts","sourceRoot":"","sources":["../../src/iframe/IframeManager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD,UAAU,oBAAoB;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,QA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AO,CAAC,QAAQ,CAAC,YAAY,CAAqB;IAClD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAa;IAC5C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;gBAE3B,OAAO,EAAE,oBAAoB;IAYzC,KAAK,CAAC,SAAS,EAAE,WAAW,GAAG,IAAI;IAoBnC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAQ/B,OAAO,IAAI,IAAI;IAOf,OAAO,CAAC,YAAY;IA+BpB,OAAO,CAAC,UAAU;IAwElB,OAAO,CAAC,aAAa;CActB"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -16,6 +16,18 @@ export interface CheckoutConfig {
|
|
|
16
16
|
* Ignored for inline/modal — handle `success` / `cancel` events instead.
|
|
17
17
|
*/
|
|
18
18
|
returnUrl?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Hosted checkout origin to talk to. Defaults to the origin this package was
|
|
21
|
+
* built against, which is always production.
|
|
22
|
+
*
|
|
23
|
+
* Merchants should leave this unset. Set it only to point a non-production
|
|
24
|
+
* app at a non-production checkout, e.g.
|
|
25
|
+
* `checkoutOrigin: "https://ct-dev-checkout.web.app"`.
|
|
26
|
+
*
|
|
27
|
+
* Must be https; http is accepted only on loopback, for a checkout app
|
|
28
|
+
* running locally.
|
|
29
|
+
*/
|
|
30
|
+
checkoutOrigin?: string;
|
|
19
31
|
}
|
|
20
32
|
export interface CheckoutReady {
|
|
21
33
|
intentId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC;AAE3D,MAAM,WAAW,cAAc;IAC7B,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IAEjB,+DAA+D;IAC/D,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,IAAI,CAAC,EA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;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB,GACD;IACE,MAAM,EAAE,0BAA0B,CAAC;IACnC,IAAI,EAAE,kBAAkB,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE,MAAM,EAAE,0BAA0B,CAAC;IACnC,IAAI,EAAE,iBAAiB,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;CACpB,GACD;IACE,MAAM,EAAE,0BAA0B,CAAC;IACnC,IAAI,EAAE,gBAAgB,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,GACD;IACE,MAAM,EAAE,0BAA0B,CAAC;IACnC,IAAI,EAAE,iBAAiB,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC"}
|
package/dist/url.d.ts
CHANGED
|
@@ -5,7 +5,19 @@ export declare function isLocalHostname(hostname: string): boolean;
|
|
|
5
5
|
export declare function isMerchantDevHostname(hostname: string): boolean;
|
|
6
6
|
export declare function normalizeIntentId(value: string): string;
|
|
7
7
|
export declare function normalizeClientToken(value: string): string;
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Resolve the hosted checkout origin.
|
|
10
|
+
*
|
|
11
|
+
* `override` (from `CheckoutConfig.checkoutOrigin`) wins; otherwise the origin
|
|
12
|
+
* baked in at build time is used. Keeping this overridable is what lets ONE
|
|
13
|
+
* published package serve production and non-production: the package is always
|
|
14
|
+
* built against production, and a staging app points itself elsewhere at
|
|
15
|
+
* runtime instead of installing a differently-built build.
|
|
16
|
+
*
|
|
17
|
+
* The override goes through the same validation as the baked value, so it must
|
|
18
|
+
* be https (http is allowed only on loopback, for a locally running checkout).
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveCheckoutOrigin(override?: string): string;
|
|
9
21
|
/** Merchant return / parent URLs — any https site, or http on local/LAN. */
|
|
10
22
|
export declare function assertSafeHttpUrl(value: string, field: string): string;
|
|
11
23
|
export declare function buildCheckoutUrl(options: {
|
package/dist/url.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../src/url.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAQ5D,gFAAgF;AAChF,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAGzD;AAkBD,0DAA0D;AAC1D,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAQ/D;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMvD;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAiB1D;AA6BD,wBAAgB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../src/url.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAQ5D,gFAAgF;AAChF,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAGzD;AAkBD,0DAA0D;AAC1D,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAQ/D;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMvD;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAiB1D;AA6BD;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAQ/D;AAED,4EAA4E;AAC5E,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,OAAO,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG,UAAU,CAAC;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,MAAM,CAiBT;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG;IACtD,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,YAAY,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CA6BA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@integralscope/command-transfer-checkout-js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7-dev.1",
|
|
4
4
|
"description": "Command Transfer Checkout Web SDK",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -37,4 +37,4 @@
|
|
|
37
37
|
"registry": "https://registry.npmjs.org",
|
|
38
38
|
"access": "public"
|
|
39
39
|
}
|
|
40
|
-
}
|
|
40
|
+
}
|