@ilands/payments 0.1.0-next.0 → 0.1.0-next.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/dist/base44.d.ts +1 -1
- package/dist/base44.js +8 -7
- package/dist/client.d.ts +12 -1
- package/dist/client.js +30 -13
- package/package.json +1 -1
package/dist/base44.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Passed into Base44's `customInstructions` field when creating a site and
|
|
6
6
|
* verified via read-back before allowing live payments.
|
|
7
7
|
*/
|
|
8
|
-
export declare const BASE44_PAYMENT_INSTRUCTIONS_VERSION = "2026-11-
|
|
8
|
+
export declare const BASE44_PAYMENT_INSTRUCTIONS_VERSION = "2026-11-27.v1";
|
|
9
9
|
export declare function buildBase44PaymentInstructions(options?: {
|
|
10
10
|
apiBaseUrl?: string;
|
|
11
11
|
webhookPath?: string;
|
package/dist/base44.js
CHANGED
|
@@ -5,22 +5,23 @@
|
|
|
5
5
|
* Passed into Base44's `customInstructions` field when creating a site and
|
|
6
6
|
* verified via read-back before allowing live payments.
|
|
7
7
|
*/
|
|
8
|
-
export const BASE44_PAYMENT_INSTRUCTIONS_VERSION = "2026-11-
|
|
8
|
+
export const BASE44_PAYMENT_INSTRUCTIONS_VERSION = "2026-11-27.v1";
|
|
9
9
|
export function buildBase44PaymentInstructions(options) {
|
|
10
10
|
const apiBaseUrl = options?.apiBaseUrl ?? "https://staging-edge.ilands.ai";
|
|
11
11
|
const webhookPath = options?.webhookPath ?? "/api/ilands-payments-webhook";
|
|
12
12
|
return [
|
|
13
13
|
`# iLands Payment SDK Integration Rules (${BASE44_PAYMENT_INSTRUCTIONS_VERSION})`,
|
|
14
14
|
"",
|
|
15
|
-
"Use `@ilands/payments` (`@ilands/payments/server` in backend functions, `@ilands/payments/client` in frontend pages) to accept card payments via iLands.",
|
|
15
|
+
"Use `@ilands/payments` (`@ilands/payments/server` in server API routes / backend functions, `@ilands/payments/client` in frontend pages) to accept card payments via iLands.",
|
|
16
16
|
"",
|
|
17
17
|
"## Mandatory Security & Reliability Invariants",
|
|
18
|
-
"1. **Server-side pricing only**: The browser MUST send only product/item IDs and quantities.
|
|
19
|
-
"2. **Secrets stay
|
|
18
|
+
"1. **Server-side pricing only**: The browser MUST send only product/item IDs and quantities. Server routes / backend functions MUST look up prices in the site database, create a local order row (`status: 'pending'`), and compute integer `amountCents` on the server. NEVER trust client-supplied prices or totals.",
|
|
19
|
+
"2. **Secrets stay on the server**: Read `ILANDS_PAYMENT_SECRET_KEY`, `ILANDS_PAYMENT_WEBHOOK_SECRET`, and `ILANDS_PAYMENT_API_BASE_URL` ONLY inside server API routes (`process.env.*` in Base44 TanStack Start) or legacy Deno backend functions (`Deno.env.get(...)`). Pass `baseUrl` from `ILANDS_PAYMENT_API_BASE_URL` to `createILandsPayments(...)`. NEVER hardcode keys, expose them to frontend code, or call Stripe directly.",
|
|
20
20
|
"3. **Freeze immutable terms before checkout**: Always pass complete `terms` (`title`, `deliveryType`, `deliverySummary`, `refundPolicy`) and your local `merchantOrderId` to `ilands.payments.create(...)`. Never overwrite historical order terms when editing catalog descriptions later.",
|
|
21
|
-
`4. **Authoritative fulfillment only**: NEVER deliver files or grant entitlements based on return URL query parameters.
|
|
22
|
-
"5. **Idempotent delivery & evidence reporting**: Deduplicate fulfillment by `paymentId`. After delivering, ALWAYS call `ilands.deliveries.report(paymentId, ...)` (and for downloadable files, first upload an immutable copy via `ilands.deliveries.uploadArtifact(paymentId,
|
|
23
|
-
"6. **Guest recovery &
|
|
21
|
+
`4. **Authoritative fulfillment only**: NEVER deliver files or grant entitlements based on return URL query parameters. Mount the webhook handler at \`${webhookPath}\` (TanStack Start server route by default, or legacy Deno backend function if upgrading a Vite SPA app), verify the raw request body via \`ilands.webhooks.verifyAndParse({ rawBody, signatureHeader })\`, and return HTTP 400 on missing or invalid signatures. Deliver ONLY after verified webhook delivery OR after your server calls \`ilands.payments.get(paymentId)\` and confirms \`status === "paid"\` with matching \`amountCents\` and \`merchantOrderId\`.`,
|
|
22
|
+
"5. **Idempotent delivery & evidence reporting**: Deduplicate fulfillment by `paymentId`. After delivering, ALWAYS call `ilands.deliveries.report(paymentId, ...)` (and for downloadable files, first upload an immutable copy via `ilands.deliveries.uploadArtifact(paymentId, { filename, contentType, bytes })`). Handle `payment.refunded` and `payment.dispute.closed` by revoking or adjusting entitlements.",
|
|
23
|
+
"6. **Guest recovery, mobile WebView & zero token leaks**: Persist the `receiptUrl` returned by `ilands.payments.create(...)` on your server order record and expose it to buyers on the order confirmation page so guests can recover orders and access iLands support without relying on browser localStorage. Always use `openCheckout` and `openReceipt` from `@ilands/payments/client` (`>= 0.1.0-next.1`) and avoid `target=\"_blank\"` on checkout, receipt, or file download actions so iLands mobile App WebView users never get stuck. NEVER print `guestAccessToken`, full `receiptUrl?token=...`, or raw payment creation responses to console logs.",
|
|
24
|
+
`7. **Coexistence with \`@ilands/auth-*\` & \`*.ilands.world\` domains**: Keep \`${webhookPath}\` publicly reachable for signed \`POST\` requests authenticated ONLY via \`X-iLands-Signature\` (NEVER require user login/Bearer token on the webhook route). Build \`returnUrl\` and \`cancelUrl\` from the site's canonical origin (e.g. \`https://<slug>.ilands.world\`) so returning from Stripe Checkout stays on the same authenticated origin. For signed-in buyers, pass server-verified \`buyer: { siteUserId, email }\` and verify ownership server-side before returning orders or downloads (never trust unverified client \`userId\`).`,
|
|
24
25
|
"",
|
|
25
26
|
`API Base URL: \`${apiBaseUrl}\``,
|
|
26
27
|
].join("\n");
|
package/dist/client.d.ts
CHANGED
|
@@ -15,9 +15,20 @@ export interface OpenCheckoutOptions {
|
|
|
15
15
|
/**
|
|
16
16
|
* Open Stripe Hosted Checkout safely in standalone browsers or embedded
|
|
17
17
|
* inside the iLands mobile WebView.
|
|
18
|
+
*
|
|
19
|
+
* Only delegates to a native bridge when the host explicitly exposes
|
|
20
|
+
* `window.ilands.openExternalUrl`. Never suppresses navigation solely because
|
|
21
|
+
* `window.ReactNativeWebView.postMessage` exists — the iLands mobile WebView
|
|
22
|
+
* loads HTTPS Stripe Checkout URLs directly in the same view and returns to
|
|
23
|
+
* `returnUrl` automatically.
|
|
18
24
|
*/
|
|
19
25
|
export declare function openCheckout(options: OpenCheckoutOptions): void;
|
|
20
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Open the canonical iLands transaction receipt & after-sales support page.
|
|
28
|
+
*
|
|
29
|
+
* Uses same-view navigation inside embedded mobile WebViews because `_blank`
|
|
30
|
+
* popups are not supported by default in iOS WKWebView / Android WebView.
|
|
31
|
+
*/
|
|
21
32
|
export declare function openReceipt(receiptUrl: string): void;
|
|
22
33
|
export interface PollOrderStatusOptions<T> {
|
|
23
34
|
/** Calls YOUR website backend (which checks DB or falls back to `ilands.payments.get`). */
|
package/dist/client.js
CHANGED
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
* It opens the Stripe Hosted Checkout URL returned by the website's own backend
|
|
7
7
|
* and polls the website's backend to observe authoritative fulfillment state.
|
|
8
8
|
*/
|
|
9
|
+
function isEmbeddedWebView(win) {
|
|
10
|
+
return typeof win.ReactNativeWebView?.postMessage === "function";
|
|
11
|
+
}
|
|
9
12
|
function assertSafeCheckoutUrl(raw) {
|
|
10
13
|
let parsed;
|
|
11
14
|
try {
|
|
@@ -39,22 +42,22 @@ function assertSafeReceiptUrl(raw) {
|
|
|
39
42
|
/**
|
|
40
43
|
* Open Stripe Hosted Checkout safely in standalone browsers or embedded
|
|
41
44
|
* inside the iLands mobile WebView.
|
|
45
|
+
*
|
|
46
|
+
* Only delegates to a native bridge when the host explicitly exposes
|
|
47
|
+
* `window.ilands.openExternalUrl`. Never suppresses navigation solely because
|
|
48
|
+
* `window.ReactNativeWebView.postMessage` exists — the iLands mobile WebView
|
|
49
|
+
* loads HTTPS Stripe Checkout URLs directly in the same view and returns to
|
|
50
|
+
* `returnUrl` automatically.
|
|
42
51
|
*/
|
|
43
52
|
export function openCheckout(options) {
|
|
44
53
|
const safeUrl = assertSafeCheckoutUrl(options.checkoutUrl);
|
|
45
54
|
const win = window;
|
|
46
55
|
const mode = options.mode ?? "auto";
|
|
47
|
-
if (mode === "auto") {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
if (typeof win.ReactNativeWebView?.postMessage === "function") {
|
|
53
|
-
win.ReactNativeWebView.postMessage(JSON.stringify({ type: "ilands.payments.open_checkout", url: safeUrl }));
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
+
if (mode === "auto" && typeof win.ilands?.openExternalUrl === "function") {
|
|
57
|
+
win.ilands.openExternalUrl(safeUrl);
|
|
58
|
+
return;
|
|
56
59
|
}
|
|
57
|
-
if (mode === "new_tab") {
|
|
60
|
+
if (mode === "new_tab" && !isEmbeddedWebView(win)) {
|
|
58
61
|
const opened = win.open(safeUrl, "_blank", "noopener,noreferrer");
|
|
59
62
|
if (!opened) {
|
|
60
63
|
win.location.assign(safeUrl);
|
|
@@ -63,12 +66,26 @@ export function openCheckout(options) {
|
|
|
63
66
|
}
|
|
64
67
|
win.location.assign(safeUrl);
|
|
65
68
|
}
|
|
66
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Open the canonical iLands transaction receipt & after-sales support page.
|
|
71
|
+
*
|
|
72
|
+
* Uses same-view navigation inside embedded mobile WebViews because `_blank`
|
|
73
|
+
* popups are not supported by default in iOS WKWebView / Android WebView.
|
|
74
|
+
*/
|
|
67
75
|
export function openReceipt(receiptUrl) {
|
|
68
76
|
const safeUrl = assertSafeReceiptUrl(receiptUrl);
|
|
69
|
-
const
|
|
77
|
+
const win = window;
|
|
78
|
+
if (typeof win.ilands?.openExternalUrl === "function") {
|
|
79
|
+
win.ilands.openExternalUrl(safeUrl);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (isEmbeddedWebView(win)) {
|
|
83
|
+
win.location.assign(safeUrl);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const opened = win.open(safeUrl, "_blank", "noopener,noreferrer");
|
|
70
87
|
if (!opened) {
|
|
71
|
-
|
|
88
|
+
win.location.assign(safeUrl);
|
|
72
89
|
}
|
|
73
90
|
}
|
|
74
91
|
/**
|