@base44-preview/sdk 0.8.63-pr.388.2dbcc27 → 0.8.63-pr.390.31c1120
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/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type { AppModule, AppPublicSettings, AppPublicSettingsResponse, } from ".
|
|
|
15
15
|
export type { McpModule, McpConsentAction, McpConsentInfo, McpConsentResponse, McpConsentTool, } from "./modules/mcp.types.js";
|
|
16
16
|
export type { ActorsModule, ActorClient, ActorRef, Connection, ActorSubscription, ActorConnectOptions, ActorNameRegistry, ActorRegistry, ActorConnectable, ActorMethods, ServiceRoleActorRef, ServiceRoleActorsModule, } from "./modules/actors.types.js";
|
|
17
17
|
export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
|
|
18
|
-
export type { PaymentsModule, ServiceRolePaymentsModule, PaymentsErrorCode, PaymentsRecurringFrequency, CheckoutBuyer, CheckoutFreeTrial, CheckoutItem, CheckoutItemRecurring, CheckoutPresentation, CheckoutShipping, CheckoutElement, CheckoutMount, MountableCheckout, CreateCheckoutParams, CreateCheckoutResult, CompleteCheckoutResult, EmbeddedCheckout, PayPalCheckoutOnClick, PayPalEmbeddedCheckout, StripeEmbeddedCheckout, MountCheckoutOptions, ListPurchasesParams, ServiceRoleListPurchasesParams, ListPurchasesResult, Purchase, PurchaseItem, PurchaseStatus, RefundParams, ShippingAddress, RefundResult, CancelSubscriptionOptions, SubscriptionResult, } from "./modules/payments.types.js";
|
|
18
|
+
export type { PaymentsModule, ServiceRolePaymentsModule, PaymentsErrorCode, PaymentsRecurringFrequency, CheckoutBuyer, CheckoutFreeTrial, CheckoutItem, CheckoutItemRecurring, CheckoutPresentation, CheckoutShipping, CheckoutElement, CheckoutMount, MountableCheckout, CreateCheckoutParams, CreateCheckoutResult, CompleteCheckoutResult, EmbeddedCheckout, PayPalCheckoutOnClick, PayPalEmbeddedCheckout, StripeEmbeddedCheckout, WixEmbeddedCheckout, MountCheckoutOptions, ListPurchasesParams, ServiceRoleListPurchasesParams, ListPurchasesResult, Purchase, PurchaseItem, PurchaseStatus, RefundParams, ShippingAddress, RefundResult, CancelSubscriptionOptions, SubscriptionResult, } from "./modules/payments.types.js";
|
|
19
19
|
export type { BrowserModule, BrowserSession, BrowserSessionOptions, } from "./modules/browser.types.js";
|
|
20
20
|
export type { VoiceModule, VoiceSession, VoiceSessionMessage, VoiceSessionOptions, } from "./modules/voice.types.js";
|
|
21
21
|
export { Actor, type Conn, type ActorConnectionIdentity, ActorError, type ActorCallIdentity, type ActorCallContext, } from "./actor.js";
|
|
@@ -13,6 +13,9 @@ export interface PaymentsCheckoutConfig {
|
|
|
13
13
|
stripe?: {
|
|
14
14
|
script_url?: string;
|
|
15
15
|
};
|
|
16
|
+
wix?: {
|
|
17
|
+
script_url?: string;
|
|
18
|
+
};
|
|
16
19
|
}
|
|
17
20
|
type PayPalButtonConfig = Pick<PayPalEmbeddedCheckout, "client_id" | "merchant_id" | "partner_attribution_id">;
|
|
18
21
|
/** @internal */
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const ALLOWED_SCRIPT_HOSTS = {
|
|
3
3
|
paypal: ["www.paypal.com", "www.sandbox.paypal.com"],
|
|
4
4
|
stripe: ["js.stripe.com"],
|
|
5
|
+
wix: ["tpa.wixapps.net"],
|
|
5
6
|
};
|
|
6
7
|
async function scriptUrlFor(provider, deps) {
|
|
7
8
|
var _a, _b;
|
|
@@ -19,7 +20,7 @@ async function scriptUrlFor(provider, deps) {
|
|
|
19
20
|
url.username !== "" ||
|
|
20
21
|
url.password !== "" ||
|
|
21
22
|
!ALLOWED_SCRIPT_HOSTS[provider].includes(url.hostname)) {
|
|
22
|
-
const name =
|
|
23
|
+
const name = { paypal: "PayPal", stripe: "Stripe", wix: "Wix" }[provider];
|
|
23
24
|
throw new Error(`The payments config has no valid ${name} script URL`);
|
|
24
25
|
}
|
|
25
26
|
return url.href;
|
|
@@ -236,6 +237,84 @@ checkout, options, deps) {
|
|
|
236
237
|
},
|
|
237
238
|
};
|
|
238
239
|
}
|
|
240
|
+
async function mountWix(element, scriptUrl, checkoutId, embedded, options, deps) {
|
|
241
|
+
var _a;
|
|
242
|
+
const wpe = await loadGlobal(scriptUrl, () => browserGlobals().wpe, deps.loadScript);
|
|
243
|
+
const locale = (((_a = document.documentElement) === null || _a === void 0 ? void 0 : _a.lang) || navigator.language || "en").split("-")[0];
|
|
244
|
+
const paymentElement = wpe(embedded.client_id, { locale }).create("checkout", {
|
|
245
|
+
intentId: embedded.order_id,
|
|
246
|
+
});
|
|
247
|
+
const box = document.createElement("div");
|
|
248
|
+
element.appendChild(box);
|
|
249
|
+
try {
|
|
250
|
+
await paymentElement.mount(box);
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
box.remove();
|
|
254
|
+
paymentElement.destroy();
|
|
255
|
+
throw error;
|
|
256
|
+
}
|
|
257
|
+
let destroyed = false;
|
|
258
|
+
let paying = false;
|
|
259
|
+
let paid = false;
|
|
260
|
+
// What the app last passed to setDisabled().
|
|
261
|
+
let disabled = false;
|
|
262
|
+
const notify = (callback) => {
|
|
263
|
+
if (destroyed)
|
|
264
|
+
return;
|
|
265
|
+
try {
|
|
266
|
+
callback();
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
console.error("[Base44 SDK] A mountCheckout() callback threw", error);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
const button = document.createElement("button");
|
|
273
|
+
button.type = "button";
|
|
274
|
+
button.className = "base44-checkout-pay";
|
|
275
|
+
button.textContent = "Pay";
|
|
276
|
+
const onClick = () => {
|
|
277
|
+
if (paying || paid || disabled)
|
|
278
|
+
return;
|
|
279
|
+
paying = true;
|
|
280
|
+
button.disabled = true;
|
|
281
|
+
// The executor runs now, so confirmPayment() is called inside the click, before any await.
|
|
282
|
+
new Promise((resolve) => resolve(paymentElement.confirmPayment()))
|
|
283
|
+
.then(async (status) => {
|
|
284
|
+
if (status !== "succeeded") {
|
|
285
|
+
notify(() => { var _a; return (_a = options.onCancel) === null || _a === void 0 ? void 0 : _a.call(options); });
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
// Runs even after destroy(), so a paid order is still completed.
|
|
289
|
+
const result = await deps.completeCheckout(checkoutId);
|
|
290
|
+
paid = true;
|
|
291
|
+
notify(() => { var _a; return (_a = options.onComplete) === null || _a === void 0 ? void 0 : _a.call(options, result); });
|
|
292
|
+
})
|
|
293
|
+
.catch((error) => notify(() => { var _a; return (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, error); }))
|
|
294
|
+
.finally(() => {
|
|
295
|
+
paying = false;
|
|
296
|
+
button.disabled = paid || disabled;
|
|
297
|
+
});
|
|
298
|
+
};
|
|
299
|
+
button.addEventListener("click", onClick);
|
|
300
|
+
element.appendChild(button);
|
|
301
|
+
return {
|
|
302
|
+
destroy() {
|
|
303
|
+
if (destroyed)
|
|
304
|
+
return;
|
|
305
|
+
destroyed = true;
|
|
306
|
+
button.removeEventListener("click", onClick);
|
|
307
|
+
button.remove();
|
|
308
|
+
box.remove();
|
|
309
|
+
paymentElement.destroy();
|
|
310
|
+
},
|
|
311
|
+
setDisabled(value) {
|
|
312
|
+
disabled = value;
|
|
313
|
+
if (!paying && !paid)
|
|
314
|
+
button.disabled = value;
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
}
|
|
239
318
|
/** The new checkout's id, refused unless it is the checkout the button was drawn for. */
|
|
240
319
|
function onClickCheckoutId(spec, button) {
|
|
241
320
|
return async () => {
|
|
@@ -291,6 +370,8 @@ export async function mountCheckout(element, checkout, options, deps) {
|
|
|
291
370
|
return mountStripe(element, await scriptUrlFor("stripe", deps), embedded, deps);
|
|
292
371
|
case "paypal":
|
|
293
372
|
return mountPayPal(element, await scriptUrlFor("paypal", deps), checkout.currency, embedded, checkout.checkout_id, options, deps);
|
|
373
|
+
case "wix":
|
|
374
|
+
return mountWix(element, await scriptUrlFor("wix", deps), checkout.checkout_id, embedded, options, deps);
|
|
294
375
|
default:
|
|
295
376
|
throw new Error(`Embedded checkout isn't supported for provider ${embedded.provider}`);
|
|
296
377
|
}
|
|
@@ -111,7 +111,7 @@ export interface CreateCheckoutParams {
|
|
|
111
111
|
metadata?: Record<string, string>;
|
|
112
112
|
/** Key that makes retries return the same checkout instead of creating another, 1 to 200 characters. Not supported for Base44 Payments or PayPal subscriptions. */
|
|
113
113
|
idempotency_key?: string;
|
|
114
|
-
/** How the buyer pays. Defaults to `'redirect'`. PayPal apps must pass `'embedded'
|
|
114
|
+
/** How the buyer pays. Defaults to `'redirect'`. PayPal apps must pass `'embedded'`. */
|
|
115
115
|
presentation?: CheckoutPresentation;
|
|
116
116
|
/**
|
|
117
117
|
* Shipping address and fee. Allowed only when at least one item is `shippable`. Supported for PayPal one-time checkouts only. Other providers and subscriptions reject it with [`invalid_request`](#paymentserrorcode).
|
|
@@ -146,10 +146,21 @@ export interface PayPalEmbeddedCheckout {
|
|
|
146
146
|
/** Whether the checkout is a one-time payment or a subscription. */
|
|
147
147
|
intent: "capture" | "subscription";
|
|
148
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Data that the Wix Payment Element needs to render, for Base44 Payments.
|
|
151
|
+
*/
|
|
152
|
+
export interface WixEmbeddedCheckout {
|
|
153
|
+
/** Payment provider. */
|
|
154
|
+
provider: "wix";
|
|
155
|
+
/** Client ID the payment element signs in with. */
|
|
156
|
+
client_id: string;
|
|
157
|
+
/** ID of the order the buyer pays. */
|
|
158
|
+
order_id: string;
|
|
159
|
+
}
|
|
149
160
|
/**
|
|
150
161
|
* Data that an embedded checkout needs to render, by provider.
|
|
151
162
|
*/
|
|
152
|
-
export type EmbeddedCheckout = StripeEmbeddedCheckout | PayPalEmbeddedCheckout;
|
|
163
|
+
export type EmbeddedCheckout = StripeEmbeddedCheckout | PayPalEmbeddedCheckout | WixEmbeddedCheckout;
|
|
153
164
|
/**
|
|
154
165
|
* Result of [`createCheckout()`](#createcheckout).
|
|
155
166
|
*
|
|
@@ -316,17 +327,17 @@ export type PaymentsErrorCode = "forbidden" | "unauthenticated" | "not_found" |
|
|
|
316
327
|
*/
|
|
317
328
|
export interface MountCheckoutOptions {
|
|
318
329
|
/**
|
|
319
|
-
* Called after the buyer approves a PayPal payment and the SDK completes the checkout. Use it to update the page, not to grant access.
|
|
330
|
+
* Called after the buyer approves a PayPal payment, or pays with Base44 Payments, and the SDK completes the checkout. Use it to update the page, not to grant access.
|
|
320
331
|
*
|
|
321
332
|
* Stripe doesn't call this. After a Stripe payment, the buyer returns to the checkout's `success_path` with a `session_id` query parameter. That parameter is the `checkout_id`. Show the result there with [`listPurchases()`](#listpurchases).
|
|
322
333
|
*/
|
|
323
334
|
onComplete?: (result: CompleteCheckoutResult) => void;
|
|
324
|
-
/** Called when the buyer closes the PayPal window without paying. The button stays mounted so the buyer can try again. */
|
|
335
|
+
/** Called when the buyer closes the PayPal window without paying, or when a Base44 Payments payment doesn't go through, a declined one included. The button stays mounted so the buyer can try again. */
|
|
325
336
|
onCancel?: () => void;
|
|
326
337
|
/**
|
|
327
|
-
* Called when a PayPal checkout fails after it's mounted
|
|
338
|
+
* Called when a PayPal or Base44 Payments checkout fails after it's mounted. The button stays mounted so the buyer can try again. For PayPal this includes a declined payment with the [`payment_declined`](#paymentserrorcode) code. If it keeps failing with `payment_declined`, create a new checkout and mount it. A declined Base44 Payments payment calls `onCancel` instead. Stripe shows its own errors inside the checkout.
|
|
328
339
|
*
|
|
329
|
-
* The error is a `Base44Error` when completing the checkout fails, or
|
|
340
|
+
* The error is a `Base44Error` when completing the checkout fails, or the provider's own error object when the PayPal window or the Wix Payment Element fails.
|
|
330
341
|
*/
|
|
331
342
|
onError?: (error: unknown) => void;
|
|
332
343
|
}
|
|
@@ -371,7 +382,7 @@ export interface PayPalCheckoutOnClick {
|
|
|
371
382
|
export interface CheckoutMount {
|
|
372
383
|
/** Removes the checkout from the page. Call it when the component that holds it unmounts. For Stripe, mounting another checkout destroys this one for you. */
|
|
373
384
|
destroy: () => void;
|
|
374
|
-
/** Grays out PayPal
|
|
385
|
+
/** Grays out the PayPal or Base44 Payments button and ignores clicks, for example until a required form is filled in. After a payment completes the button stays off, so `setDisabled(false)` can't start a second payment. Stripe ignores it. */
|
|
375
386
|
setDisabled: (disabled: boolean) => void;
|
|
376
387
|
}
|
|
377
388
|
/**
|
|
@@ -391,7 +402,7 @@ export interface CheckoutMount {
|
|
|
391
402
|
* | | Stripe | PayPal | Base44 Payments |
|
|
392
403
|
* | :- | :- | :- | :- |
|
|
393
404
|
* | Redirect checkout | Yes | No | Yes |
|
|
394
|
-
* | Embedded checkout | Yes | Yes, required |
|
|
405
|
+
* | Embedded checkout | Yes | Yes, required | Yes |
|
|
395
406
|
* | Refunds | Yes | Yes | No |
|
|
396
407
|
* | Subscription cancellation | Yes, now or at period end | Yes, now only | No |
|
|
397
408
|
* | Subscription pause and resume | Yes | Yes | No |
|
|
@@ -400,7 +411,7 @@ export interface CheckoutMount {
|
|
|
400
411
|
*
|
|
401
412
|
* This module is available to use with a client in all authentication modes:
|
|
402
413
|
*
|
|
403
|
-
* - **Anonymous or user authentication** (`base44.payments`): Preloads and mounts embedded checkouts, completes PayPal checkouts, and lists the current user's own purchases.
|
|
414
|
+
* - **Anonymous or user authentication** (`base44.payments`): Preloads and mounts embedded checkouts, completes PayPal and embedded Base44 Payments checkouts, and lists the current user's own purchases.
|
|
404
415
|
* - **Service role authentication** (`base44.asServiceRole.payments`): Creates checkouts, lists any purchase, refunds payments, and changes subscriptions. Use the [service role methods](#service-role-methods) in backend functions.
|
|
405
416
|
*
|
|
406
417
|
* @groupDescription Methods
|
|
@@ -432,8 +443,9 @@ export interface PaymentsModule {
|
|
|
432
443
|
* The SDK loads the provider's library and renders the checkout for you:
|
|
433
444
|
* - PayPal: Renders a PayPal button. When the buyer approves the payment, the SDK calls {@linkcode completeCheckout | completeCheckout()} and then `onComplete`.
|
|
434
445
|
* - Stripe: Mounts Stripe Embedded Checkout. After paying, the buyer returns to the checkout's `success_path`. Stripe allows one embedded checkout per page, so mounting another Stripe checkout destroys the previous one.
|
|
446
|
+
* - Base44 Payments: Renders the Wix Payment Element and a **Pay** button below it. Style the button with its `base44-checkout-pay` class. When the payment succeeds, the SDK calls {@linkcode completeCheckout | completeCheckout()} and then `onComplete`.
|
|
435
447
|
*
|
|
436
|
-
*
|
|
448
|
+
* For PayPal and Stripe, to make the checkout appear faster, load the library ahead of time with [`preloadCheckout()`](#preloadcheckout) when the page opens.
|
|
437
449
|
*
|
|
438
450
|
* Requires a browser environment and can't be used in the backend. Rejects when the checkout isn't embedded, when an on-click PayPal checkout is mounted before the app's PayPal can take payments, when the payments config can't be fetched or has no valid script URL for the provider, when the provider's library fails to load, or when PayPal isn't available for the checkout's currency.
|
|
439
451
|
*
|
|
@@ -507,11 +519,11 @@ export interface PaymentsModule {
|
|
|
507
519
|
*/
|
|
508
520
|
mountCheckout(element: CheckoutElement, checkout: MountableCheckout | PayPalCheckoutOnClick, options?: MountCheckoutOptions): Promise<CheckoutMount>;
|
|
509
521
|
/**
|
|
510
|
-
* Completes a PayPal checkout after the buyer
|
|
522
|
+
* Completes a PayPal or embedded Base44 Payments checkout after the buyer pays.
|
|
511
523
|
*
|
|
512
524
|
* When you use {@linkcode mountCheckout | mountCheckout()}, it calls this for you. Call it directly only if you render your own PayPal button. Calling it again for the same checkout returns the same result.
|
|
513
525
|
*
|
|
514
|
-
* Only PayPal checkouts need completing. Other
|
|
526
|
+
* Only PayPal and embedded Base44 Payments checkouts need completing. Other checkouts reject with [`complete_not_supported`](#paymentserrorcode).
|
|
515
527
|
*
|
|
516
528
|
* To complete the checkout from a backend function instead, use [`completeCheckout()`](#service-role-methods) with the service role.
|
|
517
529
|
*
|
|
@@ -642,11 +654,11 @@ export interface ServiceRolePaymentsModule {
|
|
|
642
654
|
*/
|
|
643
655
|
createCheckout(params: CreateCheckoutParams): Promise<CreateCheckoutResult>;
|
|
644
656
|
/**
|
|
645
|
-
* Completes a PayPal checkout from a backend function, after the buyer
|
|
657
|
+
* Completes a PayPal or embedded Base44 Payments checkout from a backend function, after the buyer pays.
|
|
646
658
|
*
|
|
647
659
|
* Use it when you render your own PayPal button and its `onApprove` handler sends the checkout ID to your backend. Calling it again for the same checkout returns the same result.
|
|
648
660
|
*
|
|
649
|
-
* Only PayPal checkouts need completing. Other
|
|
661
|
+
* Only PayPal and embedded Base44 Payments checkouts need completing. Other checkouts reject with [`complete_not_supported`](#paymentserrorcode).
|
|
650
662
|
*
|
|
651
663
|
* @param checkoutId - The `checkout_id` from {@linkcode createCheckout | createCheckout()}.
|
|
652
664
|
* @returns Promise resolving to the checkout's payment status.
|