@invonetwork/web-sdk 2.5.1 → 3.0.0
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/CHANGELOG.md +35 -0
- package/README.md +28 -31
- package/dist/{chunk-5X3ESHJR.js → chunk-SPTYWJDN.js} +7 -2
- package/dist/index.cjs +72 -189
- package/dist/index.d.cts +18 -39
- package/dist/index.d.ts +18 -39
- package/dist/index.js +69 -191
- package/dist/server.cjs +48 -64
- package/dist/server.d.cts +14 -14
- package/dist/server.d.ts +14 -14
- package/dist/server.js +45 -66
- package/dist/{types-BHvVjdMV.d.cts → types-DMNXAGiw.d.cts} +45 -116
- package/dist/{types-BHvVjdMV.d.ts → types-DMNXAGiw.d.ts} +45 -116
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,47 +1,26 @@
|
|
|
1
|
-
import { M as
|
|
2
|
-
export {
|
|
1
|
+
import { M as MountCheckoutOptions, C as CheckoutMountHandle, a as ClientConfig, b as CallOptions, A as ApproveResult, c as ConfirmReceiptResult, L as LinkDeviceResult, P as PendingCollectResult, D as DestinationsQuery, d as DestinationsResult, B as BalanceResult, E as EnrollmentBeginResult, e as EnrollmentVerifyResult, R as RecoveryBeginResult, f as RecoveryCompleteResult } from './types-DMNXAGiw.js';
|
|
2
|
+
export { g as BalanceRow, h as DestinationGame, I as InvoError, i as InvoErrorInfo, j as InvoHooks, k as InvoRequestInfo, l as InvoResponseInfo, m as PendingCollectItem, n as Rail, V as VerificationMethod } from './types-DMNXAGiw.js';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Platform Commerce card confirmation (browser side). The server (`InvoServer.
|
|
6
|
-
* platformCommerce.purchase` with `fundingSource:"card"`) returns a `clientSecret`; this
|
|
7
|
-
* mounts the processor's Payment Element (card / Apple Pay / Google Pay) and confirms it.
|
|
8
|
-
* The sale is real only on the `platform_commerce.purchased` webhook — treat a "succeeded"
|
|
9
|
-
* here as "show processing", never as fulfilled.
|
|
10
|
-
*/
|
|
11
4
|
declare class PlatformCommerceClient {
|
|
12
|
-
private readonly defaultPublishableKey;
|
|
13
|
-
constructor(defaultPublishableKey: () => string | undefined);
|
|
14
5
|
/**
|
|
15
|
-
*
|
|
16
|
-
* This is the fully-controllable primitive (`confirmCardPayment` builds on it).
|
|
6
|
+
* Embed INVO's hosted checkout in an iframe and listen for completion.
|
|
17
7
|
*
|
|
18
8
|
* ```ts
|
|
19
|
-
* const
|
|
20
|
-
*
|
|
9
|
+
* const handle = invo.platformCommerce.mountCheckout("#checkout", checkoutUrl, {
|
|
10
|
+
* onComplete: () => showProcessing(), // then reconcile server-side
|
|
21
11
|
* });
|
|
22
|
-
* //
|
|
23
|
-
* const r = await session.confirm({ returnUrl: location.href });
|
|
24
|
-
* if (r.status === "succeeded") showProcessing();
|
|
25
|
-
* session.destroy();
|
|
12
|
+
* // later: handle.destroy();
|
|
26
13
|
* ```
|
|
27
|
-
*/
|
|
28
|
-
mountCardPayment(clientSecret: string, opts: MountCardPaymentOptions): Promise<CardPaymentSession>;
|
|
29
|
-
/**
|
|
30
|
-
* One-call mount + confirm. Mounts the Payment Element into `opts.mount` and resolves
|
|
31
|
-
* when the payment is confirmed via a submit trigger — either `opts.submit` (your Pay
|
|
32
|
-
* button, selector or element) or a minimal button the SDK renders inside `mount`. For
|
|
33
|
-
* full control over the button, prefer {@link mountCardPayment}.
|
|
34
14
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* remount.
|
|
15
|
+
* Or skip the helper and redirect: `location.href = checkoutUrl` (the buyer returns to
|
|
16
|
+
* the `successUrl`/`cancelUrl` you passed to the server `purchase()`).
|
|
17
|
+
*
|
|
18
|
+
* `onComplete` fires on the page's `INVO_CHECKOUT_COMPLETE` postMessage -- accepted ONLY
|
|
19
|
+
* from the checkout URL's own origin (any other window could forge the event). It is a
|
|
20
|
+
* UX signal: the sale is REAL only on the `platform_commerce.purchased` webhook, never
|
|
21
|
+
* on this client event.
|
|
43
22
|
*/
|
|
44
|
-
|
|
23
|
+
mountCheckout(el: string | HTMLElement, checkoutUrl: string, opts?: MountCheckoutOptions): CheckoutMountHandle;
|
|
45
24
|
}
|
|
46
25
|
declare class InvoClient {
|
|
47
26
|
private readonly http;
|
|
@@ -49,11 +28,11 @@ declare class InvoClient {
|
|
|
49
28
|
private readonly refreshToken;
|
|
50
29
|
/** In-flight refresh, shared so concurrent expiries trigger a single re-mint. */
|
|
51
30
|
private refreshInFlight;
|
|
52
|
-
private readonly commercePublishableKey;
|
|
53
31
|
/**
|
|
54
|
-
* Platform Commerce (ecommerce)
|
|
32
|
+
* Platform Commerce (ecommerce) hosted-checkout embed. Use after
|
|
55
33
|
* `InvoServer.platformCommerce.purchase({ fundingSource: "card" })` returns a
|
|
56
|
-
* `
|
|
34
|
+
* `checkoutUrl` — either redirect the buyer there, or embed it with
|
|
35
|
+
* `mountCheckout`. No card element, no processor dependency. See
|
|
57
36
|
* {@link PlatformCommerceClient}.
|
|
58
37
|
*/
|
|
59
38
|
readonly platformCommerce: PlatformCommerceClient;
|
|
@@ -179,4 +158,4 @@ declare class InvoClient {
|
|
|
179
158
|
private confirmReceipt;
|
|
180
159
|
}
|
|
181
160
|
|
|
182
|
-
export { ApproveResult, BalanceResult, CallOptions,
|
|
161
|
+
export { ApproveResult, BalanceResult, CallOptions, CheckoutMountHandle, ClientConfig, ConfirmReceiptResult, DestinationsQuery, DestinationsResult, EnrollmentBeginResult, EnrollmentVerifyResult, InvoClient, LinkDeviceResult, MountCheckoutOptions, PendingCollectResult, PlatformCommerceClient, RecoveryBeginResult, RecoveryCompleteResult };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { InvoError, assertSecureBaseUrl, Http, toDestinationsResult } from './chunk-
|
|
2
|
-
export { InvoError } from './chunk-
|
|
1
|
+
import { InvoError, assertSecureBaseUrl, Http, toDestinationsResult } from './chunk-SPTYWJDN.js';
|
|
2
|
+
export { InvoError } from './chunk-SPTYWJDN.js';
|
|
3
3
|
|
|
4
4
|
// src/shared/webauthn.ts
|
|
5
5
|
function malformedOptions(field) {
|
|
@@ -120,216 +120,96 @@ function toBalanceRow(row) {
|
|
|
120
120
|
raw: row
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
|
-
var PROCESSOR_SRC = "https://js.stripe.com/v3";
|
|
124
|
-
var PROCESSOR_LOAD_TIMEOUT_MS = 1e4;
|
|
125
|
-
var processorScriptLoad;
|
|
126
|
-
function loadProcessorScript() {
|
|
127
|
-
if (typeof document === "undefined" || typeof window === "undefined") {
|
|
128
|
-
return Promise.reject(
|
|
129
|
-
new InvoError({
|
|
130
|
-
message: "confirmCardPayment requires a browser DOM (window/document).",
|
|
131
|
-
code: "DOM_UNAVAILABLE",
|
|
132
|
-
status: 0
|
|
133
|
-
})
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
if (window.Stripe) return Promise.resolve();
|
|
137
|
-
if (processorScriptLoad) return processorScriptLoad;
|
|
138
|
-
processorScriptLoad = new Promise((resolve, reject) => {
|
|
139
|
-
const fail = () => {
|
|
140
|
-
processorScriptLoad = void 0;
|
|
141
|
-
reject(
|
|
142
|
-
new InvoError({
|
|
143
|
-
message: "Failed to load the card processor script.",
|
|
144
|
-
code: "PROCESSOR_LOAD_FAILED",
|
|
145
|
-
status: 0
|
|
146
|
-
})
|
|
147
|
-
);
|
|
148
|
-
};
|
|
149
|
-
const existing = document.querySelector(
|
|
150
|
-
`script[src="${PROCESSOR_SRC}"]`
|
|
151
|
-
);
|
|
152
|
-
if (existing) {
|
|
153
|
-
const started = Date.now();
|
|
154
|
-
const poll = setInterval(() => {
|
|
155
|
-
if (window.Stripe) {
|
|
156
|
-
clearInterval(poll);
|
|
157
|
-
resolve();
|
|
158
|
-
} else if (Date.now() - started > PROCESSOR_LOAD_TIMEOUT_MS) {
|
|
159
|
-
clearInterval(poll);
|
|
160
|
-
existing.remove();
|
|
161
|
-
fail();
|
|
162
|
-
}
|
|
163
|
-
}, 100);
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
const script = document.createElement("script");
|
|
167
|
-
script.src = PROCESSOR_SRC;
|
|
168
|
-
script.async = true;
|
|
169
|
-
script.addEventListener("load", () => resolve());
|
|
170
|
-
script.addEventListener("error", () => {
|
|
171
|
-
script.remove();
|
|
172
|
-
fail();
|
|
173
|
-
});
|
|
174
|
-
document.head.appendChild(script);
|
|
175
|
-
});
|
|
176
|
-
return processorScriptLoad;
|
|
177
|
-
}
|
|
178
|
-
async function defaultLoadProcessor(publishableKey) {
|
|
179
|
-
await loadProcessorScript();
|
|
180
|
-
const factory = window.Stripe;
|
|
181
|
-
if (typeof factory !== "function") {
|
|
182
|
-
throw new InvoError({
|
|
183
|
-
message: "The card processor was unavailable after loading.",
|
|
184
|
-
code: "PROCESSOR_UNAVAILABLE",
|
|
185
|
-
status: 0
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
return factory(publishableKey);
|
|
189
|
-
}
|
|
190
|
-
function mapCardConfirm(res) {
|
|
191
|
-
const raw = res;
|
|
192
|
-
if (res.error) {
|
|
193
|
-
return { status: "failed", error: res.error.message ?? "Card payment failed.", raw };
|
|
194
|
-
}
|
|
195
|
-
const pi = res.paymentIntent;
|
|
196
|
-
const s = pi?.status;
|
|
197
|
-
let status;
|
|
198
|
-
if (s === "succeeded") status = "succeeded";
|
|
199
|
-
else if (s === "processing") status = "processing";
|
|
200
|
-
else if (s === "requires_action" || s === "requires_confirmation") status = "requires_action";
|
|
201
|
-
else status = "failed";
|
|
202
|
-
return { status, paymentIntentId: pi?.id, raw };
|
|
203
|
-
}
|
|
204
|
-
function resolveSubmit(opts) {
|
|
205
|
-
if (opts.submit) {
|
|
206
|
-
const el = typeof opts.submit === "string" ? typeof document !== "undefined" ? document.querySelector(opts.submit) : null : opts.submit;
|
|
207
|
-
if (!el) {
|
|
208
|
-
throw new InvoError({
|
|
209
|
-
message: `confirmCardPayment could not find the submit element "${String(opts.submit)}".`,
|
|
210
|
-
code: "SUBMIT_NOT_FOUND",
|
|
211
|
-
status: 0
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
return { el, created: false };
|
|
215
|
-
}
|
|
216
|
-
if (typeof document === "undefined") {
|
|
217
|
-
throw new InvoError({
|
|
218
|
-
message: "confirmCardPayment needs a submit button: pass `submit`, or use `mountCardPayment(...).confirm()` from your own button.",
|
|
219
|
-
code: "SUBMIT_REQUIRED",
|
|
220
|
-
status: 0
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
const container = typeof opts.mount === "string" ? document.querySelector(opts.mount) : opts.mount;
|
|
224
|
-
const btn = document.createElement("button");
|
|
225
|
-
btn.type = "button";
|
|
226
|
-
btn.textContent = opts.submitLabel ?? "Pay";
|
|
227
|
-
(container ?? document.body).appendChild(btn);
|
|
228
|
-
return { el: btn, created: true };
|
|
229
|
-
}
|
|
230
123
|
var PlatformCommerceClient = class {
|
|
231
|
-
constructor(defaultPublishableKey) {
|
|
232
|
-
this.defaultPublishableKey = defaultPublishableKey;
|
|
233
|
-
}
|
|
234
124
|
/**
|
|
235
|
-
*
|
|
236
|
-
* This is the fully-controllable primitive (`confirmCardPayment` builds on it).
|
|
125
|
+
* Embed INVO's hosted checkout in an iframe and listen for completion.
|
|
237
126
|
*
|
|
238
127
|
* ```ts
|
|
239
|
-
* const
|
|
240
|
-
*
|
|
128
|
+
* const handle = invo.platformCommerce.mountCheckout("#checkout", checkoutUrl, {
|
|
129
|
+
* onComplete: () => showProcessing(), // then reconcile server-side
|
|
241
130
|
* });
|
|
242
|
-
* //
|
|
243
|
-
* const r = await session.confirm({ returnUrl: location.href });
|
|
244
|
-
* if (r.status === "succeeded") showProcessing();
|
|
245
|
-
* session.destroy();
|
|
131
|
+
* // later: handle.destroy();
|
|
246
132
|
* ```
|
|
133
|
+
*
|
|
134
|
+
* Or skip the helper and redirect: `location.href = checkoutUrl` (the buyer returns to
|
|
135
|
+
* the `successUrl`/`cancelUrl` you passed to the server `purchase()`).
|
|
136
|
+
*
|
|
137
|
+
* `onComplete` fires on the page's `INVO_CHECKOUT_COMPLETE` postMessage -- accepted ONLY
|
|
138
|
+
* from the checkout URL's own origin (any other window could forge the event). It is a
|
|
139
|
+
* UX signal: the sale is REAL only on the `platform_commerce.purchased` webhook, never
|
|
140
|
+
* on this client event.
|
|
247
141
|
*/
|
|
248
|
-
|
|
249
|
-
if (
|
|
250
|
-
throw new
|
|
142
|
+
mountCheckout(el, checkoutUrl, opts) {
|
|
143
|
+
if (typeof document === "undefined" || typeof window === "undefined") {
|
|
144
|
+
throw new InvoError({
|
|
145
|
+
message: "mountCheckout requires a browser DOM (window/document).",
|
|
146
|
+
code: "DOM_UNAVAILABLE",
|
|
147
|
+
status: 0
|
|
148
|
+
});
|
|
251
149
|
}
|
|
252
|
-
if (
|
|
253
|
-
throw new Error("
|
|
150
|
+
if (!checkoutUrl || !checkoutUrl.trim()) {
|
|
151
|
+
throw new Error("mountCheckout requires the server-returned `checkoutUrl`.");
|
|
254
152
|
}
|
|
255
|
-
|
|
256
|
-
|
|
153
|
+
let checkoutOrigin;
|
|
154
|
+
try {
|
|
155
|
+
const u = new URL(checkoutUrl);
|
|
156
|
+
const isLocal = u.hostname === "localhost" || u.hostname === "127.0.0.1";
|
|
157
|
+
if (u.protocol !== "https:" && !(u.protocol === "http:" && isLocal)) {
|
|
158
|
+
throw new Error("not https");
|
|
159
|
+
}
|
|
160
|
+
checkoutOrigin = u.origin;
|
|
161
|
+
} catch {
|
|
257
162
|
throw new InvoError({
|
|
258
|
-
message: "
|
|
259
|
-
code: "
|
|
163
|
+
message: "mountCheckout requires an absolute https checkoutUrl.",
|
|
164
|
+
code: "INVALID_INPUT",
|
|
260
165
|
status: 0
|
|
261
166
|
});
|
|
262
167
|
}
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
const returnUrl = confirmOpts?.returnUrl ?? opts.returnUrl;
|
|
270
|
-
const res = await processor.confirmPayment({
|
|
271
|
-
elements,
|
|
272
|
-
confirmParams: returnUrl ? { return_url: returnUrl } : void 0,
|
|
273
|
-
// Stay in-page unless the bank forces a redirect (then return_url completes it).
|
|
274
|
-
redirect: "if_required"
|
|
168
|
+
const container = typeof el === "string" ? document.querySelector(el) : el;
|
|
169
|
+
if (!container) {
|
|
170
|
+
throw new InvoError({
|
|
171
|
+
message: `mountCheckout could not find the container "${String(el)}".`,
|
|
172
|
+
code: "MOUNT_NOT_FOUND",
|
|
173
|
+
status: 0
|
|
275
174
|
});
|
|
276
|
-
|
|
175
|
+
}
|
|
176
|
+
const iframe = document.createElement("iframe");
|
|
177
|
+
iframe.src = checkoutUrl;
|
|
178
|
+
iframe.title = opts?.title ?? "INVO checkout";
|
|
179
|
+
if (opts?.className) iframe.className = opts.className;
|
|
180
|
+
iframe.style.width = "100%";
|
|
181
|
+
iframe.style.border = "0";
|
|
182
|
+
iframe.allow = "payment";
|
|
183
|
+
const onMessage = (event) => {
|
|
184
|
+
if (event.origin !== checkoutOrigin) return;
|
|
185
|
+
if (iframe.contentWindow && event.source !== iframe.contentWindow) return;
|
|
186
|
+
const msg = event.data;
|
|
187
|
+
if (!msg || msg.type !== "INVO_CHECKOUT_COMPLETE") return;
|
|
188
|
+
opts?.onComplete?.(
|
|
189
|
+
msg.data && typeof msg.data === "object" ? msg.data : {}
|
|
190
|
+
);
|
|
277
191
|
};
|
|
192
|
+
window.addEventListener("message", onMessage);
|
|
193
|
+
container.appendChild(iframe);
|
|
278
194
|
return {
|
|
279
|
-
|
|
280
|
-
confirm,
|
|
195
|
+
iframe,
|
|
281
196
|
destroy() {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
} catch {
|
|
285
|
-
}
|
|
197
|
+
window.removeEventListener("message", onMessage);
|
|
198
|
+
iframe.remove();
|
|
286
199
|
}
|
|
287
200
|
};
|
|
288
201
|
}
|
|
289
|
-
/**
|
|
290
|
-
* One-call mount + confirm. Mounts the Payment Element into `opts.mount` and resolves
|
|
291
|
-
* when the payment is confirmed via a submit trigger — either `opts.submit` (your Pay
|
|
292
|
-
* button, selector or element) or a minimal button the SDK renders inside `mount`. For
|
|
293
|
-
* full control over the button, prefer {@link mountCardPayment}.
|
|
294
|
-
*
|
|
295
|
-
* Two flow notes:
|
|
296
|
-
* - **Bank redirect:** with `redirect: "if_required"` most cards confirm in-page, but a
|
|
297
|
-
* bank can force a full redirect — the browser then navigates away (this promise never
|
|
298
|
-
* settles) and returns to `returnUrl`. On that return page, reconcile via your server's
|
|
299
|
-
* `platformCommerce.getStatus(orderId)` / the `platform_commerce.purchased` webhook.
|
|
300
|
-
* - **Decline / "failed":** the element is torn down when this resolves — to let the user
|
|
301
|
-
* retry after a decline, call `confirmCardPayment` (or `mountCardPayment`) again to
|
|
302
|
-
* remount.
|
|
303
|
-
*/
|
|
304
|
-
async confirmCardPayment(clientSecret, opts) {
|
|
305
|
-
const session = await this.mountCardPayment(clientSecret, opts);
|
|
306
|
-
let trigger;
|
|
307
|
-
try {
|
|
308
|
-
trigger = resolveSubmit(opts);
|
|
309
|
-
} catch (e) {
|
|
310
|
-
session.destroy();
|
|
311
|
-
throw e;
|
|
312
|
-
}
|
|
313
|
-
return new Promise((resolve, reject) => {
|
|
314
|
-
const finish = (settle) => {
|
|
315
|
-
if (trigger.created) trigger.el.remove();
|
|
316
|
-
session.destroy();
|
|
317
|
-
settle();
|
|
318
|
-
};
|
|
319
|
-
const onClick = () => {
|
|
320
|
-
trigger.el.removeEventListener("click", onClick);
|
|
321
|
-
if ("disabled" in trigger.el) trigger.el.disabled = true;
|
|
322
|
-
session.confirm().then(
|
|
323
|
-
(r) => finish(() => resolve(r)),
|
|
324
|
-
(e) => finish(() => reject(e))
|
|
325
|
-
);
|
|
326
|
-
};
|
|
327
|
-
trigger.el.addEventListener("click", onClick);
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
202
|
};
|
|
331
203
|
var InvoClient = class {
|
|
332
204
|
constructor(config) {
|
|
205
|
+
/**
|
|
206
|
+
* Platform Commerce (ecommerce) hosted-checkout embed. Use after
|
|
207
|
+
* `InvoServer.platformCommerce.purchase({ fundingSource: "card" })` returns a
|
|
208
|
+
* `checkoutUrl` — either redirect the buyer there, or embed it with
|
|
209
|
+
* `mountCheckout`. No card element, no processor dependency. See
|
|
210
|
+
* {@link PlatformCommerceClient}.
|
|
211
|
+
*/
|
|
212
|
+
this.platformCommerce = new PlatformCommerceClient();
|
|
333
213
|
if (!config.token) throw new Error("InvoClient requires a player `token`.");
|
|
334
214
|
if (!config.baseUrl) throw new Error("InvoClient requires a `baseUrl`.");
|
|
335
215
|
assertSecureBaseUrl(config.baseUrl);
|
|
@@ -344,8 +224,6 @@ var InvoClient = class {
|
|
|
344
224
|
});
|
|
345
225
|
this.auth = { kind: "bearer", token: config.token };
|
|
346
226
|
this.refreshToken = config.refreshToken;
|
|
347
|
-
this.commercePublishableKey = config.commercePublishableKey;
|
|
348
|
-
this.platformCommerce = new PlatformCommerceClient(() => this.commercePublishableKey);
|
|
349
227
|
}
|
|
350
228
|
assertWebAuthn() {
|
|
351
229
|
if (typeof navigator === "undefined" || !navigator.credentials) {
|
package/dist/server.cjs
CHANGED
|
@@ -159,6 +159,11 @@ var InvoError = class _InvoError extends Error {
|
|
|
159
159
|
get isBelowCardMinimum() {
|
|
160
160
|
return this.code === "BELOW_STRIPE_MINIMUM";
|
|
161
161
|
}
|
|
162
|
+
/** True if a Platform Commerce CARD purchase exceeded the hosted checkout's single-charge
|
|
163
|
+
* cap of $999.99 (`ABOVE_CARD_MAXIMUM`, 400) — split the sale or lower the amount. */
|
|
164
|
+
get isAboveCardMaximum() {
|
|
165
|
+
return this.code === "ABOVE_CARD_MAXIMUM";
|
|
166
|
+
}
|
|
162
167
|
/**
|
|
163
168
|
* True if a Platform Commerce refund targeted an order that was already refunded
|
|
164
169
|
* (409). Idempotent outcome — the original refund did happen, so treat this as
|
|
@@ -608,7 +613,7 @@ async function hmacHexSubtle(secret, message) {
|
|
|
608
613
|
}
|
|
609
614
|
|
|
610
615
|
// src/server.ts
|
|
611
|
-
var DEFAULT_UA = "invonetwork-web-sdk/
|
|
616
|
+
var DEFAULT_UA = "invonetwork-web-sdk/3.0.0 (+https://invo.network)";
|
|
612
617
|
var MAX_USD_AMOUNT = 999.99;
|
|
613
618
|
var MAX_ITEM_PRICE = 999999.99;
|
|
614
619
|
function invalidInput(label, value, why) {
|
|
@@ -770,48 +775,8 @@ function requireField(value, field, raw) {
|
|
|
770
775
|
return s;
|
|
771
776
|
}
|
|
772
777
|
var FUNDING_SOURCES = /* @__PURE__ */ new Set(["balance", "card"]);
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
}
|
|
776
|
-
function assertBillingAddress(addr, label) {
|
|
777
|
-
if (!addr || typeof addr !== "object") {
|
|
778
|
-
throw invalidInputNoEcho(label, 'is required for the "card" funding source and must be an object');
|
|
779
|
-
}
|
|
780
|
-
const required = [
|
|
781
|
-
[`${label}.line1`, addr.line1],
|
|
782
|
-
[`${label}.city`, addr.city],
|
|
783
|
-
[`${label}.postalCode`, addr.postalCode],
|
|
784
|
-
[`${label}.country`, addr.country]
|
|
785
|
-
];
|
|
786
|
-
for (const [k, v] of required) {
|
|
787
|
-
if (typeof v !== "string" || !v.trim()) throw invalidInputNoEcho(k, "is required");
|
|
788
|
-
}
|
|
789
|
-
if (!/^[A-Za-z]{2}$/.test(addr.country)) {
|
|
790
|
-
throw invalidInputNoEcho(`${label}.country`, "must be a 2-letter ISO country code");
|
|
791
|
-
}
|
|
792
|
-
const optional = [
|
|
793
|
-
[`${label}.name`, addr.name],
|
|
794
|
-
[`${label}.line2`, addr.line2],
|
|
795
|
-
[`${label}.state`, addr.state]
|
|
796
|
-
];
|
|
797
|
-
for (const [k, v] of optional) {
|
|
798
|
-
if (v !== void 0 && typeof v !== "string") {
|
|
799
|
-
throw invalidInputNoEcho(k, "must be a string when provided");
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
function toBillingAddressBody(addr) {
|
|
804
|
-
const body = {
|
|
805
|
-
line1: addr.line1,
|
|
806
|
-
city: addr.city,
|
|
807
|
-
postal_code: addr.postalCode,
|
|
808
|
-
country: addr.country
|
|
809
|
-
};
|
|
810
|
-
if (addr.name) body["name"] = addr.name;
|
|
811
|
-
if (addr.line2) body["line2"] = addr.line2;
|
|
812
|
-
if (addr.state) body["state"] = addr.state;
|
|
813
|
-
return body;
|
|
814
|
-
}
|
|
778
|
+
var CARD_MIN_USD = 0.5;
|
|
779
|
+
var CARD_MAX_USD = 999.99;
|
|
815
780
|
var PlatformCommerceServer = class {
|
|
816
781
|
constructor(http, auth) {
|
|
817
782
|
this.http = http;
|
|
@@ -824,19 +789,19 @@ var PlatformCommerceServer = class {
|
|
|
824
789
|
*
|
|
825
790
|
* - `fundingSource: "balance"` → settles synchronously; result `status:"success"` with
|
|
826
791
|
* `newBalance`/`financialBreakdown`. `totalPrice` is the tenant's network-currency amount.
|
|
827
|
-
* - `fundingSource: "card"` → result `status:"requires_payment"` + `
|
|
828
|
-
*
|
|
829
|
-
*
|
|
830
|
-
*
|
|
831
|
-
*
|
|
832
|
-
*
|
|
833
|
-
*
|
|
792
|
+
* - `fundingSource: "card"` → result `status:"requires_payment"` + `checkoutUrl`/`sessionId`.
|
|
793
|
+
* Send the buyer to `checkoutUrl` — INVO's hosted page owns the card form, wallets,
|
|
794
|
+
* billing address, and 3-D Secure (there is NO billing address in this request, and no
|
|
795
|
+
* client payment code to write; optionally embed via
|
|
796
|
+
* `InvoClient.platformCommerce.mountCheckout`). `totalPrice` is USD ($0.50–$999.99).
|
|
797
|
+
* The sale is real only on the `platform_commerce.purchased` webhook — never on the
|
|
798
|
+
* client return.
|
|
834
799
|
*
|
|
835
|
-
*
|
|
836
|
-
*
|
|
837
|
-
*
|
|
838
|
-
*
|
|
839
|
-
*
|
|
800
|
+
* Idempotency on `clientRequestId`: the balance leg throws a 409
|
|
801
|
+
* (`err.isDuplicateRequest`) on a duplicate; the card leg REPLAYS the same checkout
|
|
802
|
+
* session (`idempotentReplay: true`) — a lost response is safely recovered by retrying
|
|
803
|
+
* with the SAME `clientRequestId`. A non-platform tenant throws
|
|
804
|
+
* `err.isNotPlatformTenant` (403).
|
|
840
805
|
*/
|
|
841
806
|
async purchase(input, opts) {
|
|
842
807
|
const required = [
|
|
@@ -867,7 +832,20 @@ var PlatformCommerceServer = class {
|
|
|
867
832
|
);
|
|
868
833
|
}
|
|
869
834
|
if (input.fundingSource === "card") {
|
|
870
|
-
|
|
835
|
+
if (total < CARD_MIN_USD) {
|
|
836
|
+
throw new InvoError({
|
|
837
|
+
message: `Card purchases must be at least $${CARD_MIN_USD.toFixed(2)}.`,
|
|
838
|
+
code: "BELOW_STRIPE_MINIMUM",
|
|
839
|
+
status: 0
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
if (total > CARD_MAX_USD) {
|
|
843
|
+
throw new InvoError({
|
|
844
|
+
message: `Card purchases must be $${CARD_MAX_USD} or less.`,
|
|
845
|
+
code: "ABOVE_CARD_MAXIMUM",
|
|
846
|
+
status: 0
|
|
847
|
+
});
|
|
848
|
+
}
|
|
871
849
|
}
|
|
872
850
|
if (input.playerPhone !== void 0) assertE164(input.playerPhone, "playerPhone");
|
|
873
851
|
const body = {
|
|
@@ -884,31 +862,37 @@ var PlatformCommerceServer = class {
|
|
|
884
862
|
if (input.playerPhone) body["player_phone"] = input.playerPhone;
|
|
885
863
|
if (input.itemDescription) body["item_description"] = input.itemDescription;
|
|
886
864
|
if (input.itemCategory) body["item_category"] = input.itemCategory;
|
|
887
|
-
if (input.
|
|
865
|
+
if (input.successUrl) body["success_url"] = input.successUrl;
|
|
866
|
+
if (input.cancelUrl) body["cancel_url"] = input.cancelUrl;
|
|
867
|
+
if (input.metadata) body["metadata"] = input.metadata;
|
|
888
868
|
const raw = await this.http.post(
|
|
889
869
|
"/api/platform-commerce/purchase",
|
|
890
870
|
body,
|
|
891
871
|
this.auth,
|
|
872
|
+
// Safe to retry: balance dedupes (dup → 409); card REPLAYS the same session.
|
|
892
873
|
{ idempotent: true, signal: opts?.signal }
|
|
893
|
-
// client_request_id makes this safe to retry (dup → 409)
|
|
894
874
|
);
|
|
895
|
-
const orderIdRaw = raw["order_id"];
|
|
896
|
-
requireField(orderIdRaw, "order_id", raw);
|
|
897
875
|
const status = String(raw["status"] ?? "");
|
|
898
|
-
if (status === "requires_payment"
|
|
899
|
-
requireField(raw["
|
|
876
|
+
if (status === "requires_payment") {
|
|
877
|
+
requireField(raw["checkout_url"], "checkout_url", raw);
|
|
878
|
+
} else {
|
|
879
|
+
requireField(raw["order_id"], "order_id", raw);
|
|
900
880
|
}
|
|
881
|
+
const expiresAtRaw = raw["expires_at"];
|
|
901
882
|
return {
|
|
902
883
|
status,
|
|
903
884
|
fundingSource: String(raw["funding_source"] ?? input.fundingSource),
|
|
904
|
-
orderId:
|
|
885
|
+
orderId: raw["order_id"] ?? void 0,
|
|
905
886
|
transactionId: raw["transaction_id"],
|
|
906
887
|
newBalance: raw["new_balance"] ?? null,
|
|
907
888
|
previousBalance: raw["previous_balance"] ?? null,
|
|
908
889
|
currencyName: raw["currency_name"],
|
|
909
890
|
financialBreakdown: raw["financial_breakdown"],
|
|
910
|
-
|
|
891
|
+
sessionId: raw["session_id"],
|
|
892
|
+
checkoutUrl: raw["checkout_url"],
|
|
893
|
+
expiresAt: typeof expiresAtRaw === "number" ? expiresAtRaw : void 0,
|
|
911
894
|
amountUsd: raw["amount_usd"] ?? null,
|
|
895
|
+
idempotentReplay: raw["idempotent_replay"] === true,
|
|
912
896
|
raw
|
|
913
897
|
};
|
|
914
898
|
}
|
package/dist/server.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { I as InvoError, H as Http, o as AuthHeader, p as PlatformPurchaseInput, b as CallOptions, q as PlatformPurchaseResult, r as PlatformOrderStatusResult, s as PlatformRefundInput, t as PlatformRefundResult, S as ServerConfig, u as PlayerToken, v as InitiateSendInput, w as InitiateResult, x as InitiateTransferInput, y as CreateCheckoutInput, z as CreateCheckoutResult, F as PurchaseInput, G as PurchaseResult, J as ConfirmPaymentResult, O as OrderDetailsResult, K as PurchaseItemInput, N as PurchaseItemResult, Q as ItemHistoryQuery, T as ItemHistoryResult, U as ItemOrderQuery, W as PlayerBalanceQuery, X as PlayerBalanceResult, Y as InboundPendingQuery, Z as InboundPendingResult, _ as LinkedIdentitiesQuery, $ as LinkedIdentitiesResult, a0 as SmsVerifyResult, a1 as ClaimTransferInput, a2 as ClaimResult, a3 as ClaimCurrencyInput, a4 as TransactionStatusResult, a5 as GuardianApprovalStatusResult, a6 as ServerDestinationsQuery, d as DestinationsResult, a7 as PhoneShareContact, a8 as PhoneShareInitiateResult, a9 as PhoneShareApproveInput, aa as PhoneShareApproveResult, ab as PhoneShareStatusResult } from './types-DMNXAGiw.cjs';
|
|
2
|
+
export { ac as CurrencyBalance, h as DestinationGame, ad as FundingSource, ae as InboundPendingItem, i as InvoErrorInfo, j as InvoHooks, k as InvoRequestInfo, l as InvoResponseInfo, af as LinkedIdentityEmail, ag as PlatformPurchaseStatus, n as Rail, V as VerificationMethod } from './types-DMNXAGiw.cjs';
|
|
3
3
|
|
|
4
4
|
interface VerifyWebhookOptions {
|
|
5
5
|
/** Max age of the signed timestamp, in seconds. Default 300 (5 min). */
|
|
@@ -222,19 +222,19 @@ declare class PlatformCommerceServer {
|
|
|
222
222
|
*
|
|
223
223
|
* - `fundingSource: "balance"` → settles synchronously; result `status:"success"` with
|
|
224
224
|
* `newBalance`/`financialBreakdown`. `totalPrice` is the tenant's network-currency amount.
|
|
225
|
-
* - `fundingSource: "card"` → result `status:"requires_payment"` + `
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
225
|
+
* - `fundingSource: "card"` → result `status:"requires_payment"` + `checkoutUrl`/`sessionId`.
|
|
226
|
+
* Send the buyer to `checkoutUrl` — INVO's hosted page owns the card form, wallets,
|
|
227
|
+
* billing address, and 3-D Secure (there is NO billing address in this request, and no
|
|
228
|
+
* client payment code to write; optionally embed via
|
|
229
|
+
* `InvoClient.platformCommerce.mountCheckout`). `totalPrice` is USD ($0.50–$999.99).
|
|
230
|
+
* The sale is real only on the `platform_commerce.purchased` webhook — never on the
|
|
231
|
+
* client return.
|
|
229
232
|
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
* 409 and the `clientSecret` cannot be re-fetched — reconcile that order via the
|
|
236
|
-
* `platform_commerce.purchased` webhook / `getStatus`, and use a NEW `clientRequestId`
|
|
237
|
-
* for a fresh attempt. The balance leg has no such gap.
|
|
233
|
+
* Idempotency on `clientRequestId`: the balance leg throws a 409
|
|
234
|
+
* (`err.isDuplicateRequest`) on a duplicate; the card leg REPLAYS the same checkout
|
|
235
|
+
* session (`idempotentReplay: true`) — a lost response is safely recovered by retrying
|
|
236
|
+
* with the SAME `clientRequestId`. A non-platform tenant throws
|
|
237
|
+
* `err.isNotPlatformTenant` (403).
|
|
238
238
|
*/
|
|
239
239
|
purchase(input: PlatformPurchaseInput, opts?: CallOptions): Promise<PlatformPurchaseResult>;
|
|
240
240
|
/** Poll an order's status: `completed` (balance immediately; card after the webhook),
|