@base44-preview/sdk 0.8.58-beta.0-pr.366.dccfb00 → 0.8.58-beta.0-pr.367.230725c
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/client.types.d.ts
CHANGED
|
@@ -134,7 +134,7 @@ export interface Base44Client {
|
|
|
134
134
|
actors: ActorsModule;
|
|
135
135
|
/** {@link AuthModule | Auth module} for user authentication and management. */
|
|
136
136
|
auth: AuthModule;
|
|
137
|
-
/**
|
|
137
|
+
/** [Connectors module](/developers/references/sdk/docs/interfaces/connectors#app-user-connectors) for app-user OAuth flows. */
|
|
138
138
|
connectors: UserConnectorsModule;
|
|
139
139
|
/** {@link EntitiesModule | Entities module} for CRUD operations on your data models. */
|
|
140
140
|
entities: EntitiesModule;
|
|
@@ -241,7 +241,7 @@ export interface Base44Client {
|
|
|
241
241
|
functions: FunctionsModule;
|
|
242
242
|
/** {@link IntegrationsModule | Integrations module} with elevated permissions. */
|
|
243
243
|
integrations: IntegrationsModule;
|
|
244
|
-
/**
|
|
244
|
+
/** [Payments module](/developers/references/sdk/docs/interfaces/payments#service-role-methods) for creating checkouts, refunds, and subscription changes. */
|
|
245
245
|
payments: ServiceRolePaymentsModule;
|
|
246
246
|
/** {@link SsoModule | SSO module} for generating SSO tokens. */
|
|
247
247
|
sso: SsoModule;
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
|
14
14
|
export type { AppModule, AppPublicSettings, AppPublicSettingsResponse, } from "./modules/app.types.js";
|
|
15
15
|
export type { ActorsModule, ActorClient, ActorRef, Connection, ActorSubscription, ActorConnectOptions, ActorNameRegistry, ActorRegistry, } from "./modules/actors.types.js";
|
|
16
16
|
export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
|
|
17
|
-
export type { PaymentsModule, ServiceRolePaymentsModule, PaymentsErrorCode, PaymentsRecurringFrequency, CheckoutBuyer, CheckoutFreeTrial, CheckoutItem, CheckoutItemRecurring, CheckoutPresentation, CheckoutShipping, CheckoutElement, CheckoutMount, MountableCheckout, CreateCheckoutParams, CreateCheckoutResult, CompleteCheckoutResult, EmbeddedCheckout,
|
|
17
|
+
export type { PaymentsModule, ServiceRolePaymentsModule, PaymentsErrorCode, PaymentsRecurringFrequency, CheckoutBuyer, CheckoutFreeTrial, CheckoutItem, CheckoutItemRecurring, CheckoutPresentation, CheckoutShipping, CheckoutElement, CheckoutMount, MountableCheckout, CreateCheckoutParams, CreateCheckoutResult, CompleteCheckoutResult, EmbeddedCheckout, PayPalEmbeddedCheckout, StripeEmbeddedCheckout, MountCheckoutOptions, ListPurchasesParams, ServiceRoleListPurchasesParams, ListPurchasesResult, Purchase, PurchaseItem, PurchaseStatus, RefundParams, ShippingAddress, RefundResult, CancelSubscriptionOptions, SubscriptionResult, } from "./modules/payments.types.js";
|
|
18
18
|
export type { BrowserModule, BrowserSession, BrowserSessionOptions, } from "./modules/browser.types.js";
|
|
19
19
|
export { Actor, type Conn } from "./actor.js";
|
|
20
20
|
export type { ConnectorsModule, UserConnectorsModule, ConnectorApiRequest, ConnectorApiResponse, ConnectorApiResponsePhase, } from "./modules/connectors.types.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CheckoutElement, CheckoutMount, CompleteCheckoutResult, MountableCheckout, MountCheckoutOptions
|
|
1
|
+
import type { CheckoutElement, CheckoutMount, CompleteCheckoutResult, MountableCheckout, MountCheckoutOptions } from "./payments.types.js";
|
|
2
2
|
/** @internal */
|
|
3
3
|
export type LoadScript = (src: string) => Promise<void>;
|
|
4
4
|
/**
|
|
@@ -8,13 +8,11 @@ export type LoadScript = (src: string) => Promise<void>;
|
|
|
8
8
|
export interface PaymentsCheckoutConfig {
|
|
9
9
|
paypal?: {
|
|
10
10
|
script_url?: string;
|
|
11
|
-
button?: PayPalButtonConfig | null;
|
|
12
11
|
};
|
|
13
12
|
stripe?: {
|
|
14
13
|
script_url?: string;
|
|
15
14
|
};
|
|
16
15
|
}
|
|
17
|
-
type PayPalButtonConfig = Pick<PayPalEmbeddedCheckout, "client_id" | "merchant_id" | "partner_attribution_id">;
|
|
18
16
|
/** @internal */
|
|
19
17
|
export interface MountCheckoutDeps {
|
|
20
18
|
completeCheckout: (checkoutId: string) => Promise<CompleteCheckoutResult>;
|
|
@@ -35,5 +33,4 @@ export declare function preloadCheckout(provider: "paypal" | "stripe", deps: Pic
|
|
|
35
33
|
* Mounts the embedded checkout that createCheckout() returned.
|
|
36
34
|
* @internal
|
|
37
35
|
*/
|
|
38
|
-
export declare function mountCheckout(element: CheckoutElement, checkout: MountableCheckout
|
|
39
|
-
export {};
|
|
36
|
+
export declare function mountCheckout(element: CheckoutElement, checkout: MountableCheckout, options: MountCheckoutOptions, deps: MountCheckoutDeps): Promise<CheckoutMount>;
|
|
@@ -103,8 +103,6 @@ function mountStripe(element, scriptUrl, embedded, deps) {
|
|
|
103
103
|
activeStripeCheckout = null;
|
|
104
104
|
checkout.destroy();
|
|
105
105
|
},
|
|
106
|
-
// Stripe's own form has no single button to disable.
|
|
107
|
-
setDisabled: () => undefined,
|
|
108
106
|
};
|
|
109
107
|
activeStripeCheckout = handle;
|
|
110
108
|
return handle;
|
|
@@ -112,9 +110,7 @@ function mountStripe(element, scriptUrl, embedded, deps) {
|
|
|
112
110
|
stripeQueue = mount.catch(() => undefined);
|
|
113
111
|
return mount;
|
|
114
112
|
}
|
|
115
|
-
async function mountPayPal(element, scriptUrl, currency, embedded,
|
|
116
|
-
// A created checkout's id, or what an on-click checkout calls inside the click to create one.
|
|
117
|
-
checkout, options, deps) {
|
|
113
|
+
async function mountPayPal(element, scriptUrl, checkoutId, currency, embedded, options, deps) {
|
|
118
114
|
var _a;
|
|
119
115
|
const paypal = await loadGlobal(scriptUrl, () => browserGlobals().paypal, deps.loadScript);
|
|
120
116
|
if (typeof paypal.createInstance !== "function") {
|
|
@@ -146,10 +142,6 @@ checkout, options, deps) {
|
|
|
146
142
|
}
|
|
147
143
|
let destroyed = false;
|
|
148
144
|
let completing = false;
|
|
149
|
-
// Set once a payment goes through: another click would create and charge a second order.
|
|
150
|
-
let paid = false;
|
|
151
|
-
let starting = false;
|
|
152
|
-
let checkoutId = typeof checkout === "string" ? checkout : undefined;
|
|
153
145
|
// App callbacks run only while mounted, and their own errors never reach PayPal or onError.
|
|
154
146
|
const notify = (callback) => {
|
|
155
147
|
if (destroyed)
|
|
@@ -169,8 +161,6 @@ checkout, options, deps) {
|
|
|
169
161
|
button.disabled = true;
|
|
170
162
|
let result;
|
|
171
163
|
try {
|
|
172
|
-
if (!checkoutId)
|
|
173
|
-
throw new Error("PayPal approved a checkout that wasn't created");
|
|
174
164
|
// Runs even after destroy(), so an approved payment is still captured.
|
|
175
165
|
result = await deps.completeCheckout(checkoutId);
|
|
176
166
|
}
|
|
@@ -182,7 +172,6 @@ checkout, options, deps) {
|
|
|
182
172
|
return;
|
|
183
173
|
}
|
|
184
174
|
completing = false;
|
|
185
|
-
paid = true;
|
|
186
175
|
notify(() => { var _a; return (_a = options.onComplete) === null || _a === void 0 ? void 0 : _a.call(options, result); });
|
|
187
176
|
},
|
|
188
177
|
onCancel() {
|
|
@@ -194,26 +183,15 @@ checkout, options, deps) {
|
|
|
194
183
|
});
|
|
195
184
|
button.setAttribute("type", subscription ? "subscribe" : "pay");
|
|
196
185
|
const onClick = () => {
|
|
197
|
-
if (
|
|
186
|
+
if (completing)
|
|
198
187
|
return;
|
|
199
|
-
starting = true;
|
|
200
188
|
// Not awaited before start(), which must run inside the click to open PayPal's popup.
|
|
201
|
-
const id = Promise.resolve()
|
|
202
|
-
.then(typeof checkout === "string" ? () => checkout : checkout)
|
|
203
|
-
.then((resolved) => {
|
|
204
|
-
checkoutId = resolved;
|
|
205
|
-
return subscription ? { subscriptionId: resolved } : { orderId: resolved };
|
|
206
|
-
});
|
|
189
|
+
const id = Promise.resolve(subscription ? { subscriptionId: checkoutId } : { orderId: checkoutId });
|
|
207
190
|
const report = (error) => notify(() => { var _a; return (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, error); });
|
|
208
191
|
try {
|
|
209
|
-
Promise.resolve(session.start({ presentationMode: "auto" }, id))
|
|
210
|
-
.catch(report)
|
|
211
|
-
.finally(() => {
|
|
212
|
-
starting = false;
|
|
213
|
-
});
|
|
192
|
+
Promise.resolve(session.start({ presentationMode: "auto" }, id)).catch(report);
|
|
214
193
|
}
|
|
215
194
|
catch (error) {
|
|
216
|
-
starting = false;
|
|
217
195
|
report(error);
|
|
218
196
|
}
|
|
219
197
|
};
|
|
@@ -229,26 +207,6 @@ checkout, options, deps) {
|
|
|
229
207
|
button.remove();
|
|
230
208
|
(_a = session.destroy) === null || _a === void 0 ? void 0 : _a.call(session);
|
|
231
209
|
},
|
|
232
|
-
setDisabled(disabled) {
|
|
233
|
-
// A payment being completed, or already made, keeps the button off whatever the app asks.
|
|
234
|
-
if (!completing && !paid)
|
|
235
|
-
button.disabled = disabled;
|
|
236
|
-
},
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
/** The new checkout's id, refused unless it is the checkout the button was drawn for. */
|
|
240
|
-
function onClickCheckoutId(spec, button) {
|
|
241
|
-
return async () => {
|
|
242
|
-
var _a;
|
|
243
|
-
const checkout = await spec.createCheckout();
|
|
244
|
-
const embedded = checkout === null || checkout === void 0 ? void 0 : checkout.embedded;
|
|
245
|
-
if ((embedded === null || embedded === void 0 ? void 0 : embedded.provider) !== "paypal" ||
|
|
246
|
-
embedded.intent !== spec.intent ||
|
|
247
|
-
embedded.merchant_id !== button.merchant_id ||
|
|
248
|
-
((_a = checkout.currency) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== spec.currency.toLowerCase()) {
|
|
249
|
-
throw new Error("createCheckout() returned a checkout that doesn't match the PayPal button. Check its provider, intent and currency.");
|
|
250
|
-
}
|
|
251
|
-
return checkout.checkout_id;
|
|
252
210
|
};
|
|
253
211
|
}
|
|
254
212
|
/**
|
|
@@ -279,9 +237,6 @@ export async function mountCheckout(element, checkout, options, deps) {
|
|
|
279
237
|
if (!element) {
|
|
280
238
|
throw new Error("mountCheckout() requires an element to render in");
|
|
281
239
|
}
|
|
282
|
-
if ("createCheckout" in checkout) {
|
|
283
|
-
return mountPayPalOnClick(element, checkout, options, deps);
|
|
284
|
-
}
|
|
285
240
|
const embedded = checkout === null || checkout === void 0 ? void 0 : checkout.embedded;
|
|
286
241
|
if (!embedded) {
|
|
287
242
|
throw new Error("This checkout isn't embedded. Create it with presentation: 'embedded', or send the buyer to its redirect_url.");
|
|
@@ -290,21 +245,8 @@ export async function mountCheckout(element, checkout, options, deps) {
|
|
|
290
245
|
case "stripe":
|
|
291
246
|
return mountStripe(element, await scriptUrlFor("stripe", deps), embedded, deps);
|
|
292
247
|
case "paypal":
|
|
293
|
-
return mountPayPal(element, await scriptUrlFor("paypal", deps), checkout.currency, embedded,
|
|
248
|
+
return mountPayPal(element, await scriptUrlFor("paypal", deps), checkout.checkout_id, checkout.currency, embedded, options, deps);
|
|
294
249
|
default:
|
|
295
250
|
throw new Error(`Embedded checkout isn't supported for provider ${embedded.provider}`);
|
|
296
251
|
}
|
|
297
252
|
}
|
|
298
|
-
async function mountPayPalOnClick(element, spec, options, deps) {
|
|
299
|
-
var _a, _b;
|
|
300
|
-
if (spec.provider !== "paypal" || typeof spec.createCheckout !== "function") {
|
|
301
|
-
throw new Error("Only PayPal can create its checkout on click");
|
|
302
|
-
}
|
|
303
|
-
const scriptUrl = await scriptUrlFor("paypal", deps);
|
|
304
|
-
const button = (_b = (_a = (await deps.getConfig())) === null || _a === void 0 ? void 0 : _a.paypal) === null || _b === void 0 ? void 0 : _b.button;
|
|
305
|
-
if (!(button === null || button === void 0 ? void 0 : button.client_id) || !button.merchant_id) {
|
|
306
|
-
throw new Error("PayPal isn't ready to take payments in this app yet");
|
|
307
|
-
}
|
|
308
|
-
const embedded = { provider: "paypal", ...button, intent: spec.intent };
|
|
309
|
-
return mountPayPal(element, scriptUrl, spec.currency, embedded, onClickCheckoutId(spec, button), options, deps);
|
|
310
|
-
}
|
|
@@ -350,29 +350,12 @@ export interface MountableCheckout {
|
|
|
350
350
|
/** Data for the embedded checkout. Mounting rejects when it's `null`. */
|
|
351
351
|
embedded: EmbeddedCheckout | null;
|
|
352
352
|
}
|
|
353
|
-
/**
|
|
354
|
-
* A PayPal checkout that [`mountCheckout()`](#mountcheckout) creates when the buyer clicks PayPal's button. The button shows as soon as the page loads, the buyer clicks once, and no order is created until they do.
|
|
355
|
-
*/
|
|
356
|
-
export interface PayPalCheckoutOnClick {
|
|
357
|
-
/** Payment provider. Only PayPal can create its checkout on click. */
|
|
358
|
-
provider: "paypal";
|
|
359
|
-
/** Three-letter ISO currency code the checkout uses, such as `'usd'`. */
|
|
360
|
-
currency: string;
|
|
361
|
-
/** Whether the checkout is a one-time payment or a subscription. */
|
|
362
|
-
intent: "capture" | "subscription";
|
|
363
|
-
/**
|
|
364
|
-
* Creates the checkout when the buyer clicks, usually by calling the backend function that calls {@linkcode ServiceRolePaymentsModule.createCheckout | createCheckout()}. Resolve with its result. Reject to stop, for example when a required form field is empty: PayPal's window closes and `onError` receives the error.
|
|
365
|
-
*/
|
|
366
|
-
createCheckout: () => Promise<MountableCheckout>;
|
|
367
|
-
}
|
|
368
353
|
/**
|
|
369
354
|
* A mounted embedded checkout.
|
|
370
355
|
*/
|
|
371
356
|
export interface CheckoutMount {
|
|
372
357
|
/** 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
358
|
destroy: () => void;
|
|
374
|
-
/** PayPal: greys out the 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
|
-
setDisabled: (disabled: boolean) => void;
|
|
376
359
|
}
|
|
377
360
|
/**
|
|
378
361
|
* Payments module for accepting one-time payments and subscriptions in your app through its connected payment provider.
|
|
@@ -433,14 +416,12 @@ export interface PaymentsModule {
|
|
|
433
416
|
*
|
|
434
417
|
* To make the checkout appear faster, load the library ahead of time with [`preloadCheckout()`](#preloadcheckout) when the page opens.
|
|
435
418
|
*
|
|
436
|
-
*
|
|
437
|
-
*
|
|
438
|
-
* 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.
|
|
419
|
+
* Requires a browser environment and can't be used in the backend. Rejects when the checkout isn't embedded, 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
420
|
*
|
|
440
421
|
* The checkout's callbacks run in the buyer's browser, where they can be faked. Grant access to what the buyer paid for only after your backend confirms the purchase, for example with [`listPurchases()`](#service-role-methods) in a backend function.
|
|
441
422
|
*
|
|
442
423
|
* @param element - Element to render the checkout in. It should be empty.
|
|
443
|
-
* @param checkout - The result of {@linkcode ServiceRolePaymentsModule.createCheckout | createCheckout()}
|
|
424
|
+
* @param checkout - The result of {@linkcode ServiceRolePaymentsModule.createCheckout | createCheckout()}.
|
|
444
425
|
* @param options - Callbacks for the checkout's outcome.
|
|
445
426
|
* @returns Promise resolving to the mounted checkout once it renders.
|
|
446
427
|
*
|
|
@@ -464,25 +445,6 @@ export interface PaymentsModule {
|
|
|
464
445
|
* ```
|
|
465
446
|
*
|
|
466
447
|
* @example
|
|
467
|
-
* ```typescript
|
|
468
|
-
* // PayPal: show the button on page load and create the checkout on click
|
|
469
|
-
* const mount = await base44.payments.mountCheckout(
|
|
470
|
-
* document.getElementById('paypal')!,
|
|
471
|
-
* {
|
|
472
|
-
* provider: 'paypal',
|
|
473
|
-
* currency: 'usd',
|
|
474
|
-
* intent: 'capture',
|
|
475
|
-
* createCheckout: async () =>
|
|
476
|
-
* (await base44.functions.invoke('createCheckout', { productId })).data,
|
|
477
|
-
* },
|
|
478
|
-
* { onComplete: ({ checkout_id }) => confirmPurchase(checkout_id) }
|
|
479
|
-
* );
|
|
480
|
-
*
|
|
481
|
-
* // Grey out the button until the shipping form is valid
|
|
482
|
-
* mount.setDisabled(!formIsValid);
|
|
483
|
-
* ```
|
|
484
|
-
*
|
|
485
|
-
* @example
|
|
486
448
|
* ```tsx
|
|
487
449
|
* // React component
|
|
488
450
|
* function Checkout({ checkout }: { checkout: CreateCheckoutResult }) {
|
|
@@ -505,7 +467,7 @@ export interface PaymentsModule {
|
|
|
505
467
|
* }
|
|
506
468
|
* ```
|
|
507
469
|
*/
|
|
508
|
-
mountCheckout(element: CheckoutElement, checkout: MountableCheckout
|
|
470
|
+
mountCheckout(element: CheckoutElement, checkout: MountableCheckout, options?: MountCheckoutOptions): Promise<CheckoutMount>;
|
|
509
471
|
/**
|
|
510
472
|
* Completes a PayPal checkout after the buyer approves it.
|
|
511
473
|
*
|