@dodopayments/better-auth
Version:
A Better Auth plugin for integrating Dodo Payments into your authentication flow.
541 lines (540 loc) • 27.1 kB
TypeScript
import type { DodoPaymentsOptions } from "./types";
export type { Product, DodoPaymentsPlugin, DodoPaymentsPlugins, DodoPaymentsEndpoints, DodoPaymentsOptions, PaymentItems, SubscriptionItems, CustomerPortalResponse, CreateCheckoutResponse, WebhookResponse, } from "./types";
export { dodopaymentsClient } from "./client";
export { portal } from "./plugins/portal";
export { checkout, CheckoutOptions } from "./plugins/checkout";
export { webhooks } from "./plugins/webhooks";
export declare const dodopayments: (options: DodoPaymentsOptions) => {
id: "dodopayments";
endpoints: {
checkout: {
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: {
body: import("zod").objectInputType<{
product_id: import("zod").ZodOptional<import("zod").ZodString>;
quantity: import("zod").ZodOptional<import("zod").ZodNumber>;
product_cart: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
product_id: import("zod").ZodString;
quantity: import("zod").ZodNumber;
}, "strip", import("zod").ZodTypeAny, {
quantity: number;
product_id: string;
}, {
quantity: number;
product_id: string;
}>, "many">>;
billing: import("zod").ZodObject<{
city: import("zod").ZodString;
country: import("zod").ZodString;
state: import("zod").ZodString;
street: import("zod").ZodString;
zipcode: import("zod").ZodString;
}, "strip", import("zod").ZodTypeAny, {
country: string;
city: string;
state: string;
street: string;
zipcode: string;
}, {
country: string;
city: string;
state: string;
street: string;
zipcode: string;
}>;
customer: import("zod").ZodObject<{
customer_id: import("zod").ZodOptional<import("zod").ZodString>;
email: import("zod").ZodOptional<import("zod").ZodString>;
name: import("zod").ZodOptional<import("zod").ZodString>;
}, "strip", import("zod").ZodTypeAny, {
email?: string | undefined;
customer_id?: string | undefined;
name?: string | undefined;
}, {
email?: string | undefined;
customer_id?: string | undefined;
name?: string | undefined;
}>;
discount_id: import("zod").ZodOptional<import("zod").ZodString>;
addons: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
addon_id: import("zod").ZodString;
quantity: import("zod").ZodNumber;
}, "strip", import("zod").ZodTypeAny, {
quantity: number;
addon_id: string;
}, {
quantity: number;
addon_id: string;
}>, "many">>;
metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodString>>;
currency: import("zod").ZodOptional<import("zod").ZodString>;
} & {
slug: import("zod").ZodOptional<import("zod").ZodString>;
referenceId: import("zod").ZodOptional<import("zod").ZodString>;
}, import("zod").ZodUnknown, "strip">;
} & {
method?: "POST" | undefined;
} & {
query?: Record<string, any> | undefined;
} & {
params?: Record<string, any>;
} & {
request: Request;
} & {
headers?: HeadersInit;
} & {
asResponse?: boolean;
returnHeaders?: boolean;
use?: import("better-call").Middleware[];
path?: string;
} & {
asResponse?: AsResponse | undefined;
returnHeaders?: ReturnHeaders | undefined;
}): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
headers: Headers;
response: import("./types").CreateCheckoutResponse;
} : import("./types").CreateCheckoutResponse>;
options: {
method: "POST";
body: import("zod").ZodObject<{
product_id: import("zod").ZodOptional<import("zod").ZodString>;
quantity: import("zod").ZodOptional<import("zod").ZodNumber>;
product_cart: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
product_id: import("zod").ZodString;
quantity: import("zod").ZodNumber;
}, "strip", import("zod").ZodTypeAny, {
quantity: number;
product_id: string;
}, {
quantity: number;
product_id: string;
}>, "many">>;
billing: import("zod").ZodObject<{
city: import("zod").ZodString;
country: import("zod").ZodString;
state: import("zod").ZodString;
street: import("zod").ZodString;
zipcode: import("zod").ZodString;
}, "strip", import("zod").ZodTypeAny, {
country: string;
city: string;
state: string;
street: string;
zipcode: string;
}, {
country: string;
city: string;
state: string;
street: string;
zipcode: string;
}>;
customer: import("zod").ZodObject<{
customer_id: import("zod").ZodOptional<import("zod").ZodString>;
email: import("zod").ZodOptional<import("zod").ZodString>;
name: import("zod").ZodOptional<import("zod").ZodString>;
}, "strip", import("zod").ZodTypeAny, {
email?: string | undefined;
customer_id?: string | undefined;
name?: string | undefined;
}, {
email?: string | undefined;
customer_id?: string | undefined;
name?: string | undefined;
}>;
discount_id: import("zod").ZodOptional<import("zod").ZodString>;
addons: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
addon_id: import("zod").ZodString;
quantity: import("zod").ZodNumber;
}, "strip", import("zod").ZodTypeAny, {
quantity: number;
addon_id: string;
}, {
quantity: number;
addon_id: string;
}>, "many">>;
metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodString>>;
currency: import("zod").ZodOptional<import("zod").ZodString>;
} & {
slug: import("zod").ZodOptional<import("zod").ZodString>;
referenceId: import("zod").ZodOptional<import("zod").ZodString>;
}, "strip", import("zod").ZodUnknown, import("zod").objectOutputType<{
product_id: import("zod").ZodOptional<import("zod").ZodString>;
quantity: import("zod").ZodOptional<import("zod").ZodNumber>;
product_cart: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
product_id: import("zod").ZodString;
quantity: import("zod").ZodNumber;
}, "strip", import("zod").ZodTypeAny, {
quantity: number;
product_id: string;
}, {
quantity: number;
product_id: string;
}>, "many">>;
billing: import("zod").ZodObject<{
city: import("zod").ZodString;
country: import("zod").ZodString;
state: import("zod").ZodString;
street: import("zod").ZodString;
zipcode: import("zod").ZodString;
}, "strip", import("zod").ZodTypeAny, {
country: string;
city: string;
state: string;
street: string;
zipcode: string;
}, {
country: string;
city: string;
state: string;
street: string;
zipcode: string;
}>;
customer: import("zod").ZodObject<{
customer_id: import("zod").ZodOptional<import("zod").ZodString>;
email: import("zod").ZodOptional<import("zod").ZodString>;
name: import("zod").ZodOptional<import("zod").ZodString>;
}, "strip", import("zod").ZodTypeAny, {
email?: string | undefined;
customer_id?: string | undefined;
name?: string | undefined;
}, {
email?: string | undefined;
customer_id?: string | undefined;
name?: string | undefined;
}>;
discount_id: import("zod").ZodOptional<import("zod").ZodString>;
addons: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
addon_id: import("zod").ZodString;
quantity: import("zod").ZodNumber;
}, "strip", import("zod").ZodTypeAny, {
quantity: number;
addon_id: string;
}, {
quantity: number;
addon_id: string;
}>, "many">>;
metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodString>>;
currency: import("zod").ZodOptional<import("zod").ZodString>;
} & {
slug: import("zod").ZodOptional<import("zod").ZodString>;
referenceId: import("zod").ZodOptional<import("zod").ZodString>;
}, import("zod").ZodUnknown, "strip">, import("zod").objectInputType<{
product_id: import("zod").ZodOptional<import("zod").ZodString>;
quantity: import("zod").ZodOptional<import("zod").ZodNumber>;
product_cart: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
product_id: import("zod").ZodString;
quantity: import("zod").ZodNumber;
}, "strip", import("zod").ZodTypeAny, {
quantity: number;
product_id: string;
}, {
quantity: number;
product_id: string;
}>, "many">>;
billing: import("zod").ZodObject<{
city: import("zod").ZodString;
country: import("zod").ZodString;
state: import("zod").ZodString;
street: import("zod").ZodString;
zipcode: import("zod").ZodString;
}, "strip", import("zod").ZodTypeAny, {
country: string;
city: string;
state: string;
street: string;
zipcode: string;
}, {
country: string;
city: string;
state: string;
street: string;
zipcode: string;
}>;
customer: import("zod").ZodObject<{
customer_id: import("zod").ZodOptional<import("zod").ZodString>;
email: import("zod").ZodOptional<import("zod").ZodString>;
name: import("zod").ZodOptional<import("zod").ZodString>;
}, "strip", import("zod").ZodTypeAny, {
email?: string | undefined;
customer_id?: string | undefined;
name?: string | undefined;
}, {
email?: string | undefined;
customer_id?: string | undefined;
name?: string | undefined;
}>;
discount_id: import("zod").ZodOptional<import("zod").ZodString>;
addons: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
addon_id: import("zod").ZodString;
quantity: import("zod").ZodNumber;
}, "strip", import("zod").ZodTypeAny, {
quantity: number;
addon_id: string;
}, {
quantity: number;
addon_id: string;
}>, "many">>;
metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodString>>;
currency: import("zod").ZodOptional<import("zod").ZodString>;
} & {
slug: import("zod").ZodOptional<import("zod").ZodString>;
referenceId: import("zod").ZodOptional<import("zod").ZodString>;
}, import("zod").ZodUnknown, "strip">>;
requireRequest: true;
} & {
use: any[];
};
path: "/dodopayments/checkout";
};
} | {
portal: {
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({
body?: undefined;
} & {
method?: "GET" | undefined;
} & {
query?: Record<string, any> | undefined;
} & {
params?: Record<string, any>;
} & {
request?: Request;
} & {
headers?: HeadersInit;
} & {
asResponse?: boolean;
returnHeaders?: boolean;
use?: import("better-call").Middleware[];
path?: string;
} & {
asResponse?: AsResponse | undefined;
returnHeaders?: ReturnHeaders | undefined;
}) | undefined): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
headers: Headers;
response: import("./types").CustomerPortalResponse;
} : import("./types").CustomerPortalResponse>;
options: {
method: "GET";
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
session: {
session: Record<string, any> & {
id: string;
userId: string;
expiresAt: Date;
createdAt: Date;
updatedAt: Date;
token: string;
ipAddress?: string | null | undefined;
userAgent?: string | null | undefined;
};
user: Record<string, any> & {
id: string;
email: string;
emailVerified: boolean;
name: string;
createdAt: Date;
updatedAt: Date;
image?: string | null | undefined;
};
};
}>)[];
} & {
use: any[];
};
path: "/dodopayments/customer/portal";
};
subscriptions: {
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({
body?: undefined;
} & {
method?: "GET" | undefined;
} & {
query?: {
status?: "active" | "cancelled" | "on_hold" | "pending" | "failed" | "expired" | undefined;
page?: number | undefined;
limit?: number | undefined;
} | undefined;
} & {
params?: Record<string, any>;
} & {
request?: Request;
} & {
headers?: HeadersInit;
} & {
asResponse?: boolean;
returnHeaders?: boolean;
use?: import("better-call").Middleware[];
path?: string;
} & {
asResponse?: AsResponse | undefined;
returnHeaders?: ReturnHeaders | undefined;
}) | undefined): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
headers: Headers;
response: import("./types").SubscriptionItems;
} : import("./types").SubscriptionItems>;
options: {
method: "GET";
query: import("zod").ZodOptional<import("zod").ZodObject<{
page: import("zod").ZodOptional<import("zod").ZodNumber>;
limit: import("zod").ZodOptional<import("zod").ZodNumber>;
status: import("zod").ZodOptional<import("zod").ZodEnum<["active", "cancelled", "on_hold", "pending", "failed", "expired"]>>;
}, "strip", import("zod").ZodTypeAny, {
status?: "active" | "cancelled" | "on_hold" | "pending" | "failed" | "expired" | undefined;
page?: number | undefined;
limit?: number | undefined;
}, {
status?: "active" | "cancelled" | "on_hold" | "pending" | "failed" | "expired" | undefined;
page?: number | undefined;
limit?: number | undefined;
}>>;
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
session: {
session: Record<string, any> & {
id: string;
userId: string;
expiresAt: Date;
createdAt: Date;
updatedAt: Date;
token: string;
ipAddress?: string | null | undefined;
userAgent?: string | null | undefined;
};
user: Record<string, any> & {
id: string;
email: string;
emailVerified: boolean;
name: string;
createdAt: Date;
updatedAt: Date;
image?: string | null | undefined;
};
};
}>)[];
} & {
use: any[];
};
path: "/dodopayments/customer/subscriptions/list";
};
payments: {
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({
body?: undefined;
} & {
method?: "GET" | undefined;
} & {
query?: {
status?: "cancelled" | "failed" | "succeeded" | "processing" | "requires_customer_action" | "requires_merchant_action" | "requires_payment_method" | "requires_confirmation" | "requires_capture" | "partially_captured" | "partially_captured_and_capturable" | undefined;
page?: number | undefined;
limit?: number | undefined;
} | undefined;
} & {
params?: Record<string, any>;
} & {
request?: Request;
} & {
headers?: HeadersInit;
} & {
asResponse?: boolean;
returnHeaders?: boolean;
use?: import("better-call").Middleware[];
path?: string;
} & {
asResponse?: AsResponse | undefined;
returnHeaders?: ReturnHeaders | undefined;
}) | undefined): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
headers: Headers;
response: import("./types").PaymentItems;
} : import("./types").PaymentItems>;
options: {
method: "GET";
query: import("zod").ZodOptional<import("zod").ZodObject<{
page: import("zod").ZodOptional<import("zod").ZodNumber>;
limit: import("zod").ZodOptional<import("zod").ZodNumber>;
status: import("zod").ZodOptional<import("zod").ZodEnum<["succeeded", "failed", "cancelled", "processing", "requires_customer_action", "requires_merchant_action", "requires_payment_method", "requires_confirmation", "requires_capture", "partially_captured", "partially_captured_and_capturable"]>>;
}, "strip", import("zod").ZodTypeAny, {
status?: "cancelled" | "failed" | "succeeded" | "processing" | "requires_customer_action" | "requires_merchant_action" | "requires_payment_method" | "requires_confirmation" | "requires_capture" | "partially_captured" | "partially_captured_and_capturable" | undefined;
page?: number | undefined;
limit?: number | undefined;
}, {
status?: "cancelled" | "failed" | "succeeded" | "processing" | "requires_customer_action" | "requires_merchant_action" | "requires_payment_method" | "requires_confirmation" | "requires_capture" | "partially_captured" | "partially_captured_and_capturable" | undefined;
page?: number | undefined;
limit?: number | undefined;
}>>;
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
session: {
session: Record<string, any> & {
id: string;
userId: string;
expiresAt: Date;
createdAt: Date;
updatedAt: Date;
token: string;
ipAddress?: string | null | undefined;
userAgent?: string | null | undefined;
};
user: Record<string, any> & {
id: string;
email: string;
emailVerified: boolean;
name: string;
createdAt: Date;
updatedAt: Date;
image?: string | null | undefined;
};
};
}>)[];
} & {
use: any[];
};
path: "/dodopayments/customer/payments/list";
};
} | {
dodopaymentsWebhooks: {
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({
body?: undefined;
} & {
method?: "POST" | undefined;
} & {
query?: Record<string, any> | undefined;
} & {
params?: Record<string, any>;
} & {
request?: Request;
} & {
headers?: HeadersInit;
} & {
asResponse?: boolean;
returnHeaders?: boolean;
use?: import("better-call").Middleware[];
path?: string;
} & {
asResponse?: AsResponse | undefined;
returnHeaders?: ReturnHeaders | undefined;
}) | undefined): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
headers: Headers;
response: import("./types").WebhookResponse;
} : import("./types").WebhookResponse>;
options: {
method: "POST";
metadata: {
isAction: boolean;
};
cloneRequest: true;
} & {
use: any[];
};
path: "/dodopayments/webhooks";
};
};
init(): {
options: {
databaseHooks: {
user: {
create: {
after: (user: import("better-auth").User, ctx?: import("better-auth").GenericEndpointContext) => Promise<void>;
};
update: {
after: (user: import("better-auth").User, ctx?: import("better-auth").GenericEndpointContext) => Promise<void>;
};
};
};
};
};
};