@base44-preview/sdk 0.8.58-pr.368.f587f1e → 0.8.59-pr.370.a3fc0ae
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
|
@@ -6,7 +6,7 @@ export type { Base44Client, CreateClientAnalyticsConfig, CreateClientConfig, Cre
|
|
|
6
6
|
export * from "./types.js";
|
|
7
7
|
export type { DeleteManyResult, DeleteResult, EntitiesModule, EntityAggregateResult, EntityAggregateSpec, EntityDateBucket, EntityDistinctOptions, EntityFilterOperators, EntityFilterQuery, EntityFilterValue, EntityHandler, EntityListOptions, EntityPage, EntityRecord, EntityTypeRegistry, EntityUpsertOptions, EntityUpsertResult, ImportResult, RealtimeEventType, RealtimeEvent, RealtimeCallback, SortField, UpdateManyResult, } from "./modules/entities.types.js";
|
|
8
8
|
export type { AuthModule, LoginResponse, RegisterParams, VerifyOtpParams, ChangePasswordParams, ResetPasswordParams, User, } from "./modules/auth.types.js";
|
|
9
|
-
export type { IntegrationsModule, IntegrationEndpointFunction, CoreIntegrations, InvokeLLMParams, GenerateImageParams, GenerateImageResult, UploadFileParams, UploadFileResult, SendEmailParams, SendEmailResult, ExtractDataFromUploadedFileParams, ExtractDataFromUploadedFileResult, UploadPrivateFileParams, UploadPrivateFileResult, CreateFileSignedUrlParams, CreateFileSignedUrlResult, } from "./modules/integrations.types.js";
|
|
9
|
+
export type { IntegrationsModule, IntegrationEndpointFunction, CoreIntegrations, InvokeLLMParams, GenerateImageParams, GenerateImageResult, UploadFileParams, UploadFileResult, EmailAttachment, SendEmailParams, SendEmailResult, ExtractDataFromUploadedFileParams, ExtractDataFromUploadedFileResult, UploadPrivateFileParams, UploadPrivateFileResult, CreateFileSignedUrlParams, CreateFileSignedUrlResult, } from "./modules/integrations.types.js";
|
|
10
10
|
export type { FunctionsModule, FunctionName, FunctionNameRegistry, } from "./modules/functions.types.js";
|
|
11
11
|
export type { AgentsModule, AgentName, AgentNameRegistry, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents.types.js";
|
|
12
12
|
export type { AiGatewayModule, AiGatewayConnection, AiGatewayConnectionOptions, } from "./modules/ai-gateway.types.js";
|
|
@@ -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, PayPalEmbeddedCheckout, StripeEmbeddedCheckout, MountCheckoutOptions, ListPurchasesParams, ServiceRoleListPurchasesParams, ListPurchasesResult, Purchase, PurchaseItem, PurchaseStatus, RefundParams, ShippingAddress, RefundResult, CancelSubscriptionOptions, SubscriptionResult, } from "./modules/payments.types.js";
|
|
17
|
+
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
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";
|
|
@@ -86,6 +86,21 @@ export interface UploadFileResult {
|
|
|
86
86
|
/** URL of the uploaded file. */
|
|
87
87
|
file_url: string;
|
|
88
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* A file to attach to an email.
|
|
91
|
+
*/
|
|
92
|
+
export interface EmailAttachment {
|
|
93
|
+
/**
|
|
94
|
+
* File name the recipient sees, including the extension. The supported extensions are `csv`, `docx`, `gif`, `ics`, `jpeg`, `jpg`, `md`, `pdf`, `png`, `txt`, `webp`, and `xlsx`.
|
|
95
|
+
*/
|
|
96
|
+
filename: string;
|
|
97
|
+
/**
|
|
98
|
+
* A file your app already uploaded, such as the `file_url` returned by [`UploadFile()`](#uploadfile) or the `file_uri` returned by [`UploadPrivateFile()`](#uploadprivatefile). Files uploaded by other apps are rejected.
|
|
99
|
+
*/
|
|
100
|
+
file_url?: string;
|
|
101
|
+
/** Base64-encoded file contents, for a file your code generated. */
|
|
102
|
+
content?: string;
|
|
103
|
+
}
|
|
89
104
|
/**
|
|
90
105
|
* Parameters for the SendEmail function.
|
|
91
106
|
*/
|
|
@@ -94,10 +109,18 @@ export interface SendEmailParams {
|
|
|
94
109
|
to: string;
|
|
95
110
|
/** Email subject line. */
|
|
96
111
|
subject: string;
|
|
97
|
-
/**
|
|
98
|
-
body
|
|
99
|
-
/** The
|
|
112
|
+
/** HTML email body. The same as `html`, so set one or the other, not both. */
|
|
113
|
+
body?: string;
|
|
114
|
+
/** HTML email body. The same as `body`, so set one or the other, not both. */
|
|
115
|
+
html?: string;
|
|
116
|
+
/**
|
|
117
|
+
* Plain-text email body. On its own, it sends a plain-text email. Set it together with `body` or `html` to send both versions in one email, and the recipient's mail client shows whichever it prefers. Make sure both versions say the same thing.
|
|
118
|
+
*/
|
|
119
|
+
text?: string;
|
|
120
|
+
/** The name of the sender. If omitted, the app's name is used. */
|
|
100
121
|
from_name?: string;
|
|
122
|
+
/** Files to attach. You can attach up to 5 files, up to 5 MB each and 10 MB in total. Set `filename` and exactly one of `file_url` or `content` on each file. */
|
|
123
|
+
attachments?: EmailAttachment[];
|
|
101
124
|
}
|
|
102
125
|
export type SendEmailResult = any;
|
|
103
126
|
/**
|
|
@@ -236,10 +259,35 @@ export interface CoreIntegrations {
|
|
|
236
259
|
*/
|
|
237
260
|
UploadFile(params: UploadFileParams): Promise<UploadFileResult>;
|
|
238
261
|
/**
|
|
239
|
-
* Send
|
|
262
|
+
* Send an email from your app.
|
|
263
|
+
*
|
|
264
|
+
* You can always email registered users of your app. To email anyone else, the app needs a paid plan and a connected custom domain.
|
|
240
265
|
*
|
|
241
|
-
* @param params - Parameters for sending email
|
|
266
|
+
* @param params - Parameters for sending email. Set at least one of `body`, `html`, or `text`.
|
|
242
267
|
* @returns Promise resolving when the email is sent.
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```typescript
|
|
271
|
+
* // Send an HTML email with a plain-text version
|
|
272
|
+
* await base44.integrations.Core.SendEmail({
|
|
273
|
+
* to: "user@example.com",
|
|
274
|
+
* subject: "Your order has shipped",
|
|
275
|
+
* html: "<p>Your order <strong>#1234</strong> is on its way.</p>",
|
|
276
|
+
* text: "Your order #1234 is on its way.",
|
|
277
|
+
* });
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```typescript
|
|
282
|
+
* // Attach a file your app uploaded
|
|
283
|
+
* const { file_url } = await base44.integrations.Core.UploadFile({ file });
|
|
284
|
+
* await base44.integrations.Core.SendEmail({
|
|
285
|
+
* to: "user@example.com",
|
|
286
|
+
* subject: "Your invoice",
|
|
287
|
+
* html: "<p>Your invoice is attached.</p>",
|
|
288
|
+
* attachments: [{ filename: "invoice.pdf", file_url }],
|
|
289
|
+
* });
|
|
290
|
+
* ```
|
|
243
291
|
*/
|
|
244
292
|
SendEmail(params: SendEmailParams): Promise<SendEmailResult>;
|
|
245
293
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CheckoutElement, CheckoutMount, CompleteCheckoutResult, MountableCheckout, MountCheckoutOptions } from "./payments.types.js";
|
|
1
|
+
import type { CheckoutElement, CheckoutMount, CompleteCheckoutResult, MountableCheckout, MountCheckoutOptions, PayPalCheckoutOnClick, PayPalEmbeddedCheckout } from "./payments.types.js";
|
|
2
2
|
/** @internal */
|
|
3
3
|
export type LoadScript = (src: string) => Promise<void>;
|
|
4
4
|
/**
|
|
@@ -8,11 +8,13 @@ export type LoadScript = (src: string) => Promise<void>;
|
|
|
8
8
|
export interface PaymentsCheckoutConfig {
|
|
9
9
|
paypal?: {
|
|
10
10
|
script_url?: string;
|
|
11
|
+
button?: PayPalButtonConfig | null;
|
|
11
12
|
};
|
|
12
13
|
stripe?: {
|
|
13
14
|
script_url?: string;
|
|
14
15
|
};
|
|
15
16
|
}
|
|
17
|
+
type PayPalButtonConfig = Pick<PayPalEmbeddedCheckout, "client_id" | "merchant_id" | "partner_attribution_id">;
|
|
16
18
|
/** @internal */
|
|
17
19
|
export interface MountCheckoutDeps {
|
|
18
20
|
completeCheckout: (checkoutId: string) => Promise<CompleteCheckoutResult>;
|
|
@@ -33,4 +35,5 @@ export declare function preloadCheckout(provider: "paypal" | "stripe", deps: Pic
|
|
|
33
35
|
* Mounts the embedded checkout that createCheckout() returned.
|
|
34
36
|
* @internal
|
|
35
37
|
*/
|
|
36
|
-
export declare function mountCheckout(element: CheckoutElement, checkout: MountableCheckout, options: MountCheckoutOptions, deps: MountCheckoutDeps): Promise<CheckoutMount>;
|
|
38
|
+
export declare function mountCheckout(element: CheckoutElement, checkout: MountableCheckout | PayPalCheckoutOnClick, options: MountCheckoutOptions, deps: MountCheckoutDeps): Promise<CheckoutMount>;
|
|
39
|
+
export {};
|
|
@@ -103,6 +103,8 @@ 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,
|
|
106
108
|
};
|
|
107
109
|
activeStripeCheckout = handle;
|
|
108
110
|
return handle;
|
|
@@ -110,7 +112,9 @@ function mountStripe(element, scriptUrl, embedded, deps) {
|
|
|
110
112
|
stripeQueue = mount.catch(() => undefined);
|
|
111
113
|
return mount;
|
|
112
114
|
}
|
|
113
|
-
async function mountPayPal(element, scriptUrl,
|
|
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) {
|
|
114
118
|
var _a;
|
|
115
119
|
const paypal = await loadGlobal(scriptUrl, () => browserGlobals().paypal, deps.loadScript);
|
|
116
120
|
if (typeof paypal.createInstance !== "function") {
|
|
@@ -142,6 +146,10 @@ async function mountPayPal(element, scriptUrl, checkoutId, currency, embedded, o
|
|
|
142
146
|
}
|
|
143
147
|
let destroyed = false;
|
|
144
148
|
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;
|
|
145
153
|
// App callbacks run only while mounted, and their own errors never reach PayPal or onError.
|
|
146
154
|
const notify = (callback) => {
|
|
147
155
|
if (destroyed)
|
|
@@ -161,6 +169,8 @@ async function mountPayPal(element, scriptUrl, checkoutId, currency, embedded, o
|
|
|
161
169
|
button.disabled = true;
|
|
162
170
|
let result;
|
|
163
171
|
try {
|
|
172
|
+
if (!checkoutId)
|
|
173
|
+
throw new Error("PayPal approved a checkout that wasn't created");
|
|
164
174
|
// Runs even after destroy(), so an approved payment is still captured.
|
|
165
175
|
result = await deps.completeCheckout(checkoutId);
|
|
166
176
|
}
|
|
@@ -172,6 +182,7 @@ async function mountPayPal(element, scriptUrl, checkoutId, currency, embedded, o
|
|
|
172
182
|
return;
|
|
173
183
|
}
|
|
174
184
|
completing = false;
|
|
185
|
+
paid = true;
|
|
175
186
|
notify(() => { var _a; return (_a = options.onComplete) === null || _a === void 0 ? void 0 : _a.call(options, result); });
|
|
176
187
|
},
|
|
177
188
|
onCancel() {
|
|
@@ -183,15 +194,26 @@ async function mountPayPal(element, scriptUrl, checkoutId, currency, embedded, o
|
|
|
183
194
|
});
|
|
184
195
|
button.setAttribute("type", subscription ? "subscribe" : "pay");
|
|
185
196
|
const onClick = () => {
|
|
186
|
-
if (completing)
|
|
197
|
+
if (paid || completing || starting || button.disabled)
|
|
187
198
|
return;
|
|
199
|
+
starting = true;
|
|
188
200
|
// Not awaited before start(), which must run inside the click to open PayPal's popup.
|
|
189
|
-
const id = Promise.resolve(
|
|
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
|
+
});
|
|
190
207
|
const report = (error) => notify(() => { var _a; return (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, error); });
|
|
191
208
|
try {
|
|
192
|
-
Promise.resolve(session.start({ presentationMode: "auto" }, id))
|
|
209
|
+
Promise.resolve(session.start({ presentationMode: "auto" }, id))
|
|
210
|
+
.catch(report)
|
|
211
|
+
.finally(() => {
|
|
212
|
+
starting = false;
|
|
213
|
+
});
|
|
193
214
|
}
|
|
194
215
|
catch (error) {
|
|
216
|
+
starting = false;
|
|
195
217
|
report(error);
|
|
196
218
|
}
|
|
197
219
|
};
|
|
@@ -207,6 +229,26 @@ async function mountPayPal(element, scriptUrl, checkoutId, currency, embedded, o
|
|
|
207
229
|
button.remove();
|
|
208
230
|
(_a = session.destroy) === null || _a === void 0 ? void 0 : _a.call(session);
|
|
209
231
|
},
|
|
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;
|
|
210
252
|
};
|
|
211
253
|
}
|
|
212
254
|
/**
|
|
@@ -237,6 +279,9 @@ export async function mountCheckout(element, checkout, options, deps) {
|
|
|
237
279
|
if (!element) {
|
|
238
280
|
throw new Error("mountCheckout() requires an element to render in");
|
|
239
281
|
}
|
|
282
|
+
if ("createCheckout" in checkout) {
|
|
283
|
+
return mountPayPalOnClick(element, checkout, options, deps);
|
|
284
|
+
}
|
|
240
285
|
const embedded = checkout === null || checkout === void 0 ? void 0 : checkout.embedded;
|
|
241
286
|
if (!embedded) {
|
|
242
287
|
throw new Error("This checkout isn't embedded. Create it with presentation: 'embedded', or send the buyer to its redirect_url.");
|
|
@@ -245,8 +290,21 @@ export async function mountCheckout(element, checkout, options, deps) {
|
|
|
245
290
|
case "stripe":
|
|
246
291
|
return mountStripe(element, await scriptUrlFor("stripe", deps), embedded, deps);
|
|
247
292
|
case "paypal":
|
|
248
|
-
return mountPayPal(element, await scriptUrlFor("paypal", deps), checkout.
|
|
293
|
+
return mountPayPal(element, await scriptUrlFor("paypal", deps), checkout.currency, embedded, checkout.checkout_id, options, deps);
|
|
249
294
|
default:
|
|
250
295
|
throw new Error(`Embedded checkout isn't supported for provider ${embedded.provider}`);
|
|
251
296
|
}
|
|
252
297
|
}
|
|
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,12 +350,29 @@ 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 [`createCheckout()`](#createcheckout). Resolve with its result. It must be an embedded PayPal checkout with the same `currency` and `intent` you set here, or `onError` receives an error. Reject to stop, for example when a required form field is empty. PayPal's window then closes and `onError` receives the error.
|
|
365
|
+
*/
|
|
366
|
+
createCheckout: () => Promise<MountableCheckout>;
|
|
367
|
+
}
|
|
353
368
|
/**
|
|
354
369
|
* A mounted embedded checkout.
|
|
355
370
|
*/
|
|
356
371
|
export interface CheckoutMount {
|
|
357
372
|
/** 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. */
|
|
358
373
|
destroy: () => void;
|
|
374
|
+
/** Grays out PayPal's 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;
|
|
359
376
|
}
|
|
360
377
|
/**
|
|
361
378
|
* Payments module for accepting one-time payments and subscriptions in your app through its connected payment provider.
|
|
@@ -408,7 +425,7 @@ export interface PaymentsModule {
|
|
|
408
425
|
/**
|
|
409
426
|
* Renders an embedded checkout inside an element on the page.
|
|
410
427
|
*
|
|
411
|
-
* Pass the result of a {@linkcode ServiceRolePaymentsModule.createCheckout | createCheckout()} call made with `presentation: 'embedded'`. Because only the service role can create checkouts, create it in a backend function and return the result to the page.
|
|
428
|
+
* Pass the result of a {@linkcode ServiceRolePaymentsModule.createCheckout | createCheckout()} call made with `presentation: 'embedded'`. Because only the service role can create checkouts, create it in a backend function and return the result to the page. For PayPal, you can instead pass a {@linkcode PayPalCheckoutOnClick} to show the button before any checkout exists. The SDK creates the checkout only when the buyer clicks the button, so visitors who don't buy don't leave unused checkouts behind.
|
|
412
429
|
*
|
|
413
430
|
* The SDK loads the provider's library and renders the checkout for you:
|
|
414
431
|
* - PayPal: Renders a PayPal button. When the buyer approves the payment, the SDK calls {@linkcode completeCheckout | completeCheckout()} and then `onComplete`.
|
|
@@ -416,12 +433,12 @@ export interface PaymentsModule {
|
|
|
416
433
|
*
|
|
417
434
|
* To make the checkout appear faster, load the library ahead of time with [`preloadCheckout()`](#preloadcheckout) when the page opens.
|
|
418
435
|
*
|
|
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.
|
|
436
|
+
* 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.
|
|
420
437
|
*
|
|
421
438
|
* 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.
|
|
422
439
|
*
|
|
423
440
|
* @param element - Element to render the checkout in. It should be empty.
|
|
424
|
-
* @param checkout - The result of {@linkcode ServiceRolePaymentsModule.createCheckout | createCheckout()}.
|
|
441
|
+
* @param checkout - The result of {@linkcode ServiceRolePaymentsModule.createCheckout | createCheckout()}, or for PayPal a {@linkcode PayPalCheckoutOnClick} that creates it when the buyer clicks.
|
|
425
442
|
* @param options - Callbacks for the checkout's outcome.
|
|
426
443
|
* @returns Promise resolving to the mounted checkout once it renders.
|
|
427
444
|
*
|
|
@@ -445,6 +462,25 @@ export interface PaymentsModule {
|
|
|
445
462
|
* ```
|
|
446
463
|
*
|
|
447
464
|
* @example
|
|
465
|
+
* ```typescript
|
|
466
|
+
* // Create a PayPal checkout on click
|
|
467
|
+
* const mount = await base44.payments.mountCheckout(
|
|
468
|
+
* document.getElementById('paypal')!,
|
|
469
|
+
* {
|
|
470
|
+
* provider: 'paypal',
|
|
471
|
+
* currency: 'usd',
|
|
472
|
+
* intent: 'capture',
|
|
473
|
+
* createCheckout: async () =>
|
|
474
|
+
* (await base44.functions.invoke('createCheckout', { productId })).data,
|
|
475
|
+
* },
|
|
476
|
+
* { onComplete: ({ checkout_id }) => confirmPurchase(checkout_id) }
|
|
477
|
+
* );
|
|
478
|
+
*
|
|
479
|
+
* // Gray out the button until the shipping form is valid
|
|
480
|
+
* mount.setDisabled(!formIsValid);
|
|
481
|
+
* ```
|
|
482
|
+
*
|
|
483
|
+
* @example
|
|
448
484
|
* ```tsx
|
|
449
485
|
* // React component
|
|
450
486
|
* function Checkout({ checkout }: { checkout: CreateCheckoutResult }) {
|
|
@@ -467,7 +503,7 @@ export interface PaymentsModule {
|
|
|
467
503
|
* }
|
|
468
504
|
* ```
|
|
469
505
|
*/
|
|
470
|
-
mountCheckout(element: CheckoutElement, checkout: MountableCheckout, options?: MountCheckoutOptions): Promise<CheckoutMount>;
|
|
506
|
+
mountCheckout(element: CheckoutElement, checkout: MountableCheckout | PayPalCheckoutOnClick, options?: MountCheckoutOptions): Promise<CheckoutMount>;
|
|
471
507
|
/**
|
|
472
508
|
* Completes a PayPal checkout after the buyer approves it.
|
|
473
509
|
*
|