@invonetwork/web-sdk 2.5.1 → 3.1.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 +110 -0
- package/README.md +125 -39
- package/dist/{chunk-5X3ESHJR.js → chunk-BPZJ63RM.js} +68 -2
- package/dist/index.cjs +133 -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 +134 -69
- package/dist/server.d.cts +39 -19
- package/dist/server.d.ts +39 -19
- package/dist/server.js +70 -71
- package/dist/{types-BHvVjdMV.d.cts → types-DjY-50jn.d.cts} +115 -118
- package/dist/{types-BHvVjdMV.d.ts → types-DjY-50jn.d.ts} +115 -118
- package/package.json +1 -1
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-BPZJ63RM.js';
|
|
2
|
+
export { InvoError } from './chunk-BPZJ63RM.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
|
@@ -132,6 +132,67 @@ var InvoError = class _InvoError extends Error {
|
|
|
132
132
|
get isNonSteamValueIntoSteamBlocked() {
|
|
133
133
|
return this.code === "NON_STEAM_VALUE_INTO_STEAM_BLOCKED";
|
|
134
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* True if the initiate was refused because **the caller's OWN game is in testing**
|
|
137
|
+
* (`SOURCE_GAME_NOT_LIVE`, 403). Reaches this SDK via `initiateSend` / `initiateTransfer`;
|
|
138
|
+
* the backend uses the same code on its Amazon rewards-send path too (not wrapped here),
|
|
139
|
+
* so one branch keeps working if that flow is ever added.
|
|
140
|
+
*
|
|
141
|
+
* **The caller can self-serve this**: switch the game to Live in the developer console
|
|
142
|
+
* (Game Settings → Status). Show `err.message` — it names the game and the exact control.
|
|
143
|
+
* `err.gameStatus` carries the current state if you want to render it.
|
|
144
|
+
*
|
|
145
|
+
* Deliberately distinct from {@link isTargetGameNotLive} — do NOT collapse the two into
|
|
146
|
+
* one "not live" case. The remediation differs: this one the developer can fix, the
|
|
147
|
+
* other one they cannot.
|
|
148
|
+
*/
|
|
149
|
+
get isSourceGameNotLive() {
|
|
150
|
+
return this.code === "SOURCE_GAME_NOT_LIVE";
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* True if the initiate was refused because **the DESTINATION game is in testing**
|
|
154
|
+
* (`TARGET_GAME_NOT_LIVE`, 403). Reaches this SDK via `initiateSend` / `initiateTransfer`;
|
|
155
|
+
* same backend vocabulary on the Amazon rewards-send path (not wrapped here).
|
|
156
|
+
*
|
|
157
|
+
* **The caller usually CANNOT fix this** — the destination is another developer's game
|
|
158
|
+
* and only its owner can switch it to Live. Don't offer a "go fix it" action; show
|
|
159
|
+
* `err.message` and, ideally, steer the player to a different destination
|
|
160
|
+
* (`getDestinations`). `err.gameStatus` carries the current state.
|
|
161
|
+
*
|
|
162
|
+
* Deliberately distinct from {@link isSourceGameNotLive} — see the note there.
|
|
163
|
+
*/
|
|
164
|
+
get isTargetGameNotLive() {
|
|
165
|
+
return this.code === "TARGET_GAME_NOT_LIVE";
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The game's current status from a `*_GAME_NOT_LIVE` refusal (`game_status`, e.g.
|
|
169
|
+
* `"testing"`) — for rendering the actual state. Present on both the source and target
|
|
170
|
+
* refusals.
|
|
171
|
+
*/
|
|
172
|
+
get gameStatus() {
|
|
173
|
+
const v = this.bodyObject()["game_status"];
|
|
174
|
+
return typeof v === "string" && v ? v : void 0;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* True if the tenant has **no verified WebAuthn RP ID**, so passkey endpoints are dark
|
|
178
|
+
* (`WEBAUTHN_NOT_ENABLED_FOR_TENANT`, 403).
|
|
179
|
+
*
|
|
180
|
+
* **This is a configuration state, not a failure.** Passkey step-up is per-tenant and
|
|
181
|
+
* stays dark until the developer verifies a domain in the console. Treat it as
|
|
182
|
+
* "this tenant hasn't enabled passkeys yet" and fall back to the SMS/in-app path rather
|
|
183
|
+
* than surfacing an error to the player — the ceremony was never available to fail.
|
|
184
|
+
*
|
|
185
|
+
* This is currently the COMMON case, not an edge case: as of 2026-08-05 only 4 of 23
|
|
186
|
+
* sandbox tenants and **0 of 3 production tenants** have a verified RP ID. Every
|
|
187
|
+
* integration needs this branch until domain verification is widespread.
|
|
188
|
+
*
|
|
189
|
+
* The fix (for the developer's own tenant) is to verify a domain — see the passkey
|
|
190
|
+
* prerequisites in the README. Note this refusal carries the code on `code`, not
|
|
191
|
+
* `error_code`; the SDK reads both, so `err.code` is populated either way.
|
|
192
|
+
*/
|
|
193
|
+
get isWebauthnNotEnabledForTenant() {
|
|
194
|
+
return this.code === "WEBAUTHN_NOT_ENABLED_FOR_TENANT";
|
|
195
|
+
}
|
|
135
196
|
/** True if the phone-share (phone, requesting_email) pair was already approved. */
|
|
136
197
|
get isPhoneShareAlreadyApproved() {
|
|
137
198
|
return this.code === "PHONE_SHARE_ALREADY_APPROVED";
|
|
@@ -159,6 +220,11 @@ var InvoError = class _InvoError extends Error {
|
|
|
159
220
|
get isBelowCardMinimum() {
|
|
160
221
|
return this.code === "BELOW_STRIPE_MINIMUM";
|
|
161
222
|
}
|
|
223
|
+
/** True if a Platform Commerce CARD purchase exceeded the hosted checkout's single-charge
|
|
224
|
+
* cap of $999.99 (`ABOVE_CARD_MAXIMUM`, 400) — split the sale or lower the amount. */
|
|
225
|
+
get isAboveCardMaximum() {
|
|
226
|
+
return this.code === "ABOVE_CARD_MAXIMUM";
|
|
227
|
+
}
|
|
162
228
|
/**
|
|
163
229
|
* True if a Platform Commerce refund targeted an order that was already refunded
|
|
164
230
|
* (409). Idempotent outcome — the original refund did happen, so treat this as
|
|
@@ -608,7 +674,7 @@ async function hmacHexSubtle(secret, message) {
|
|
|
608
674
|
}
|
|
609
675
|
|
|
610
676
|
// src/server.ts
|
|
611
|
-
var DEFAULT_UA = "invonetwork-web-sdk/
|
|
677
|
+
var DEFAULT_UA = "invonetwork-web-sdk/3.0.0 (+https://invo.network)";
|
|
612
678
|
var MAX_USD_AMOUNT = 999.99;
|
|
613
679
|
var MAX_ITEM_PRICE = 999999.99;
|
|
614
680
|
function invalidInput(label, value, why) {
|
|
@@ -770,48 +836,8 @@ function requireField(value, field, raw) {
|
|
|
770
836
|
return s;
|
|
771
837
|
}
|
|
772
838
|
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
|
-
}
|
|
839
|
+
var CARD_MIN_USD = 0.5;
|
|
840
|
+
var CARD_MAX_USD = 999.99;
|
|
815
841
|
var PlatformCommerceServer = class {
|
|
816
842
|
constructor(http, auth) {
|
|
817
843
|
this.http = http;
|
|
@@ -824,19 +850,19 @@ var PlatformCommerceServer = class {
|
|
|
824
850
|
*
|
|
825
851
|
* - `fundingSource: "balance"` → settles synchronously; result `status:"success"` with
|
|
826
852
|
* `newBalance`/`financialBreakdown`. `totalPrice` is the tenant's network-currency amount.
|
|
827
|
-
* - `fundingSource: "card"` → result `status:"requires_payment"` + `
|
|
828
|
-
*
|
|
829
|
-
*
|
|
830
|
-
*
|
|
831
|
-
*
|
|
832
|
-
*
|
|
833
|
-
*
|
|
853
|
+
* - `fundingSource: "card"` → result `status:"requires_payment"` + `checkoutUrl`/`sessionId`.
|
|
854
|
+
* Send the buyer to `checkoutUrl` — INVO's hosted page owns the card form, wallets,
|
|
855
|
+
* billing address, and 3-D Secure (there is NO billing address in this request, and no
|
|
856
|
+
* client payment code to write; optionally embed via
|
|
857
|
+
* `InvoClient.platformCommerce.mountCheckout`). `totalPrice` is USD ($0.50–$999.99).
|
|
858
|
+
* The sale is real only on the `platform_commerce.purchased` webhook — never on the
|
|
859
|
+
* client return.
|
|
834
860
|
*
|
|
835
|
-
*
|
|
836
|
-
*
|
|
837
|
-
*
|
|
838
|
-
*
|
|
839
|
-
*
|
|
861
|
+
* Idempotency on `clientRequestId`: the balance leg throws a 409
|
|
862
|
+
* (`err.isDuplicateRequest`) on a duplicate; the card leg REPLAYS the same checkout
|
|
863
|
+
* session (`idempotentReplay: true`) — a lost response is safely recovered by retrying
|
|
864
|
+
* with the SAME `clientRequestId`. A non-platform tenant throws
|
|
865
|
+
* `err.isNotPlatformTenant` (403).
|
|
840
866
|
*/
|
|
841
867
|
async purchase(input, opts) {
|
|
842
868
|
const required = [
|
|
@@ -867,7 +893,20 @@ var PlatformCommerceServer = class {
|
|
|
867
893
|
);
|
|
868
894
|
}
|
|
869
895
|
if (input.fundingSource === "card") {
|
|
870
|
-
|
|
896
|
+
if (total < CARD_MIN_USD) {
|
|
897
|
+
throw new InvoError({
|
|
898
|
+
message: `Card purchases must be at least $${CARD_MIN_USD.toFixed(2)}.`,
|
|
899
|
+
code: "BELOW_STRIPE_MINIMUM",
|
|
900
|
+
status: 0
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
if (total > CARD_MAX_USD) {
|
|
904
|
+
throw new InvoError({
|
|
905
|
+
message: `Card purchases must be $${CARD_MAX_USD} or less.`,
|
|
906
|
+
code: "ABOVE_CARD_MAXIMUM",
|
|
907
|
+
status: 0
|
|
908
|
+
});
|
|
909
|
+
}
|
|
871
910
|
}
|
|
872
911
|
if (input.playerPhone !== void 0) assertE164(input.playerPhone, "playerPhone");
|
|
873
912
|
const body = {
|
|
@@ -884,31 +923,37 @@ var PlatformCommerceServer = class {
|
|
|
884
923
|
if (input.playerPhone) body["player_phone"] = input.playerPhone;
|
|
885
924
|
if (input.itemDescription) body["item_description"] = input.itemDescription;
|
|
886
925
|
if (input.itemCategory) body["item_category"] = input.itemCategory;
|
|
887
|
-
if (input.
|
|
926
|
+
if (input.successUrl) body["success_url"] = input.successUrl;
|
|
927
|
+
if (input.cancelUrl) body["cancel_url"] = input.cancelUrl;
|
|
928
|
+
if (input.metadata) body["metadata"] = input.metadata;
|
|
888
929
|
const raw = await this.http.post(
|
|
889
930
|
"/api/platform-commerce/purchase",
|
|
890
931
|
body,
|
|
891
932
|
this.auth,
|
|
933
|
+
// Safe to retry: balance dedupes (dup → 409); card REPLAYS the same session.
|
|
892
934
|
{ idempotent: true, signal: opts?.signal }
|
|
893
|
-
// client_request_id makes this safe to retry (dup → 409)
|
|
894
935
|
);
|
|
895
|
-
const orderIdRaw = raw["order_id"];
|
|
896
|
-
requireField(orderIdRaw, "order_id", raw);
|
|
897
936
|
const status = String(raw["status"] ?? "");
|
|
898
|
-
if (status === "requires_payment"
|
|
899
|
-
requireField(raw["
|
|
937
|
+
if (status === "requires_payment") {
|
|
938
|
+
requireField(raw["checkout_url"], "checkout_url", raw);
|
|
939
|
+
} else {
|
|
940
|
+
requireField(raw["order_id"], "order_id", raw);
|
|
900
941
|
}
|
|
942
|
+
const expiresAtRaw = raw["expires_at"];
|
|
901
943
|
return {
|
|
902
944
|
status,
|
|
903
945
|
fundingSource: String(raw["funding_source"] ?? input.fundingSource),
|
|
904
|
-
orderId:
|
|
946
|
+
orderId: raw["order_id"] ?? void 0,
|
|
905
947
|
transactionId: raw["transaction_id"],
|
|
906
948
|
newBalance: raw["new_balance"] ?? null,
|
|
907
949
|
previousBalance: raw["previous_balance"] ?? null,
|
|
908
950
|
currencyName: raw["currency_name"],
|
|
909
951
|
financialBreakdown: raw["financial_breakdown"],
|
|
910
|
-
|
|
952
|
+
sessionId: raw["session_id"],
|
|
953
|
+
checkoutUrl: raw["checkout_url"],
|
|
954
|
+
expiresAt: typeof expiresAtRaw === "number" ? expiresAtRaw : void 0,
|
|
911
955
|
amountUsd: raw["amount_usd"] ?? null,
|
|
956
|
+
idempotentReplay: raw["idempotent_replay"] === true,
|
|
912
957
|
raw
|
|
913
958
|
};
|
|
914
959
|
}
|
|
@@ -1444,10 +1489,22 @@ var InvoServer = class {
|
|
|
1444
1489
|
};
|
|
1445
1490
|
}
|
|
1446
1491
|
/**
|
|
1447
|
-
* Complete a TRANSFER's SMS-PIN step
|
|
1448
|
-
*
|
|
1449
|
-
*
|
|
1450
|
-
*
|
|
1492
|
+
* Complete a TRANSFER's SMS-PIN step — the LAST-RESORT fallback for a sender who has
|
|
1493
|
+
* no passkey.
|
|
1494
|
+
*
|
|
1495
|
+
* @deprecated The SMS-PIN path is being phased out and a future major version will
|
|
1496
|
+
* remove this method. **Passkeys are the gold standard for authorizing money movement**
|
|
1497
|
+
* — an SMS PIN is a shared secret on a channel exposed to SIM swap and interception,
|
|
1498
|
+
* and it is not a peer of a WebAuthn assertion. When `initiate*` returns
|
|
1499
|
+
* `verificationMethod: "sms"` it is telling you the sender has no passkey: prompt
|
|
1500
|
+
* `InvoClient.enrollPasskey()` and then approve with
|
|
1501
|
+
* `InvoClient.approveTransfer(transactionId)`. Reach for this method only when the user
|
|
1502
|
+
* cannot enroll (unsupported device) or declines. Still fully functional — this
|
|
1503
|
+
* annotation changes documentation only, not behavior.
|
|
1504
|
+
*
|
|
1505
|
+
* NOT idempotent — each attempt is counted server-side, so this is never auto-retried.
|
|
1506
|
+
* A bad PIN throws a 400 InvoError carrying `attempts_remaining` on `err.body`; a
|
|
1507
|
+
* blocked recipient throws 429 (`sms_verification_blocked`).
|
|
1451
1508
|
*/
|
|
1452
1509
|
async verifySmsTransfer(transactionId, smsPin, opts) {
|
|
1453
1510
|
if (typeof transactionId !== "string" || !transactionId.trim()) {
|
|
@@ -1465,7 +1522,15 @@ var InvoServer = class {
|
|
|
1465
1522
|
);
|
|
1466
1523
|
return toSmsVerifyResult(raw);
|
|
1467
1524
|
}
|
|
1468
|
-
/**
|
|
1525
|
+
/**
|
|
1526
|
+
* Complete a SEND's SMS-PIN step — the LAST-RESORT fallback for a sender who has no
|
|
1527
|
+
* passkey. See {@link verifySmsTransfer}.
|
|
1528
|
+
*
|
|
1529
|
+
* @deprecated The SMS-PIN path is being phased out and a future major version will
|
|
1530
|
+
* remove this method. Prompt `InvoClient.enrollPasskey()` and approve with
|
|
1531
|
+
* `InvoClient.approveSend(transactionId)` instead; use this only when the user cannot
|
|
1532
|
+
* enroll or declines. Documentation only — behavior is unchanged.
|
|
1533
|
+
*/
|
|
1469
1534
|
async verifySmsSend(transactionId, smsPin, opts) {
|
|
1470
1535
|
if (typeof transactionId !== "string" || !transactionId.trim()) {
|
|
1471
1536
|
throw invalidInput("transactionId", transactionId, "is required");
|