@base44-preview/sdk 0.8.63-pr.391.2760310 → 0.8.63-pr.392.a02dae3
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";
|
|
@@ -97,17 +97,6 @@ export interface AiGatewayModuleConfig {
|
|
|
97
97
|
* request options, the model list, and limits, see
|
|
98
98
|
* [Generate music with the AI Gateway](/developers/references/sdk/getting-started/ai-gateway-music).
|
|
99
99
|
*
|
|
100
|
-
* ## 3D models
|
|
101
|
-
*
|
|
102
|
-
* The gateway also serves a 3D model endpoint, `/3d-models`, so you can turn a
|
|
103
|
-
* text prompt or an image of one object into a textured 3D model. OpenAI has no
|
|
104
|
-
* 3D endpoint, so the request format is Base44's own. 3D generation is
|
|
105
|
-
* synchronous. The request returns the stored GLB file's `url` once the model is
|
|
106
|
-
* ready, which usually takes one to three minutes. Pass `'automatic'` or pin
|
|
107
|
-
* `'hunyuan_3d_v3_1_pro'`, which `automatic` always uses. For request options,
|
|
108
|
-
* the model list, and limits, see
|
|
109
|
-
* [Generate 3D models with the AI Gateway](/developers/references/sdk/getting-started/ai-gateway-3d-models).
|
|
110
|
-
*
|
|
111
100
|
* ## Structured evaluations
|
|
112
101
|
*
|
|
113
102
|
* The `typesafe` provider runs the `jev` evaluation model through
|
|
@@ -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 */
|
|
@@ -30,7 +33,7 @@ export declare const loadScript: LoadScript;
|
|
|
30
33
|
* Fetches the payments config and loads the provider's script ahead of mountCheckout().
|
|
31
34
|
* @internal
|
|
32
35
|
*/
|
|
33
|
-
export declare function preloadCheckout(provider: "paypal" | "stripe", deps: Pick<MountCheckoutDeps, "getConfig" | "loadScript">): Promise<void>;
|
|
36
|
+
export declare function preloadCheckout(provider: "paypal" | "stripe" | "wix", deps: Pick<MountCheckoutDeps, "getConfig" | "loadScript">): Promise<void>;
|
|
34
37
|
/**
|
|
35
38
|
* Mounts the embedded checkout that createCheckout() returned.
|
|
36
39
|
* @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,135 @@ checkout, options, deps) {
|
|
|
236
237
|
},
|
|
237
238
|
};
|
|
238
239
|
}
|
|
240
|
+
const WIX_TOKEN_URL = "https://www.wixapis.com/oauth2/token";
|
|
241
|
+
// Renewed this long before it expires, as the Payment Element does.
|
|
242
|
+
const WIX_TOKEN_MARGIN_MS = 60000;
|
|
243
|
+
// One visitor per client ID for the page, so remounts and other checkouts reuse its token.
|
|
244
|
+
const wixVisitors = new Map();
|
|
245
|
+
async function requestWixTokens(body) {
|
|
246
|
+
const response = await fetch(WIX_TOKEN_URL, {
|
|
247
|
+
method: "POST",
|
|
248
|
+
headers: { "Content-Type": "application/json" },
|
|
249
|
+
body: JSON.stringify(body),
|
|
250
|
+
});
|
|
251
|
+
if (!response.ok) {
|
|
252
|
+
throw new Error(`The Wix ${body.grantType} token request failed with status ${response.status}`);
|
|
253
|
+
}
|
|
254
|
+
const data = (await response.json());
|
|
255
|
+
return {
|
|
256
|
+
accessToken: data.access_token,
|
|
257
|
+
refreshToken: data.refresh_token,
|
|
258
|
+
expiresAt: Date.now() + data.expires_in * 1000,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
async function renewWixTokens(clientId, tokens) {
|
|
262
|
+
if (tokens) {
|
|
263
|
+
try {
|
|
264
|
+
return await requestWixTokens({ refresh_token: tokens.refreshToken, grantType: "refresh_token" });
|
|
265
|
+
}
|
|
266
|
+
catch (_a) {
|
|
267
|
+
// The refresh token expired or was revoked, so a new visitor is minted.
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return requestWixTokens({ clientId, grantType: "anonymous" });
|
|
271
|
+
}
|
|
272
|
+
/** Gives the Payment Element an anonymous visitor's access token for the client. */
|
|
273
|
+
function wixVisitorAccessToken(clientId) {
|
|
274
|
+
return async ({ renew = false } = {}) => {
|
|
275
|
+
var _a, _b;
|
|
276
|
+
const visitor = (_a = wixVisitors.get(clientId)) !== null && _a !== void 0 ? _a : {};
|
|
277
|
+
wixVisitors.set(clientId, visitor);
|
|
278
|
+
// Expired now, so other callers wait for the renewed token instead of getting this one.
|
|
279
|
+
if (renew && visitor.tokens)
|
|
280
|
+
visitor.tokens = { ...visitor.tokens, expiresAt: 0 };
|
|
281
|
+
const { tokens } = visitor;
|
|
282
|
+
if (tokens && tokens.expiresAt - WIX_TOKEN_MARGIN_MS > Date.now()) {
|
|
283
|
+
return tokens.accessToken;
|
|
284
|
+
}
|
|
285
|
+
(_b = visitor.pending) !== null && _b !== void 0 ? _b : (visitor.pending = renewWixTokens(clientId, tokens)
|
|
286
|
+
.then((renewed) => (visitor.tokens = renewed))
|
|
287
|
+
.finally(() => (visitor.pending = undefined)));
|
|
288
|
+
return (await visitor.pending).accessToken;
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
async function mountWix(element, scriptUrl, checkoutId, clientId, options, deps) {
|
|
292
|
+
var _a;
|
|
293
|
+
const wpe = await loadGlobal(scriptUrl, () => browserGlobals().wpe, deps.loadScript);
|
|
294
|
+
const locale = (((_a = document.documentElement) === null || _a === void 0 ? void 0 : _a.lang) || navigator.language || "en").split("-")[0];
|
|
295
|
+
const getAccessToken = wixVisitorAccessToken(clientId);
|
|
296
|
+
const paymentElement = wpe({ getAccessToken, locale }).create("checkout", {
|
|
297
|
+
intentId: checkoutId,
|
|
298
|
+
});
|
|
299
|
+
let destroyed = false;
|
|
300
|
+
let ready = false;
|
|
301
|
+
let paying = false;
|
|
302
|
+
// Set once a payment succeeds or the element rejects one: either way it refuses another.
|
|
303
|
+
let finished = false;
|
|
304
|
+
const notify = (callback) => {
|
|
305
|
+
if (destroyed)
|
|
306
|
+
return;
|
|
307
|
+
try {
|
|
308
|
+
callback();
|
|
309
|
+
}
|
|
310
|
+
catch (error) {
|
|
311
|
+
console.error("[Base44 SDK] A mountCheckout() callback threw", error);
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
paymentElement.on("ready", () => {
|
|
315
|
+
ready = true;
|
|
316
|
+
notify(() => { var _a; return (_a = options.onReadyChange) === null || _a === void 0 ? void 0 : _a.call(options, true); });
|
|
317
|
+
});
|
|
318
|
+
// The element fires ready again once it recovers.
|
|
319
|
+
paymentElement.on("loaderror", () => {
|
|
320
|
+
ready = false;
|
|
321
|
+
notify(() => { var _a; return (_a = options.onReadyChange) === null || _a === void 0 ? void 0 : _a.call(options, false); });
|
|
322
|
+
});
|
|
323
|
+
const box = document.createElement("div");
|
|
324
|
+
element.appendChild(box);
|
|
325
|
+
try {
|
|
326
|
+
await paymentElement.mount(box);
|
|
327
|
+
}
|
|
328
|
+
catch (error) {
|
|
329
|
+
box.remove();
|
|
330
|
+
paymentElement.destroy();
|
|
331
|
+
throw error;
|
|
332
|
+
}
|
|
333
|
+
return {
|
|
334
|
+
pay() {
|
|
335
|
+
if (destroyed || !ready || paying || finished)
|
|
336
|
+
return Promise.resolve();
|
|
337
|
+
paying = true;
|
|
338
|
+
// The executor runs now, so confirmPayment() is called inside the app's click, before any await.
|
|
339
|
+
return new Promise((resolve) => resolve(paymentElement.confirmPayment()))
|
|
340
|
+
.then(async ({ status }) => {
|
|
341
|
+
if (status !== "succeeded") {
|
|
342
|
+
notify(() => { var _a; return (_a = options.onCancel) === null || _a === void 0 ? void 0 : _a.call(options); });
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
finished = true;
|
|
346
|
+
// Runs even after destroy(), so a paid order is still completed.
|
|
347
|
+
const result = await deps.completeCheckout(checkoutId);
|
|
348
|
+
notify(() => { var _a; return (_a = options.onComplete) === null || _a === void 0 ? void 0 : _a.call(options, result); });
|
|
349
|
+
})
|
|
350
|
+
.catch((error) => {
|
|
351
|
+
finished = true;
|
|
352
|
+
notify(() => { var _a; return (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, error); });
|
|
353
|
+
})
|
|
354
|
+
.finally(() => {
|
|
355
|
+
paying = false;
|
|
356
|
+
});
|
|
357
|
+
},
|
|
358
|
+
destroy() {
|
|
359
|
+
if (destroyed)
|
|
360
|
+
return;
|
|
361
|
+
destroyed = true;
|
|
362
|
+
box.remove();
|
|
363
|
+
paymentElement.destroy();
|
|
364
|
+
},
|
|
365
|
+
// The app owns the Pay button, so it disables its own.
|
|
366
|
+
setDisabled: () => undefined,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
239
369
|
/** The new checkout's id, refused unless it is the checkout the button was drawn for. */
|
|
240
370
|
function onClickCheckoutId(spec, button) {
|
|
241
371
|
return async () => {
|
|
@@ -258,7 +388,7 @@ function onClickCheckoutId(spec, button) {
|
|
|
258
388
|
export async function preloadCheckout(provider, deps) {
|
|
259
389
|
if (typeof window === "undefined" || typeof document === "undefined")
|
|
260
390
|
return;
|
|
261
|
-
const read = () => (
|
|
391
|
+
const read = () => ({ paypal: browserGlobals().paypal, stripe: browserGlobals().Stripe, wix: browserGlobals().wpe })[provider];
|
|
262
392
|
try {
|
|
263
393
|
if (!read()) {
|
|
264
394
|
await deps.loadScript(await scriptUrlFor(provider, deps));
|
|
@@ -291,6 +421,11 @@ export async function mountCheckout(element, checkout, options, deps) {
|
|
|
291
421
|
return mountStripe(element, await scriptUrlFor("stripe", deps), embedded, deps);
|
|
292
422
|
case "paypal":
|
|
293
423
|
return mountPayPal(element, await scriptUrlFor("paypal", deps), checkout.currency, embedded, checkout.checkout_id, options, deps);
|
|
424
|
+
case "wix":
|
|
425
|
+
if (!embedded.client_id) {
|
|
426
|
+
throw new Error("This Base44 Payments checkout has no client ID to render with");
|
|
427
|
+
}
|
|
428
|
+
return mountWix(element, await scriptUrlFor("wix", deps), checkout.checkout_id, embedded.client_id, options, deps);
|
|
294
429
|
default:
|
|
295
430
|
throw new Error(`Embedded checkout isn't supported for provider ${embedded.provider}`);
|
|
296
431
|
}
|
|
@@ -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,19 @@ 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. May be absent, so don't rely on it. */
|
|
156
|
+
client_id?: string;
|
|
157
|
+
}
|
|
149
158
|
/**
|
|
150
159
|
* Data that an embedded checkout needs to render, by provider.
|
|
151
160
|
*/
|
|
152
|
-
export type EmbeddedCheckout = StripeEmbeddedCheckout | PayPalEmbeddedCheckout;
|
|
161
|
+
export type EmbeddedCheckout = StripeEmbeddedCheckout | PayPalEmbeddedCheckout | WixEmbeddedCheckout;
|
|
153
162
|
/**
|
|
154
163
|
* Result of [`createCheckout()`](#createcheckout).
|
|
155
164
|
*
|
|
@@ -218,6 +227,10 @@ export interface Purchase {
|
|
|
218
227
|
metadata?: Record<string, string> | null;
|
|
219
228
|
/** ID of the subscription, for recurring purchases. */
|
|
220
229
|
subscription_id?: string | null;
|
|
230
|
+
/** Current state of the subscription, for Base44 Payments subscription purchases: `active`, `paused` or `canceled`. `null` while the provider retries a renewal, or when the state couldn't be read. */
|
|
231
|
+
subscription_status?: "active" | "paused" | "canceled" | null;
|
|
232
|
+
/** When the paid period ends, as an ISO 8601 date, for an `active` Base44 Payments subscription. After a cancel at period end it's when access ends. `null` otherwise. */
|
|
233
|
+
paid_until?: string | null;
|
|
221
234
|
/** Where the order ships, whether your app or the provider collected the address. Always `null` unless you call with the service role. Save it on your order record. */
|
|
222
235
|
shipping_address?: ShippingAddress | null;
|
|
223
236
|
/** Shipping fee in minor units, when the checkout charged one. */
|
|
@@ -316,19 +329,23 @@ export type PaymentsErrorCode = "forbidden" | "unauthenticated" | "not_found" |
|
|
|
316
329
|
*/
|
|
317
330
|
export interface MountCheckoutOptions {
|
|
318
331
|
/**
|
|
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.
|
|
332
|
+
* 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
333
|
*
|
|
321
334
|
* 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
335
|
*/
|
|
323
336
|
onComplete?: (result: CompleteCheckoutResult) => void;
|
|
324
|
-
/** Called when the buyer closes the PayPal window without paying. The button stays mounted
|
|
337
|
+
/** 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 buyer can try again: PayPal's button stays mounted, and for Base44 Payments call `pay()` again. */
|
|
325
338
|
onCancel?: () => void;
|
|
326
339
|
/**
|
|
327
|
-
* Called when a PayPal checkout fails after it's mounted,
|
|
340
|
+
* Called when a PayPal or Base44 Payments checkout fails after it's mounted. PayPal's button stays mounted so the buyer can try again. For Base44 Payments, `pay()` does nothing after this, since the payment element refuses another payment, so create a new checkout and mount it. 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
341
|
*
|
|
329
|
-
* The error is a `Base44Error` when completing the checkout fails, or
|
|
342
|
+
* 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
343
|
*/
|
|
331
344
|
onError?: (error: unknown) => void;
|
|
345
|
+
/**
|
|
346
|
+
* Base44 Payments only. Called with `true` when the payment element can take a payment, and with `false` if it stops loading. It can be called again with `true` once the element recovers. Enable your Pay button only while it's ready.
|
|
347
|
+
*/
|
|
348
|
+
onReadyChange?: (ready: boolean) => void;
|
|
332
349
|
}
|
|
333
350
|
/**
|
|
334
351
|
* An element on the page to render the checkout in, such as the result of `document.getElementById()`.
|
|
@@ -371,8 +388,16 @@ export interface PayPalCheckoutOnClick {
|
|
|
371
388
|
export interface CheckoutMount {
|
|
372
389
|
/** 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
390
|
destroy: () => void;
|
|
374
|
-
/** Grays out PayPal
|
|
391
|
+
/** Grays out the PayPal 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 and Base44 Payments ignore it: Base44 Payments uses your own button, so disable that instead. */
|
|
375
392
|
setDisabled: (disabled: boolean) => void;
|
|
393
|
+
/**
|
|
394
|
+
* Base44 Payments only. Pays with what the buyer entered in the payment element. Call it from your own Pay button's click handler, synchronously and before any `await`, so the payment can open any window it needs.
|
|
395
|
+
*
|
|
396
|
+
* When the payment succeeds, the SDK calls {@linkcode PaymentsModule.completeCheckout | completeCheckout()} and then `onComplete`. Otherwise it calls `onCancel` or `onError`. It does nothing while the element isn't ready, while a payment is in progress, or after a payment succeeded or failed, so a second click can't charge twice.
|
|
397
|
+
*
|
|
398
|
+
* @returns Promise resolving once the payment and its callbacks finish. It never rejects.
|
|
399
|
+
*/
|
|
400
|
+
pay?: () => Promise<void>;
|
|
376
401
|
}
|
|
377
402
|
/**
|
|
378
403
|
* Payments module for accepting one-time payments and subscriptions in your app through its connected payment provider.
|
|
@@ -391,16 +416,16 @@ export interface CheckoutMount {
|
|
|
391
416
|
* | | Stripe | PayPal | Base44 Payments |
|
|
392
417
|
* | :- | :- | :- | :- |
|
|
393
418
|
* | Redirect checkout | Yes | No | Yes |
|
|
394
|
-
* | Embedded checkout | Yes | Yes, required |
|
|
395
|
-
* | Refunds | Yes | Yes |
|
|
396
|
-
* | Subscription cancellation | Yes, now or at period end | Yes, now only |
|
|
397
|
-
* | Subscription pause and resume | Yes | Yes |
|
|
419
|
+
* | Embedded checkout | Yes | Yes, required | Yes |
|
|
420
|
+
* | Refunds | Yes | Yes | Yes |
|
|
421
|
+
* | Subscription cancellation | Yes, now or at period end | Yes, now only | Yes, now or at period end |
|
|
422
|
+
* | Subscription pause and resume | Yes | Yes | Yes |
|
|
398
423
|
*
|
|
399
424
|
* ## Authentication modes
|
|
400
425
|
*
|
|
401
426
|
* This module is available to use with a client in all authentication modes:
|
|
402
427
|
*
|
|
403
|
-
* - **Anonymous or user authentication** (`base44.payments`): Preloads and mounts embedded checkouts, completes PayPal checkouts, and lists the current user's own purchases.
|
|
428
|
+
* - **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
429
|
* - **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
430
|
*
|
|
406
431
|
* @groupDescription Methods
|
|
@@ -408,13 +433,13 @@ export interface CheckoutMount {
|
|
|
408
433
|
*/
|
|
409
434
|
export interface PaymentsModule {
|
|
410
435
|
/**
|
|
411
|
-
* Starts downloading the provider's JavaScript library, Stripe.js
|
|
436
|
+
* Starts downloading the provider's JavaScript library, Stripe.js, the PayPal JavaScript SDK or the Wix Payment Element, before you mount a checkout, so the checkout appears faster.
|
|
412
437
|
*
|
|
413
438
|
* Call it when the checkout page or form opens, while the buyer is still filling it in. {@linkcode mountCheckout | mountCheckout()} needs the library to render the checkout, and downloads it itself if you didn't preload it.
|
|
414
439
|
*
|
|
415
440
|
* It never rejects, so you don't need to await it or catch errors. If the library can't load, `mountCheckout()` tries again and rejects with the error. Loading the library requires a browser environment and is skipped in the backend.
|
|
416
441
|
*
|
|
417
|
-
* @param provider - The provider the app is connected to.
|
|
442
|
+
* @param provider - The provider the app is connected to. Use `'wix'` for Base44 Payments.
|
|
418
443
|
* @returns Promise resolving once the library has loaded or failed to load.
|
|
419
444
|
*
|
|
420
445
|
* @example
|
|
@@ -423,7 +448,7 @@ export interface PaymentsModule {
|
|
|
423
448
|
* base44.payments.preloadCheckout('paypal');
|
|
424
449
|
* ```
|
|
425
450
|
*/
|
|
426
|
-
preloadCheckout(provider: "paypal" | "stripe"): Promise<void>;
|
|
451
|
+
preloadCheckout(provider: "paypal" | "stripe" | "wix"): Promise<void>;
|
|
427
452
|
/**
|
|
428
453
|
* Renders an embedded checkout inside an element on the page.
|
|
429
454
|
*
|
|
@@ -432,6 +457,7 @@ export interface PaymentsModule {
|
|
|
432
457
|
* The SDK loads the provider's library and renders the checkout for you:
|
|
433
458
|
* - PayPal: Renders a PayPal button. When the buyer approves the payment, the SDK calls {@linkcode completeCheckout | completeCheckout()} and then `onComplete`.
|
|
434
459
|
* - 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.
|
|
460
|
+
* - Base44 Payments: Renders the Wix Payment Element, with no button of its own. Add your own Pay button, enable it while `onReadyChange` reports the element is ready, and call the mount's `pay()` from its click handler. When the payment succeeds, the SDK calls {@linkcode completeCheckout | completeCheckout()} and then `onComplete`.
|
|
435
461
|
*
|
|
436
462
|
* To make the checkout appear faster, load the library ahead of time with [`preloadCheckout()`](#preloadcheckout) when the page opens.
|
|
437
463
|
*
|
|
@@ -483,6 +509,27 @@ export interface PaymentsModule {
|
|
|
483
509
|
* ```
|
|
484
510
|
*
|
|
485
511
|
* @example
|
|
512
|
+
* ```typescript
|
|
513
|
+
* // Base44 Payments with your own Pay button
|
|
514
|
+
* const payButton = document.getElementById('pay') as HTMLButtonElement;
|
|
515
|
+
* payButton.disabled = true;
|
|
516
|
+
* const mount = await base44.payments.mountCheckout(
|
|
517
|
+
* document.getElementById('checkout')!,
|
|
518
|
+
* checkout,
|
|
519
|
+
* {
|
|
520
|
+
* onReadyChange: (ready) => (payButton.disabled = !ready),
|
|
521
|
+
* onComplete: () => navigate('/thank-you'),
|
|
522
|
+
* onCancel: () => (payButton.disabled = false),
|
|
523
|
+
* }
|
|
524
|
+
* );
|
|
525
|
+
*
|
|
526
|
+
* payButton.addEventListener('click', () => {
|
|
527
|
+
* payButton.disabled = true;
|
|
528
|
+
* mount.pay?.();
|
|
529
|
+
* });
|
|
530
|
+
* ```
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
486
533
|
* ```tsx
|
|
487
534
|
* // React component
|
|
488
535
|
* function Checkout({ checkout }: { checkout: CreateCheckoutResult }) {
|
|
@@ -507,11 +554,11 @@ export interface PaymentsModule {
|
|
|
507
554
|
*/
|
|
508
555
|
mountCheckout(element: CheckoutElement, checkout: MountableCheckout | PayPalCheckoutOnClick, options?: MountCheckoutOptions): Promise<CheckoutMount>;
|
|
509
556
|
/**
|
|
510
|
-
* Completes a PayPal checkout after the buyer
|
|
557
|
+
* Completes a PayPal or embedded Base44 Payments checkout after the buyer pays.
|
|
511
558
|
*
|
|
512
559
|
* 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
560
|
*
|
|
514
|
-
* Only PayPal checkouts need completing. Other
|
|
561
|
+
* Only PayPal and embedded Base44 Payments checkouts need completing. Other checkouts reject with [`complete_not_supported`](#paymentserrorcode).
|
|
515
562
|
*
|
|
516
563
|
* To complete the checkout from a backend function instead, use [`completeCheckout()`](#service-role-methods) with the service role.
|
|
517
564
|
*
|
|
@@ -642,11 +689,11 @@ export interface ServiceRolePaymentsModule {
|
|
|
642
689
|
*/
|
|
643
690
|
createCheckout(params: CreateCheckoutParams): Promise<CreateCheckoutResult>;
|
|
644
691
|
/**
|
|
645
|
-
* Completes a PayPal checkout from a backend function, after the buyer
|
|
692
|
+
* Completes a PayPal or embedded Base44 Payments checkout from a backend function, after the buyer pays.
|
|
646
693
|
*
|
|
647
694
|
* 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
695
|
*
|
|
649
|
-
* Only PayPal checkouts need completing. Other
|
|
696
|
+
* Only PayPal and embedded Base44 Payments checkouts need completing. Other checkouts reject with [`complete_not_supported`](#paymentserrorcode).
|
|
650
697
|
*
|
|
651
698
|
* @param checkoutId - The `checkout_id` from {@linkcode createCheckout | createCheckout()}.
|
|
652
699
|
* @returns Promise resolving to the checkout's payment status.
|
|
@@ -705,8 +752,6 @@ export interface ServiceRolePaymentsModule {
|
|
|
705
752
|
*
|
|
706
753
|
* Retrying with the same `idempotency_key` and `amount` returns the original refund instead of refunding twice. When the call rejects with [`refund_failed`](#paymentserrorcode), the outcome is unknown, so retry it with the same values.
|
|
707
754
|
*
|
|
708
|
-
* Not supported for Base44 Payments.
|
|
709
|
-
*
|
|
710
755
|
* @param params - The payment, amount, and idempotency key.
|
|
711
756
|
* @returns Promise resolving to the refund.
|
|
712
757
|
*
|
|
@@ -727,7 +772,7 @@ export interface ServiceRolePaymentsModule {
|
|
|
727
772
|
/**
|
|
728
773
|
* Cancels a subscription, now or at the end of the current billing period.
|
|
729
774
|
*
|
|
730
|
-
*
|
|
775
|
+
* Stripe and Base44 Payments can cancel now or at the end of the period. PayPal can only cancel immediately, so `at_period_end` isn't supported there.
|
|
731
776
|
*
|
|
732
777
|
* @param subscriptionId - The `subscription_id` of the purchase.
|
|
733
778
|
* @param options - When to cancel.
|
|
@@ -745,8 +790,6 @@ export interface ServiceRolePaymentsModule {
|
|
|
745
790
|
/**
|
|
746
791
|
* Pauses a subscription's billing.
|
|
747
792
|
*
|
|
748
|
-
* Not supported for Base44 Payments.
|
|
749
|
-
*
|
|
750
793
|
* @param subscriptionId - The `subscription_id` of the purchase.
|
|
751
794
|
* @returns Promise resolving to the subscription's state.
|
|
752
795
|
*
|
|
@@ -760,8 +803,6 @@ export interface ServiceRolePaymentsModule {
|
|
|
760
803
|
/**
|
|
761
804
|
* Resumes a paused subscription's billing.
|
|
762
805
|
*
|
|
763
|
-
* Not supported for Base44 Payments.
|
|
764
|
-
*
|
|
765
806
|
* @param subscriptionId - The `subscription_id` of the purchase.
|
|
766
807
|
* @returns Promise resolving to the subscription's state.
|
|
767
808
|
*
|