@dodopayments/better-auth 1.1.3 → 1.3.0
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 +248 -0
- package/dist/plugins/checkout.d.ts +251 -0
- package/dist/plugins/checkout.js +88 -5
- package/package.json +2 -5
package/dist/index.d.ts
CHANGED
|
@@ -285,6 +285,254 @@ export declare const dodopayments: (options: DodoPaymentsOptions) => {
|
|
|
285
285
|
};
|
|
286
286
|
path: "/dodopayments/checkout";
|
|
287
287
|
};
|
|
288
|
+
checkoutSession: {
|
|
289
|
+
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: {
|
|
290
|
+
body: {
|
|
291
|
+
product_cart?: {
|
|
292
|
+
quantity: number;
|
|
293
|
+
product_id: string;
|
|
294
|
+
}[] | undefined;
|
|
295
|
+
customer?: {
|
|
296
|
+
email?: string | undefined;
|
|
297
|
+
name?: string | undefined;
|
|
298
|
+
phone_number?: string | undefined;
|
|
299
|
+
} | undefined;
|
|
300
|
+
metadata?: Record<string, string> | undefined;
|
|
301
|
+
slug?: string | undefined;
|
|
302
|
+
referenceId?: string | undefined;
|
|
303
|
+
billing_address?: {
|
|
304
|
+
country: string;
|
|
305
|
+
city?: string | undefined;
|
|
306
|
+
state?: string | undefined;
|
|
307
|
+
street?: string | undefined;
|
|
308
|
+
zipcode?: string | undefined;
|
|
309
|
+
} | undefined;
|
|
310
|
+
return_url?: string | undefined;
|
|
311
|
+
allowed_payment_method_types?: ("credit" | "debit" | "upi_collect" | "upi_intent" | "apple_pay" | "google_pay" | "amazon_pay" | "klarna" | "affirm" | "afterpay_clearpay" | "sepa" | "ach")[] | undefined;
|
|
312
|
+
billing_currency?: string | undefined;
|
|
313
|
+
show_saved_payment_methods?: boolean | undefined;
|
|
314
|
+
confirm?: boolean | undefined;
|
|
315
|
+
discount_code?: string | undefined;
|
|
316
|
+
customization?: {
|
|
317
|
+
theme?: "light" | "dark" | "system" | undefined;
|
|
318
|
+
show_order_details?: boolean | undefined;
|
|
319
|
+
show_on_demand_tag?: boolean | undefined;
|
|
320
|
+
} | undefined;
|
|
321
|
+
feature_flags?: {
|
|
322
|
+
allow_currency_selection?: boolean | undefined;
|
|
323
|
+
allow_discount_code?: boolean | undefined;
|
|
324
|
+
allow_phone_number_collection?: boolean | undefined;
|
|
325
|
+
allow_tax_id?: boolean | undefined;
|
|
326
|
+
always_create_new_customer?: boolean | undefined;
|
|
327
|
+
} | undefined;
|
|
328
|
+
subscription_data?: {
|
|
329
|
+
trial_period_days?: number | undefined;
|
|
330
|
+
} | undefined;
|
|
331
|
+
};
|
|
332
|
+
} & {
|
|
333
|
+
method?: "POST" | undefined;
|
|
334
|
+
} & {
|
|
335
|
+
query?: Record<string, any> | undefined;
|
|
336
|
+
} & {
|
|
337
|
+
params?: Record<string, any>;
|
|
338
|
+
} & {
|
|
339
|
+
request: Request;
|
|
340
|
+
} & {
|
|
341
|
+
headers?: HeadersInit;
|
|
342
|
+
} & {
|
|
343
|
+
asResponse?: boolean;
|
|
344
|
+
returnHeaders?: boolean;
|
|
345
|
+
use?: import("better-call").Middleware[];
|
|
346
|
+
path?: string;
|
|
347
|
+
} & {
|
|
348
|
+
asResponse?: AsResponse | undefined;
|
|
349
|
+
returnHeaders?: ReturnHeaders | undefined;
|
|
350
|
+
}): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
|
|
351
|
+
headers: Headers;
|
|
352
|
+
response: import("./types").CreateCheckoutResponse;
|
|
353
|
+
} : import("./types").CreateCheckoutResponse>;
|
|
354
|
+
options: {
|
|
355
|
+
method: "POST";
|
|
356
|
+
body: import("zod").ZodObject<{
|
|
357
|
+
product_cart: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
|
|
358
|
+
product_id: import("zod").ZodString;
|
|
359
|
+
quantity: import("zod").ZodNumber;
|
|
360
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
361
|
+
quantity: number;
|
|
362
|
+
product_id: string;
|
|
363
|
+
}, {
|
|
364
|
+
quantity: number;
|
|
365
|
+
product_id: string;
|
|
366
|
+
}>, "many">>;
|
|
367
|
+
customer: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
368
|
+
email: import("zod").ZodOptional<import("zod").ZodString>;
|
|
369
|
+
name: import("zod").ZodOptional<import("zod").ZodString>;
|
|
370
|
+
phone_number: import("zod").ZodOptional<import("zod").ZodString>;
|
|
371
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
372
|
+
email?: string | undefined;
|
|
373
|
+
name?: string | undefined;
|
|
374
|
+
phone_number?: string | undefined;
|
|
375
|
+
}, {
|
|
376
|
+
email?: string | undefined;
|
|
377
|
+
name?: string | undefined;
|
|
378
|
+
phone_number?: string | undefined;
|
|
379
|
+
}>>;
|
|
380
|
+
metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodString>>;
|
|
381
|
+
slug: import("zod").ZodOptional<import("zod").ZodString>;
|
|
382
|
+
referenceId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
383
|
+
billing_address: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
384
|
+
street: import("zod").ZodOptional<import("zod").ZodString>;
|
|
385
|
+
city: import("zod").ZodOptional<import("zod").ZodString>;
|
|
386
|
+
state: import("zod").ZodOptional<import("zod").ZodString>;
|
|
387
|
+
country: import("zod").ZodString;
|
|
388
|
+
zipcode: import("zod").ZodOptional<import("zod").ZodString>;
|
|
389
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
390
|
+
country: string;
|
|
391
|
+
city?: string | undefined;
|
|
392
|
+
state?: string | undefined;
|
|
393
|
+
street?: string | undefined;
|
|
394
|
+
zipcode?: string | undefined;
|
|
395
|
+
}, {
|
|
396
|
+
country: string;
|
|
397
|
+
city?: string | undefined;
|
|
398
|
+
state?: string | undefined;
|
|
399
|
+
street?: string | undefined;
|
|
400
|
+
zipcode?: string | undefined;
|
|
401
|
+
}>>;
|
|
402
|
+
return_url: import("zod").ZodOptional<import("zod").ZodString>;
|
|
403
|
+
allowed_payment_method_types: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodEnum<["credit", "debit", "upi_collect", "upi_intent", "apple_pay", "google_pay", "amazon_pay", "klarna", "affirm", "afterpay_clearpay", "sepa", "ach"]>, "many">>;
|
|
404
|
+
billing_currency: import("zod").ZodOptional<import("zod").ZodString>;
|
|
405
|
+
show_saved_payment_methods: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
406
|
+
confirm: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
407
|
+
discount_code: import("zod").ZodOptional<import("zod").ZodString>;
|
|
408
|
+
customization: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
409
|
+
theme: import("zod").ZodOptional<import("zod").ZodEnum<["light", "dark", "system"]>>;
|
|
410
|
+
show_order_details: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
411
|
+
show_on_demand_tag: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
412
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
413
|
+
theme?: "light" | "dark" | "system" | undefined;
|
|
414
|
+
show_order_details?: boolean | undefined;
|
|
415
|
+
show_on_demand_tag?: boolean | undefined;
|
|
416
|
+
}, {
|
|
417
|
+
theme?: "light" | "dark" | "system" | undefined;
|
|
418
|
+
show_order_details?: boolean | undefined;
|
|
419
|
+
show_on_demand_tag?: boolean | undefined;
|
|
420
|
+
}>>;
|
|
421
|
+
feature_flags: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
422
|
+
allow_currency_selection: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
423
|
+
allow_discount_code: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
424
|
+
allow_phone_number_collection: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
425
|
+
allow_tax_id: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
426
|
+
always_create_new_customer: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
427
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
428
|
+
allow_currency_selection?: boolean | undefined;
|
|
429
|
+
allow_discount_code?: boolean | undefined;
|
|
430
|
+
allow_phone_number_collection?: boolean | undefined;
|
|
431
|
+
allow_tax_id?: boolean | undefined;
|
|
432
|
+
always_create_new_customer?: boolean | undefined;
|
|
433
|
+
}, {
|
|
434
|
+
allow_currency_selection?: boolean | undefined;
|
|
435
|
+
allow_discount_code?: boolean | undefined;
|
|
436
|
+
allow_phone_number_collection?: boolean | undefined;
|
|
437
|
+
allow_tax_id?: boolean | undefined;
|
|
438
|
+
always_create_new_customer?: boolean | undefined;
|
|
439
|
+
}>>;
|
|
440
|
+
subscription_data: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
441
|
+
trial_period_days: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
442
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
443
|
+
trial_period_days?: number | undefined;
|
|
444
|
+
}, {
|
|
445
|
+
trial_period_days?: number | undefined;
|
|
446
|
+
}>>;
|
|
447
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
448
|
+
product_cart?: {
|
|
449
|
+
quantity: number;
|
|
450
|
+
product_id: string;
|
|
451
|
+
}[] | undefined;
|
|
452
|
+
customer?: {
|
|
453
|
+
email?: string | undefined;
|
|
454
|
+
name?: string | undefined;
|
|
455
|
+
phone_number?: string | undefined;
|
|
456
|
+
} | undefined;
|
|
457
|
+
metadata?: Record<string, string> | undefined;
|
|
458
|
+
slug?: string | undefined;
|
|
459
|
+
referenceId?: string | undefined;
|
|
460
|
+
billing_address?: {
|
|
461
|
+
country: string;
|
|
462
|
+
city?: string | undefined;
|
|
463
|
+
state?: string | undefined;
|
|
464
|
+
street?: string | undefined;
|
|
465
|
+
zipcode?: string | undefined;
|
|
466
|
+
} | undefined;
|
|
467
|
+
return_url?: string | undefined;
|
|
468
|
+
allowed_payment_method_types?: ("credit" | "debit" | "upi_collect" | "upi_intent" | "apple_pay" | "google_pay" | "amazon_pay" | "klarna" | "affirm" | "afterpay_clearpay" | "sepa" | "ach")[] | undefined;
|
|
469
|
+
billing_currency?: string | undefined;
|
|
470
|
+
show_saved_payment_methods?: boolean | undefined;
|
|
471
|
+
confirm?: boolean | undefined;
|
|
472
|
+
discount_code?: string | undefined;
|
|
473
|
+
customization?: {
|
|
474
|
+
theme?: "light" | "dark" | "system" | undefined;
|
|
475
|
+
show_order_details?: boolean | undefined;
|
|
476
|
+
show_on_demand_tag?: boolean | undefined;
|
|
477
|
+
} | undefined;
|
|
478
|
+
feature_flags?: {
|
|
479
|
+
allow_currency_selection?: boolean | undefined;
|
|
480
|
+
allow_discount_code?: boolean | undefined;
|
|
481
|
+
allow_phone_number_collection?: boolean | undefined;
|
|
482
|
+
allow_tax_id?: boolean | undefined;
|
|
483
|
+
always_create_new_customer?: boolean | undefined;
|
|
484
|
+
} | undefined;
|
|
485
|
+
subscription_data?: {
|
|
486
|
+
trial_period_days?: number | undefined;
|
|
487
|
+
} | undefined;
|
|
488
|
+
}, {
|
|
489
|
+
product_cart?: {
|
|
490
|
+
quantity: number;
|
|
491
|
+
product_id: string;
|
|
492
|
+
}[] | undefined;
|
|
493
|
+
customer?: {
|
|
494
|
+
email?: string | undefined;
|
|
495
|
+
name?: string | undefined;
|
|
496
|
+
phone_number?: string | undefined;
|
|
497
|
+
} | undefined;
|
|
498
|
+
metadata?: Record<string, string> | undefined;
|
|
499
|
+
slug?: string | undefined;
|
|
500
|
+
referenceId?: string | undefined;
|
|
501
|
+
billing_address?: {
|
|
502
|
+
country: string;
|
|
503
|
+
city?: string | undefined;
|
|
504
|
+
state?: string | undefined;
|
|
505
|
+
street?: string | undefined;
|
|
506
|
+
zipcode?: string | undefined;
|
|
507
|
+
} | undefined;
|
|
508
|
+
return_url?: string | undefined;
|
|
509
|
+
allowed_payment_method_types?: ("credit" | "debit" | "upi_collect" | "upi_intent" | "apple_pay" | "google_pay" | "amazon_pay" | "klarna" | "affirm" | "afterpay_clearpay" | "sepa" | "ach")[] | undefined;
|
|
510
|
+
billing_currency?: string | undefined;
|
|
511
|
+
show_saved_payment_methods?: boolean | undefined;
|
|
512
|
+
confirm?: boolean | undefined;
|
|
513
|
+
discount_code?: string | undefined;
|
|
514
|
+
customization?: {
|
|
515
|
+
theme?: "light" | "dark" | "system" | undefined;
|
|
516
|
+
show_order_details?: boolean | undefined;
|
|
517
|
+
show_on_demand_tag?: boolean | undefined;
|
|
518
|
+
} | undefined;
|
|
519
|
+
feature_flags?: {
|
|
520
|
+
allow_currency_selection?: boolean | undefined;
|
|
521
|
+
allow_discount_code?: boolean | undefined;
|
|
522
|
+
allow_phone_number_collection?: boolean | undefined;
|
|
523
|
+
allow_tax_id?: boolean | undefined;
|
|
524
|
+
always_create_new_customer?: boolean | undefined;
|
|
525
|
+
} | undefined;
|
|
526
|
+
subscription_data?: {
|
|
527
|
+
trial_period_days?: number | undefined;
|
|
528
|
+
} | undefined;
|
|
529
|
+
}>;
|
|
530
|
+
requireRequest: true;
|
|
531
|
+
} & {
|
|
532
|
+
use: any[];
|
|
533
|
+
};
|
|
534
|
+
path: "/dodopayments/checkout-session";
|
|
535
|
+
};
|
|
288
536
|
} | {
|
|
289
537
|
portal: {
|
|
290
538
|
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({
|
|
@@ -16,6 +16,9 @@ export interface CheckoutOptions {
|
|
|
16
16
|
authenticatedUsersOnly?: boolean;
|
|
17
17
|
}
|
|
18
18
|
export declare const checkout: (checkoutOptions?: CheckoutOptions) => (dodopayments: DodoPayments) => {
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated
|
|
21
|
+
*/
|
|
19
22
|
checkout: {
|
|
20
23
|
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: {
|
|
21
24
|
body: z.objectInputType<{
|
|
@@ -294,4 +297,252 @@ export declare const checkout: (checkoutOptions?: CheckoutOptions) => (dodopayme
|
|
|
294
297
|
};
|
|
295
298
|
path: "/dodopayments/checkout";
|
|
296
299
|
};
|
|
300
|
+
checkoutSession: {
|
|
301
|
+
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: {
|
|
302
|
+
body: {
|
|
303
|
+
product_cart?: {
|
|
304
|
+
quantity: number;
|
|
305
|
+
product_id: string;
|
|
306
|
+
}[] | undefined;
|
|
307
|
+
customer?: {
|
|
308
|
+
email?: string | undefined;
|
|
309
|
+
name?: string | undefined;
|
|
310
|
+
phone_number?: string | undefined;
|
|
311
|
+
} | undefined;
|
|
312
|
+
metadata?: Record<string, string> | undefined;
|
|
313
|
+
slug?: string | undefined;
|
|
314
|
+
referenceId?: string | undefined;
|
|
315
|
+
billing_address?: {
|
|
316
|
+
country: string;
|
|
317
|
+
city?: string | undefined;
|
|
318
|
+
state?: string | undefined;
|
|
319
|
+
street?: string | undefined;
|
|
320
|
+
zipcode?: string | undefined;
|
|
321
|
+
} | undefined;
|
|
322
|
+
return_url?: string | undefined;
|
|
323
|
+
allowed_payment_method_types?: ("credit" | "debit" | "upi_collect" | "upi_intent" | "apple_pay" | "google_pay" | "amazon_pay" | "klarna" | "affirm" | "afterpay_clearpay" | "sepa" | "ach")[] | undefined;
|
|
324
|
+
billing_currency?: string | undefined;
|
|
325
|
+
show_saved_payment_methods?: boolean | undefined;
|
|
326
|
+
confirm?: boolean | undefined;
|
|
327
|
+
discount_code?: string | undefined;
|
|
328
|
+
customization?: {
|
|
329
|
+
theme?: "light" | "dark" | "system" | undefined;
|
|
330
|
+
show_order_details?: boolean | undefined;
|
|
331
|
+
show_on_demand_tag?: boolean | undefined;
|
|
332
|
+
} | undefined;
|
|
333
|
+
feature_flags?: {
|
|
334
|
+
allow_currency_selection?: boolean | undefined;
|
|
335
|
+
allow_discount_code?: boolean | undefined;
|
|
336
|
+
allow_phone_number_collection?: boolean | undefined;
|
|
337
|
+
allow_tax_id?: boolean | undefined;
|
|
338
|
+
always_create_new_customer?: boolean | undefined;
|
|
339
|
+
} | undefined;
|
|
340
|
+
subscription_data?: {
|
|
341
|
+
trial_period_days?: number | undefined;
|
|
342
|
+
} | undefined;
|
|
343
|
+
};
|
|
344
|
+
} & {
|
|
345
|
+
method?: "POST" | undefined;
|
|
346
|
+
} & {
|
|
347
|
+
query?: Record<string, any> | undefined;
|
|
348
|
+
} & {
|
|
349
|
+
params?: Record<string, any>;
|
|
350
|
+
} & {
|
|
351
|
+
request: Request;
|
|
352
|
+
} & {
|
|
353
|
+
headers?: HeadersInit;
|
|
354
|
+
} & {
|
|
355
|
+
asResponse?: boolean;
|
|
356
|
+
returnHeaders?: boolean;
|
|
357
|
+
use?: import("better-call").Middleware[];
|
|
358
|
+
path?: string;
|
|
359
|
+
} & {
|
|
360
|
+
asResponse?: AsResponse | undefined;
|
|
361
|
+
returnHeaders?: ReturnHeaders | undefined;
|
|
362
|
+
}): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
|
|
363
|
+
headers: Headers;
|
|
364
|
+
response: CreateCheckoutResponse;
|
|
365
|
+
} : CreateCheckoutResponse>;
|
|
366
|
+
options: {
|
|
367
|
+
method: "POST";
|
|
368
|
+
body: z.ZodObject<{
|
|
369
|
+
product_cart: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
370
|
+
product_id: z.ZodString;
|
|
371
|
+
quantity: z.ZodNumber;
|
|
372
|
+
}, "strip", z.ZodTypeAny, {
|
|
373
|
+
quantity: number;
|
|
374
|
+
product_id: string;
|
|
375
|
+
}, {
|
|
376
|
+
quantity: number;
|
|
377
|
+
product_id: string;
|
|
378
|
+
}>, "many">>;
|
|
379
|
+
customer: z.ZodOptional<z.ZodObject<{
|
|
380
|
+
email: z.ZodOptional<z.ZodString>;
|
|
381
|
+
name: z.ZodOptional<z.ZodString>;
|
|
382
|
+
phone_number: z.ZodOptional<z.ZodString>;
|
|
383
|
+
}, "strip", z.ZodTypeAny, {
|
|
384
|
+
email?: string | undefined;
|
|
385
|
+
name?: string | undefined;
|
|
386
|
+
phone_number?: string | undefined;
|
|
387
|
+
}, {
|
|
388
|
+
email?: string | undefined;
|
|
389
|
+
name?: string | undefined;
|
|
390
|
+
phone_number?: string | undefined;
|
|
391
|
+
}>>;
|
|
392
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
393
|
+
slug: z.ZodOptional<z.ZodString>;
|
|
394
|
+
referenceId: z.ZodOptional<z.ZodString>;
|
|
395
|
+
billing_address: z.ZodOptional<z.ZodObject<{
|
|
396
|
+
street: z.ZodOptional<z.ZodString>;
|
|
397
|
+
city: z.ZodOptional<z.ZodString>;
|
|
398
|
+
state: z.ZodOptional<z.ZodString>;
|
|
399
|
+
country: z.ZodString;
|
|
400
|
+
zipcode: z.ZodOptional<z.ZodString>;
|
|
401
|
+
}, "strip", z.ZodTypeAny, {
|
|
402
|
+
country: string;
|
|
403
|
+
city?: string | undefined;
|
|
404
|
+
state?: string | undefined;
|
|
405
|
+
street?: string | undefined;
|
|
406
|
+
zipcode?: string | undefined;
|
|
407
|
+
}, {
|
|
408
|
+
country: string;
|
|
409
|
+
city?: string | undefined;
|
|
410
|
+
state?: string | undefined;
|
|
411
|
+
street?: string | undefined;
|
|
412
|
+
zipcode?: string | undefined;
|
|
413
|
+
}>>;
|
|
414
|
+
return_url: z.ZodOptional<z.ZodString>;
|
|
415
|
+
allowed_payment_method_types: z.ZodOptional<z.ZodArray<z.ZodEnum<["credit", "debit", "upi_collect", "upi_intent", "apple_pay", "google_pay", "amazon_pay", "klarna", "affirm", "afterpay_clearpay", "sepa", "ach"]>, "many">>;
|
|
416
|
+
billing_currency: z.ZodOptional<z.ZodString>;
|
|
417
|
+
show_saved_payment_methods: z.ZodOptional<z.ZodBoolean>;
|
|
418
|
+
confirm: z.ZodOptional<z.ZodBoolean>;
|
|
419
|
+
discount_code: z.ZodOptional<z.ZodString>;
|
|
420
|
+
customization: z.ZodOptional<z.ZodObject<{
|
|
421
|
+
theme: z.ZodOptional<z.ZodEnum<["light", "dark", "system"]>>;
|
|
422
|
+
show_order_details: z.ZodOptional<z.ZodBoolean>;
|
|
423
|
+
show_on_demand_tag: z.ZodOptional<z.ZodBoolean>;
|
|
424
|
+
}, "strip", z.ZodTypeAny, {
|
|
425
|
+
theme?: "light" | "dark" | "system" | undefined;
|
|
426
|
+
show_order_details?: boolean | undefined;
|
|
427
|
+
show_on_demand_tag?: boolean | undefined;
|
|
428
|
+
}, {
|
|
429
|
+
theme?: "light" | "dark" | "system" | undefined;
|
|
430
|
+
show_order_details?: boolean | undefined;
|
|
431
|
+
show_on_demand_tag?: boolean | undefined;
|
|
432
|
+
}>>;
|
|
433
|
+
feature_flags: z.ZodOptional<z.ZodObject<{
|
|
434
|
+
allow_currency_selection: z.ZodOptional<z.ZodBoolean>;
|
|
435
|
+
allow_discount_code: z.ZodOptional<z.ZodBoolean>;
|
|
436
|
+
allow_phone_number_collection: z.ZodOptional<z.ZodBoolean>;
|
|
437
|
+
allow_tax_id: z.ZodOptional<z.ZodBoolean>;
|
|
438
|
+
always_create_new_customer: z.ZodOptional<z.ZodBoolean>;
|
|
439
|
+
}, "strip", z.ZodTypeAny, {
|
|
440
|
+
allow_currency_selection?: boolean | undefined;
|
|
441
|
+
allow_discount_code?: boolean | undefined;
|
|
442
|
+
allow_phone_number_collection?: boolean | undefined;
|
|
443
|
+
allow_tax_id?: boolean | undefined;
|
|
444
|
+
always_create_new_customer?: boolean | undefined;
|
|
445
|
+
}, {
|
|
446
|
+
allow_currency_selection?: boolean | undefined;
|
|
447
|
+
allow_discount_code?: boolean | undefined;
|
|
448
|
+
allow_phone_number_collection?: boolean | undefined;
|
|
449
|
+
allow_tax_id?: boolean | undefined;
|
|
450
|
+
always_create_new_customer?: boolean | undefined;
|
|
451
|
+
}>>;
|
|
452
|
+
subscription_data: z.ZodOptional<z.ZodObject<{
|
|
453
|
+
trial_period_days: z.ZodOptional<z.ZodNumber>;
|
|
454
|
+
}, "strip", z.ZodTypeAny, {
|
|
455
|
+
trial_period_days?: number | undefined;
|
|
456
|
+
}, {
|
|
457
|
+
trial_period_days?: number | undefined;
|
|
458
|
+
}>>;
|
|
459
|
+
}, "strip", z.ZodTypeAny, {
|
|
460
|
+
product_cart?: {
|
|
461
|
+
quantity: number;
|
|
462
|
+
product_id: string;
|
|
463
|
+
}[] | undefined;
|
|
464
|
+
customer?: {
|
|
465
|
+
email?: string | undefined;
|
|
466
|
+
name?: string | undefined;
|
|
467
|
+
phone_number?: string | undefined;
|
|
468
|
+
} | undefined;
|
|
469
|
+
metadata?: Record<string, string> | undefined;
|
|
470
|
+
slug?: string | undefined;
|
|
471
|
+
referenceId?: string | undefined;
|
|
472
|
+
billing_address?: {
|
|
473
|
+
country: string;
|
|
474
|
+
city?: string | undefined;
|
|
475
|
+
state?: string | undefined;
|
|
476
|
+
street?: string | undefined;
|
|
477
|
+
zipcode?: string | undefined;
|
|
478
|
+
} | undefined;
|
|
479
|
+
return_url?: string | undefined;
|
|
480
|
+
allowed_payment_method_types?: ("credit" | "debit" | "upi_collect" | "upi_intent" | "apple_pay" | "google_pay" | "amazon_pay" | "klarna" | "affirm" | "afterpay_clearpay" | "sepa" | "ach")[] | undefined;
|
|
481
|
+
billing_currency?: string | undefined;
|
|
482
|
+
show_saved_payment_methods?: boolean | undefined;
|
|
483
|
+
confirm?: boolean | undefined;
|
|
484
|
+
discount_code?: string | undefined;
|
|
485
|
+
customization?: {
|
|
486
|
+
theme?: "light" | "dark" | "system" | undefined;
|
|
487
|
+
show_order_details?: boolean | undefined;
|
|
488
|
+
show_on_demand_tag?: boolean | undefined;
|
|
489
|
+
} | undefined;
|
|
490
|
+
feature_flags?: {
|
|
491
|
+
allow_currency_selection?: boolean | undefined;
|
|
492
|
+
allow_discount_code?: boolean | undefined;
|
|
493
|
+
allow_phone_number_collection?: boolean | undefined;
|
|
494
|
+
allow_tax_id?: boolean | undefined;
|
|
495
|
+
always_create_new_customer?: boolean | undefined;
|
|
496
|
+
} | undefined;
|
|
497
|
+
subscription_data?: {
|
|
498
|
+
trial_period_days?: number | undefined;
|
|
499
|
+
} | undefined;
|
|
500
|
+
}, {
|
|
501
|
+
product_cart?: {
|
|
502
|
+
quantity: number;
|
|
503
|
+
product_id: string;
|
|
504
|
+
}[] | undefined;
|
|
505
|
+
customer?: {
|
|
506
|
+
email?: string | undefined;
|
|
507
|
+
name?: string | undefined;
|
|
508
|
+
phone_number?: string | undefined;
|
|
509
|
+
} | undefined;
|
|
510
|
+
metadata?: Record<string, string> | undefined;
|
|
511
|
+
slug?: string | undefined;
|
|
512
|
+
referenceId?: string | undefined;
|
|
513
|
+
billing_address?: {
|
|
514
|
+
country: string;
|
|
515
|
+
city?: string | undefined;
|
|
516
|
+
state?: string | undefined;
|
|
517
|
+
street?: string | undefined;
|
|
518
|
+
zipcode?: string | undefined;
|
|
519
|
+
} | undefined;
|
|
520
|
+
return_url?: string | undefined;
|
|
521
|
+
allowed_payment_method_types?: ("credit" | "debit" | "upi_collect" | "upi_intent" | "apple_pay" | "google_pay" | "amazon_pay" | "klarna" | "affirm" | "afterpay_clearpay" | "sepa" | "ach")[] | undefined;
|
|
522
|
+
billing_currency?: string | undefined;
|
|
523
|
+
show_saved_payment_methods?: boolean | undefined;
|
|
524
|
+
confirm?: boolean | undefined;
|
|
525
|
+
discount_code?: string | undefined;
|
|
526
|
+
customization?: {
|
|
527
|
+
theme?: "light" | "dark" | "system" | undefined;
|
|
528
|
+
show_order_details?: boolean | undefined;
|
|
529
|
+
show_on_demand_tag?: boolean | undefined;
|
|
530
|
+
} | undefined;
|
|
531
|
+
feature_flags?: {
|
|
532
|
+
allow_currency_selection?: boolean | undefined;
|
|
533
|
+
allow_discount_code?: boolean | undefined;
|
|
534
|
+
allow_phone_number_collection?: boolean | undefined;
|
|
535
|
+
allow_tax_id?: boolean | undefined;
|
|
536
|
+
always_create_new_customer?: boolean | undefined;
|
|
537
|
+
} | undefined;
|
|
538
|
+
subscription_data?: {
|
|
539
|
+
trial_period_days?: number | undefined;
|
|
540
|
+
} | undefined;
|
|
541
|
+
}>;
|
|
542
|
+
requireRequest: true;
|
|
543
|
+
} & {
|
|
544
|
+
use: any[];
|
|
545
|
+
};
|
|
546
|
+
path: "/dodopayments/checkout-session";
|
|
547
|
+
};
|
|
297
548
|
};
|
package/dist/plugins/checkout.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { APIError, getSessionFromCtx } from "better-auth/api";
|
|
2
2
|
import { createAuthEndpoint } from "better-auth/plugins";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { buildCheckoutUrl, dynamicCheckoutBodySchema, } from "@dodopayments/core/checkout";
|
|
4
|
+
import { buildCheckoutUrl, checkoutSessionPayloadSchema, dynamicCheckoutBodySchema, } from "@dodopayments/core/checkout";
|
|
5
5
|
export const checkout = (checkoutOptions = {}) => (dodopayments) => {
|
|
6
6
|
return {
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated
|
|
9
|
+
*/
|
|
7
10
|
checkout: createAuthEndpoint("/dodopayments/checkout", {
|
|
8
11
|
method: "POST",
|
|
9
12
|
body: dynamicCheckoutBodySchema.extend({
|
|
@@ -15,10 +18,9 @@ export const checkout = (checkoutOptions = {}) => (dodopayments) => {
|
|
|
15
18
|
const session = await getSessionFromCtx(ctx);
|
|
16
19
|
let dodoPaymentsProductId;
|
|
17
20
|
if (ctx.body?.slug) {
|
|
18
|
-
const resolvedProducts =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
: checkoutOptions.products);
|
|
21
|
+
const resolvedProducts = typeof checkoutOptions.products === "function"
|
|
22
|
+
? await checkoutOptions.products()
|
|
23
|
+
: checkoutOptions.products;
|
|
22
24
|
const productId = resolvedProducts?.find((product) => product.slug === ctx.body.slug)?.productId;
|
|
23
25
|
if (!productId) {
|
|
24
26
|
throw new APIError("BAD_REQUEST", {
|
|
@@ -84,5 +86,86 @@ export const checkout = (checkoutOptions = {}) => (dodopayments) => {
|
|
|
84
86
|
});
|
|
85
87
|
}
|
|
86
88
|
}),
|
|
89
|
+
checkoutSession: createAuthEndpoint("/dodopayments/checkout-session", {
|
|
90
|
+
method: "POST",
|
|
91
|
+
body: checkoutSessionPayloadSchema
|
|
92
|
+
.extend({
|
|
93
|
+
slug: z.string().optional(),
|
|
94
|
+
referenceId: z.string().optional(),
|
|
95
|
+
})
|
|
96
|
+
.partial({
|
|
97
|
+
product_cart: true,
|
|
98
|
+
}),
|
|
99
|
+
requireRequest: true,
|
|
100
|
+
}, async (ctx) => {
|
|
101
|
+
const session = await getSessionFromCtx(ctx);
|
|
102
|
+
let dodoPaymentsProductId;
|
|
103
|
+
if (ctx.body?.slug) {
|
|
104
|
+
const resolvedProducts = typeof checkoutOptions.products === "function"
|
|
105
|
+
? await checkoutOptions.products()
|
|
106
|
+
: checkoutOptions.products;
|
|
107
|
+
const productId = resolvedProducts?.find((product) => product.slug === ctx.body.slug)?.productId;
|
|
108
|
+
if (!productId) {
|
|
109
|
+
throw new APIError("BAD_REQUEST", {
|
|
110
|
+
message: "Product not found",
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
dodoPaymentsProductId = productId;
|
|
114
|
+
}
|
|
115
|
+
if (checkoutOptions.authenticatedUsersOnly && !session?.user.id) {
|
|
116
|
+
throw new APIError("UNAUTHORIZED", {
|
|
117
|
+
message: "You must be logged in to checkout",
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
// Ensure we have a product_cart
|
|
121
|
+
const product_cart = dodoPaymentsProductId
|
|
122
|
+
? [{ product_id: dodoPaymentsProductId, quantity: 1 }]
|
|
123
|
+
: ctx.body.product_cart;
|
|
124
|
+
if (!product_cart || product_cart.length === 0) {
|
|
125
|
+
throw new APIError("BAD_REQUEST", {
|
|
126
|
+
message: "Neither product_cart nor slug was provided",
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
const checkoutUrl = await buildCheckoutUrl({
|
|
131
|
+
sessionPayload: {
|
|
132
|
+
...ctx.body,
|
|
133
|
+
product_cart,
|
|
134
|
+
customer: {
|
|
135
|
+
email: session?.user.email,
|
|
136
|
+
name: session?.user.name,
|
|
137
|
+
...ctx.body.customer,
|
|
138
|
+
},
|
|
139
|
+
metadata: ctx.body.referenceId
|
|
140
|
+
? {
|
|
141
|
+
referenceId: ctx.body.referenceId,
|
|
142
|
+
...ctx.body.metadata,
|
|
143
|
+
}
|
|
144
|
+
: ctx.body.metadata,
|
|
145
|
+
return_url: checkoutOptions.successUrl
|
|
146
|
+
? new URL(checkoutOptions.successUrl, ctx.request?.url).toString()
|
|
147
|
+
: undefined,
|
|
148
|
+
},
|
|
149
|
+
bearerToken: dodopayments.bearerToken,
|
|
150
|
+
environment: dodopayments.baseURL.includes("test")
|
|
151
|
+
? "test_mode"
|
|
152
|
+
: "live_mode",
|
|
153
|
+
type: "session",
|
|
154
|
+
});
|
|
155
|
+
const redirectUrl = new URL(checkoutUrl);
|
|
156
|
+
return ctx.json({
|
|
157
|
+
url: redirectUrl.toString(),
|
|
158
|
+
redirect: true,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
if (e instanceof Error) {
|
|
163
|
+
ctx.context.logger.error(`DodoPayments checkout creation failed. Error: ${e.message}`);
|
|
164
|
+
}
|
|
165
|
+
throw new APIError("INTERNAL_SERVER_ERROR", {
|
|
166
|
+
message: "Checkout session creation failed",
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}),
|
|
87
170
|
};
|
|
88
171
|
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dodopayments/better-auth",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"dev": "rollup -c -w",
|
|
10
|
-
"format": "prettier --write .",
|
|
11
|
-
"check-format": "prettier --check .",
|
|
12
10
|
"check-types": "tsc --noEmit"
|
|
13
11
|
},
|
|
14
12
|
"exports": {
|
|
@@ -20,7 +18,7 @@
|
|
|
20
18
|
},
|
|
21
19
|
"types": "./dist/index.d.ts",
|
|
22
20
|
"dependencies": {
|
|
23
|
-
"@dodopayments/core": "^0.
|
|
21
|
+
"@dodopayments/core": "^0.2.0"
|
|
24
22
|
},
|
|
25
23
|
"engines": {
|
|
26
24
|
"node": ">=16.0.0"
|
|
@@ -49,7 +47,6 @@
|
|
|
49
47
|
"rollup-plugin-dts": "^6.1.0"
|
|
50
48
|
},
|
|
51
49
|
"peerDependencies": {
|
|
52
|
-
"dodopayments": "^1.53.0",
|
|
53
50
|
"zod": "^3.0.0"
|
|
54
51
|
},
|
|
55
52
|
"type": "module",
|