paddle-checkout-accelerator 2.1.0 → 2.2.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.
Files changed (81) hide show
  1. package/bin/paddle-checkout-accelerator.js +247 -0
  2. package/dist/index.cjs +1150 -0
  3. package/dist/index.d.cts +290 -0
  4. package/dist/index.d.ts +290 -0
  5. package/dist/index.js +1079 -0
  6. package/package.json +14 -7
  7. package/recipes/nextjs/app/billing.ts +1 -1
  8. package/dist/package/index.d.ts +0 -28
  9. package/dist/package/index.js +0 -28
  10. package/dist/src/components/paddle/BillingHistory.d.ts +0 -1
  11. package/dist/src/components/paddle/BillingHistory.js +0 -17
  12. package/dist/src/components/paddle/CustomerPortal.d.ts +0 -1
  13. package/dist/src/components/paddle/CustomerPortal.js +0 -5
  14. package/dist/src/components/paddle/CustomerPortalButton.d.ts +0 -1
  15. package/dist/src/components/paddle/CustomerPortalButton.js +0 -31
  16. package/dist/src/components/paddle/InlineCheckout.d.ts +0 -5
  17. package/dist/src/components/paddle/InlineCheckout.js +0 -13
  18. package/dist/src/components/paddle/PricingTable.d.ts +0 -1
  19. package/dist/src/components/paddle/PricingTable.js +0 -27
  20. package/dist/src/components/paddle/SubscriptionCard.d.ts +0 -6
  21. package/dist/src/components/paddle/SubscriptionCard.js +0 -5
  22. package/dist/src/components/paddle/TrialBanner.d.ts +0 -5
  23. package/dist/src/components/paddle/TrialBanner.js +0 -5
  24. package/dist/src/components/paddle/UpgradeModal.d.ts +0 -11
  25. package/dist/src/components/paddle/UpgradeModal.js +0 -35
  26. package/dist/src/components/paddle/UsageMeter.d.ts +0 -6
  27. package/dist/src/components/paddle/UsageMeter.js +0 -8
  28. package/dist/src/components/paddle/gates/SubscriptionGate.d.ts +0 -7
  29. package/dist/src/components/paddle/gates/SubscriptionGate.js +0 -8
  30. package/dist/src/lib/billing/adapters/index.d.ts +0 -3
  31. package/dist/src/lib/billing/adapters/index.js +0 -3
  32. package/dist/src/lib/billing/adapters/memory.d.ts +0 -2
  33. package/dist/src/lib/billing/adapters/memory.js +0 -41
  34. package/dist/src/lib/billing/adapters/prisma/index.d.ts +0 -28
  35. package/dist/src/lib/billing/adapters/prisma/index.js +0 -80
  36. package/dist/src/lib/billing/adapters/types.d.ts +0 -13
  37. package/dist/src/lib/billing/adapters/types.js +0 -1
  38. package/dist/src/lib/billing/configure.d.ts +0 -6
  39. package/dist/src/lib/billing/configure.js +0 -13
  40. package/dist/src/lib/billing/customer-repair.d.ts +0 -4
  41. package/dist/src/lib/billing/customer-repair.js +0 -19
  42. package/dist/src/lib/billing/demo-seed.d.ts +0 -1
  43. package/dist/src/lib/billing/demo-seed.js +0 -13
  44. package/dist/src/lib/billing/entitlements.d.ts +0 -3
  45. package/dist/src/lib/billing/entitlements.js +0 -16
  46. package/dist/src/lib/billing/events.d.ts +0 -12
  47. package/dist/src/lib/billing/events.js +0 -20
  48. package/dist/src/lib/billing/plans.d.ts +0 -9
  49. package/dist/src/lib/billing/plans.js +0 -41
  50. package/dist/src/lib/billing/protection.d.ts +0 -6
  51. package/dist/src/lib/billing/protection.js +0 -16
  52. package/dist/src/lib/billing/refresh.d.ts +0 -1
  53. package/dist/src/lib/billing/refresh.js +0 -32
  54. package/dist/src/lib/billing/subscriptions.d.ts +0 -16
  55. package/dist/src/lib/billing/subscriptions.js +0 -36
  56. package/dist/src/lib/billing/teams.d.ts +0 -42
  57. package/dist/src/lib/billing/teams.js +0 -104
  58. package/dist/src/lib/billing/usage.d.ts +0 -17
  59. package/dist/src/lib/billing/usage.js +0 -40
  60. package/dist/src/lib/billing/webhook-sync.d.ts +0 -26
  61. package/dist/src/lib/billing/webhook-sync.js +0 -39
  62. package/dist/src/lib/paddle/api.d.ts +0 -1
  63. package/dist/src/lib/paddle/api.js +0 -21
  64. package/dist/src/lib/paddle/client.d.ts +0 -1
  65. package/dist/src/lib/paddle/client.js +0 -13
  66. package/dist/src/lib/paddle/customers.d.ts +0 -15
  67. package/dist/src/lib/paddle/customers.js +0 -14
  68. package/dist/src/lib/paddle/events.d.ts +0 -10
  69. package/dist/src/lib/paddle/events.js +0 -11
  70. package/dist/src/lib/paddle/hooks.d.ts +0 -4
  71. package/dist/src/lib/paddle/hooks.js +0 -11
  72. package/dist/src/lib/paddle/portal.d.ts +0 -8
  73. package/dist/src/lib/paddle/portal.js +0 -28
  74. package/dist/src/lib/paddle/subscriptions.d.ts +0 -20
  75. package/dist/src/lib/paddle/subscriptions.js +0 -10
  76. package/dist/src/lib/paddle/types.d.ts +0 -8
  77. package/dist/src/lib/paddle/types.js +0 -1
  78. package/dist/src/lib/paddle/webhook.d.ts +0 -1
  79. package/dist/src/lib/paddle/webhook.js +0 -8
  80. package/dist/src/lib/utils.d.ts +0 -2
  81. package/dist/src/lib/utils.js +0 -5
@@ -1,12 +0,0 @@
1
- import { type BillingAdapter } from "./adapters";
2
- export type BillingEventType = "subscription_created" | "payment_succeeded" | "payment_failed" | "subscription_updated" | "subscription_paused" | "subscription_canceled" | "portal_opened" | "repair_performed";
3
- export interface BillingEvent {
4
- id: string;
5
- userId: string;
6
- type: BillingEventType;
7
- createdAt: string;
8
- metadata?: Record<string, unknown>;
9
- }
10
- export declare function setBillingEventAdapter(nextAdapter: BillingAdapter): void;
11
- export declare function recordBillingEvent(event: BillingEvent): Promise<BillingEvent>;
12
- export declare function getBillingEvents(userId: string): Promise<BillingEvent[]>;
@@ -1,20 +0,0 @@
1
- import { memoryBillingAdapter, } from "./adapters";
2
- let adapter = memoryBillingAdapter;
3
- export function setBillingEventAdapter(nextAdapter) {
4
- adapter = nextAdapter;
5
- }
6
- function requireEventAdapter() {
7
- if (!adapter.recordBillingEvent ||
8
- !adapter.getBillingEvents) {
9
- throw new Error("Billing adapter does not support event operations");
10
- }
11
- return adapter;
12
- }
13
- export async function recordBillingEvent(event) {
14
- return requireEventAdapter()
15
- .recordBillingEvent(event);
16
- }
17
- export async function getBillingEvents(userId) {
18
- return requireEventAdapter()
19
- .getBillingEvents(userId);
20
- }
@@ -1,9 +0,0 @@
1
- export type PlanId = "free" | "starter" | "pro" | "business";
2
- export type FeatureKey = "checkout" | "customer_portal" | "usage_limits" | "team_members" | "api_access" | "priority_support";
3
- export declare const plans: Record<PlanId, {
4
- name: string;
5
- monthlyLimit: number;
6
- seatLimit: number;
7
- features: FeatureKey[];
8
- }>;
9
- export declare function getPlanSeatLimit(plan: PlanId): number;
@@ -1,41 +0,0 @@
1
- export const plans = {
2
- free: {
3
- name: "Free",
4
- monthlyLimit: 25,
5
- seatLimit: 1,
6
- features: ["checkout"],
7
- },
8
- starter: {
9
- name: "Starter",
10
- monthlyLimit: 500,
11
- seatLimit: 1,
12
- features: ["checkout", "customer_portal"],
13
- },
14
- pro: {
15
- name: "Pro",
16
- monthlyLimit: 5000,
17
- seatLimit: 5,
18
- features: [
19
- "checkout",
20
- "customer_portal",
21
- "usage_limits",
22
- "api_access",
23
- ],
24
- },
25
- business: {
26
- name: "Business",
27
- monthlyLimit: 50000,
28
- seatLimit: 25,
29
- features: [
30
- "checkout",
31
- "customer_portal",
32
- "usage_limits",
33
- "team_members",
34
- "api_access",
35
- "priority_support",
36
- ],
37
- },
38
- };
39
- export function getPlanSeatLimit(plan) {
40
- return plans[plan].seatLimit;
41
- }
@@ -1,6 +0,0 @@
1
- import type { PlanId, FeatureKey } from "./plans";
2
- export declare function protectPlan(userId: string, plan: PlanId): Promise<import("./subscriptions").SubscriptionRecord>;
3
- export declare function protectFeature(userId: string, feature: FeatureKey): Promise<boolean>;
4
- export declare function protectUsage(userId: string, usageKey: string, amount?: number): Promise<{
5
- allowed: boolean;
6
- }>;
@@ -1,16 +0,0 @@
1
- import { requireFeature } from "./entitlements";
2
- import { requireSubscription } from "./subscriptions";
3
- import { requireUsage, incrementUsage } from "./usage";
4
- export async function protectPlan(userId, plan) {
5
- return requireSubscription(userId, plan);
6
- }
7
- export async function protectFeature(userId, feature) {
8
- return requireFeature(userId, feature);
9
- }
10
- export async function protectUsage(userId, usageKey, amount = 1) {
11
- await requireUsage(userId, usageKey);
12
- await incrementUsage(userId, usageKey, amount);
13
- return {
14
- allowed: true,
15
- };
16
- }
@@ -1 +0,0 @@
1
- export declare function refreshSubscriptionFromPaddle(subscriptionId: string): Promise<import("./subscriptions").SubscriptionRecord>;
@@ -1,32 +0,0 @@
1
- import { upsertSubscription } from "./subscriptions";
2
- import { fetchPaddleSubscription } from "@/lib/paddle/subscriptions";
3
- function mapStatus(status) {
4
- if (status === "active")
5
- return "active";
6
- if (status === "trialing")
7
- return "trialing";
8
- if (status === "paused")
9
- return "paused";
10
- if (status === "canceled")
11
- return "canceled";
12
- if (status === "past_due")
13
- return "past_due";
14
- return "none";
15
- }
16
- export async function refreshSubscriptionFromPaddle(subscriptionId) {
17
- const response = await fetchPaddleSubscription(subscriptionId);
18
- const sub = response.data;
19
- const userId = sub?.custom_data?.userId;
20
- if (!sub || !userId) {
21
- throw new Error("Paddle subscription missing custom_data.userId");
22
- }
23
- const plan = sub.custom_data?.plan ?? "starter";
24
- return upsertSubscription({
25
- userId,
26
- plan: plan,
27
- status: mapStatus(sub.status),
28
- paddleCustomerId: sub.customer_id,
29
- paddleSubscriptionId: sub.id,
30
- currentPeriodEnd: sub.current_billing_period?.ends_at,
31
- });
32
- }
@@ -1,16 +0,0 @@
1
- import type { PlanId } from "./plans";
2
- import { type BillingAdapter } from "./adapters";
3
- export type SubscriptionStatus = "active" | "trialing" | "past_due" | "paused" | "canceled" | "expired" | "none";
4
- export interface SubscriptionRecord {
5
- userId: string;
6
- plan: PlanId;
7
- status: SubscriptionStatus;
8
- paddleCustomerId?: string;
9
- paddleSubscriptionId?: string;
10
- currentPeriodEnd?: string;
11
- }
12
- export declare function setBillingAdapter(nextAdapter: BillingAdapter): void;
13
- export declare function getSubscription(userId: string): Promise<SubscriptionRecord>;
14
- export declare function upsertSubscription(record: SubscriptionRecord): Promise<SubscriptionRecord>;
15
- export declare function isSubscriptionActive(subscription: SubscriptionRecord): boolean;
16
- export declare function requireSubscription(userId: string, minimumPlan?: PlanId): Promise<SubscriptionRecord>;
@@ -1,36 +0,0 @@
1
- import { memoryBillingAdapter, } from "./adapters";
2
- let adapter = memoryBillingAdapter;
3
- export function setBillingAdapter(nextAdapter) {
4
- adapter = nextAdapter;
5
- }
6
- export async function getSubscription(userId) {
7
- return ((await adapter.getSubscription(userId)) ?? {
8
- userId,
9
- plan: "free",
10
- status: "none",
11
- });
12
- }
13
- export async function upsertSubscription(record) {
14
- return adapter.upsertSubscription(record);
15
- }
16
- export function isSubscriptionActive(subscription) {
17
- return (subscription.status === "active" ||
18
- subscription.status === "trialing");
19
- }
20
- export async function requireSubscription(userId, minimumPlan = "starter") {
21
- const subscription = await getSubscription(userId);
22
- if (!isSubscriptionActive(subscription)) {
23
- throw new Error("Active subscription required");
24
- }
25
- const order = [
26
- "free",
27
- "starter",
28
- "pro",
29
- "business",
30
- ];
31
- if (order.indexOf(subscription.plan) <
32
- order.indexOf(minimumPlan)) {
33
- throw new Error(`${minimumPlan} plan required`);
34
- }
35
- return subscription;
36
- }
@@ -1,42 +0,0 @@
1
- import { type BillingAdapter } from "./adapters";
2
- import { type PlanId } from "./plans";
3
- export type TeamRole = "owner" | "admin" | "member";
4
- export interface TeamMember {
5
- userId: string;
6
- email?: string;
7
- role: TeamRole;
8
- joinedAt: string;
9
- }
10
- export interface TeamRecord {
11
- teamId: string;
12
- name: string;
13
- plan: PlanId;
14
- ownerId: string;
15
- members: TeamMember[];
16
- }
17
- export declare function setTeamAdapter(nextAdapter: BillingAdapter): void;
18
- export declare function createTeam({ teamId, name, ownerId, plan, }: {
19
- teamId: string;
20
- name: string;
21
- ownerId: string;
22
- plan?: PlanId;
23
- }): Promise<TeamRecord>;
24
- export declare function getTeam(teamId: string): Promise<TeamRecord | null>;
25
- export declare function updateTeamPlan(teamId: string, plan: PlanId): Promise<TeamRecord>;
26
- export declare function getSeatUsage(teamId: string): Promise<{
27
- used: number;
28
- limit: number;
29
- remaining: number;
30
- allowed: boolean;
31
- }>;
32
- export declare function canInviteTeamMember(teamId: string): Promise<boolean>;
33
- export declare function addTeamMember({ teamId, userId, email, role, }: {
34
- teamId: string;
35
- userId: string;
36
- email?: string;
37
- role?: TeamRole;
38
- }): Promise<TeamRecord>;
39
- export declare function removeTeamMember({ teamId, userId, }: {
40
- teamId: string;
41
- userId: string;
42
- }): Promise<TeamRecord>;
@@ -1,104 +0,0 @@
1
- import { memoryBillingAdapter, } from "./adapters";
2
- import { getPlanSeatLimit } from "./plans";
3
- let adapter = memoryBillingAdapter;
4
- export function setTeamAdapter(nextAdapter) {
5
- adapter = nextAdapter;
6
- }
7
- function requireTeamAdapter() {
8
- if (!adapter.getTeam || !adapter.upsertTeam) {
9
- throw new Error("Billing adapter does not support team operations");
10
- }
11
- return adapter;
12
- }
13
- export async function createTeam({ teamId, name, ownerId, plan = "free", }) {
14
- const now = new Date().toISOString();
15
- const team = {
16
- teamId,
17
- name,
18
- ownerId,
19
- plan,
20
- members: [
21
- {
22
- userId: ownerId,
23
- role: "owner",
24
- joinedAt: now,
25
- },
26
- ],
27
- };
28
- return requireTeamAdapter()
29
- .upsertTeam(team);
30
- }
31
- export async function getTeam(teamId) {
32
- return requireTeamAdapter()
33
- .getTeam(teamId);
34
- }
35
- export async function updateTeamPlan(teamId, plan) {
36
- const team = await getTeam(teamId);
37
- if (!team) {
38
- throw new Error("Team not found");
39
- }
40
- team.plan = plan;
41
- return requireTeamAdapter()
42
- .upsertTeam(team);
43
- }
44
- export async function getSeatUsage(teamId) {
45
- const team = await getTeam(teamId);
46
- if (!team) {
47
- throw new Error("Team not found");
48
- }
49
- const limit = getPlanSeatLimit(team.plan);
50
- const used = team.members.length;
51
- return {
52
- used,
53
- limit,
54
- remaining: Math.max(0, limit - used),
55
- allowed: used < limit,
56
- };
57
- }
58
- export async function canInviteTeamMember(teamId) {
59
- const usage = await getSeatUsage(teamId);
60
- return usage.allowed;
61
- }
62
- export async function addTeamMember({ teamId, userId, email, role = "member", }) {
63
- const team = await getTeam(teamId);
64
- if (!team) {
65
- throw new Error("Team not found");
66
- }
67
- const alreadyMember = team.members.some((member) => member.userId === userId);
68
- if (alreadyMember) {
69
- return team;
70
- }
71
- const usage = await getSeatUsage(teamId);
72
- if (!usage.allowed) {
73
- throw new Error("Seat limit reached");
74
- }
75
- const nextTeam = {
76
- ...team,
77
- members: [
78
- ...team.members,
79
- {
80
- userId,
81
- email,
82
- role,
83
- joinedAt: new Date().toISOString(),
84
- },
85
- ],
86
- };
87
- return requireTeamAdapter()
88
- .upsertTeam(nextTeam);
89
- }
90
- export async function removeTeamMember({ teamId, userId, }) {
91
- const team = await getTeam(teamId);
92
- if (!team) {
93
- throw new Error("Team not found");
94
- }
95
- if (team.ownerId === userId) {
96
- throw new Error("Cannot remove team owner");
97
- }
98
- const nextTeam = {
99
- ...team,
100
- members: team.members.filter((member) => member.userId !== userId),
101
- };
102
- return requireTeamAdapter()
103
- .upsertTeam(nextTeam);
104
- }
@@ -1,17 +0,0 @@
1
- import { type BillingAdapter } from "./adapters";
2
- export declare function setUsageAdapter(nextAdapter: BillingAdapter): void;
3
- export declare function getUsage(userId: string, key: string): Promise<number>;
4
- export declare function getUsageLimit(userId: string): Promise<number>;
5
- export declare function canUse(userId: string, key: string): Promise<{
6
- allowed: boolean;
7
- used: number;
8
- limit: number;
9
- remaining: number;
10
- }>;
11
- export declare function incrementUsage(userId: string, key: string, amount?: number): Promise<number>;
12
- export declare function requireUsage(userId: string, key: string): Promise<{
13
- allowed: boolean;
14
- used: number;
15
- limit: number;
16
- remaining: number;
17
- }>;
@@ -1,40 +0,0 @@
1
- import { memoryBillingAdapter, } from "./adapters";
2
- import { plans } from "./plans";
3
- import { getSubscription } from "./subscriptions";
4
- let adapter = memoryBillingAdapter;
5
- export function setUsageAdapter(nextAdapter) {
6
- adapter = nextAdapter;
7
- }
8
- function currentPeriod() {
9
- const now = new Date();
10
- return `${now.getUTCFullYear()}-${String(now.getUTCMonth() + 1).padStart(2, "0")}`;
11
- }
12
- export async function getUsage(userId, key) {
13
- return adapter.getUsage(userId, key, currentPeriod());
14
- }
15
- export async function getUsageLimit(userId) {
16
- const subscription = await getSubscription(userId);
17
- return plans[subscription.plan].monthlyLimit;
18
- }
19
- export async function canUse(userId, key) {
20
- const [used, limit] = await Promise.all([
21
- getUsage(userId, key),
22
- getUsageLimit(userId),
23
- ]);
24
- return {
25
- allowed: used < limit,
26
- used,
27
- limit,
28
- remaining: Math.max(0, limit - used),
29
- };
30
- }
31
- export async function incrementUsage(userId, key, amount = 1) {
32
- return adapter.incrementUsage(userId, key, currentPeriod(), amount);
33
- }
34
- export async function requireUsage(userId, key) {
35
- const usage = await canUse(userId, key);
36
- if (!usage.allowed) {
37
- throw new Error("Usage limit reached");
38
- }
39
- return usage;
40
- }
@@ -1,26 +0,0 @@
1
- import type { PlanId } from "./plans";
2
- interface PaddleEvent {
3
- event_type?: string;
4
- data?: {
5
- id?: string;
6
- status?: string;
7
- customer_id?: string;
8
- custom_data?: {
9
- userId?: string;
10
- plan?: PlanId;
11
- };
12
- current_billing_period?: {
13
- ends_at?: string;
14
- };
15
- };
16
- }
17
- export declare function syncPaddleEvent(event: PaddleEvent): Promise<{
18
- synced: boolean;
19
- reason: string;
20
- type?: undefined;
21
- } | {
22
- synced: boolean;
23
- type: string;
24
- reason?: undefined;
25
- }>;
26
- export {};
@@ -1,39 +0,0 @@
1
- import { upsertSubscription } from "./subscriptions";
2
- export async function syncPaddleEvent(event) {
3
- const data = event.data;
4
- const userId = data?.custom_data?.userId;
5
- if (!userId) {
6
- return {
7
- synced: false,
8
- reason: "missing userId in custom_data",
9
- };
10
- }
11
- const plan = data?.custom_data?.plan ?? "starter";
12
- if (event.event_type?.startsWith("subscription.")) {
13
- await upsertSubscription({
14
- userId,
15
- plan,
16
- status: data?.status === "active"
17
- ? "active"
18
- : data?.status === "trialing"
19
- ? "trialing"
20
- : data?.status === "paused"
21
- ? "paused"
22
- : data?.status === "canceled"
23
- ? "canceled"
24
- : "none",
25
- paddleCustomerId: data?.customer_id,
26
- paddleSubscriptionId: data?.id,
27
- currentPeriodEnd: data?.current_billing_period
28
- ?.ends_at,
29
- });
30
- return {
31
- synced: true,
32
- type: "subscription",
33
- };
34
- }
35
- return {
36
- synced: false,
37
- reason: "unhandled event type",
38
- };
39
- }
@@ -1 +0,0 @@
1
- export declare function paddleApi<T>(path: string, options?: RequestInit): Promise<T>;
@@ -1,21 +0,0 @@
1
- const PADDLE_API_BASE = process.env.PADDLE_API_BASE ??
2
- "https://api.paddle.com";
3
- export async function paddleApi(path, options = {}) {
4
- const apiKey = process.env.PADDLE_API_KEY;
5
- if (!apiKey) {
6
- throw new Error("Missing PADDLE_API_KEY");
7
- }
8
- const response = await fetch(`${PADDLE_API_BASE}${path}`, {
9
- ...options,
10
- headers: {
11
- Authorization: `Bearer ${apiKey}`,
12
- "Content-Type": "application/json",
13
- ...options.headers,
14
- },
15
- });
16
- if (!response.ok) {
17
- const text = await response.text();
18
- throw new Error(`Paddle API failed: ${response.status} ${text}`);
19
- }
20
- return response.json();
21
- }
@@ -1 +0,0 @@
1
- export declare function getPaddle(): Promise<import("@paddle/paddle-js").Paddle | undefined>;
@@ -1,13 +0,0 @@
1
- import { initializePaddle } from "@paddle/paddle-js";
2
- let paddleInstance = null;
3
- export async function getPaddle() {
4
- if (paddleInstance) {
5
- return paddleInstance;
6
- }
7
- paddleInstance =
8
- await initializePaddle({
9
- token: process.env
10
- .NEXT_PUBLIC_PADDLE_CLIENT_TOKEN,
11
- });
12
- return paddleInstance;
13
- }
@@ -1,15 +0,0 @@
1
- export interface PaddleCustomer {
2
- id: string;
3
- email?: string;
4
- name?: string;
5
- status?: string;
6
- }
7
- export interface PaddleCustomerListResponse {
8
- data?: PaddleCustomer[];
9
- }
10
- export interface PaddleCustomerResponse {
11
- data?: PaddleCustomer;
12
- }
13
- export declare function fetchPaddleCustomer(customerId: string): Promise<PaddleCustomerResponse>;
14
- export declare function findPaddleCustomersByEmail(email: string): Promise<PaddleCustomerListResponse>;
15
- export declare function findFirstPaddleCustomerByEmail(email: string): Promise<PaddleCustomer | null>;
@@ -1,14 +0,0 @@
1
- import { paddleApi } from "./api";
2
- export async function fetchPaddleCustomer(customerId) {
3
- return paddleApi(`/customers/${customerId}`);
4
- }
5
- export async function findPaddleCustomersByEmail(email) {
6
- const params = new URLSearchParams({
7
- email,
8
- });
9
- return paddleApi(`/customers?${params.toString()}`);
10
- }
11
- export async function findFirstPaddleCustomerByEmail(email) {
12
- const response = await findPaddleCustomersByEmail(email);
13
- return response.data?.[0] ?? null;
14
- }
@@ -1,10 +0,0 @@
1
- export declare enum PaddleEventType {
2
- TransactionCompleted = "transaction.completed",
3
- TransactionPaid = "transaction.paid",
4
- SubscriptionCreated = "subscription.created",
5
- SubscriptionActivated = "subscription.activated",
6
- SubscriptionUpdated = "subscription.updated",
7
- SubscriptionCanceled = "subscription.canceled",
8
- SubscriptionPaused = "subscription.paused",
9
- CustomerCreated = "customer.created"
10
- }
@@ -1,11 +0,0 @@
1
- export var PaddleEventType;
2
- (function (PaddleEventType) {
3
- PaddleEventType["TransactionCompleted"] = "transaction.completed";
4
- PaddleEventType["TransactionPaid"] = "transaction.paid";
5
- PaddleEventType["SubscriptionCreated"] = "subscription.created";
6
- PaddleEventType["SubscriptionActivated"] = "subscription.activated";
7
- PaddleEventType["SubscriptionUpdated"] = "subscription.updated";
8
- PaddleEventType["SubscriptionCanceled"] = "subscription.canceled";
9
- PaddleEventType["SubscriptionPaused"] = "subscription.paused";
10
- PaddleEventType["CustomerCreated"] = "customer.created";
11
- })(PaddleEventType || (PaddleEventType = {}));
@@ -1,4 +0,0 @@
1
- export declare function openCheckout(items: {
2
- priceId: string;
3
- quantity: number;
4
- }[]): Promise<void>;
@@ -1,11 +0,0 @@
1
- "use client";
2
- import { getPaddle } from "./client";
3
- export async function openCheckout(items) {
4
- const paddle = await getPaddle();
5
- if (!paddle) {
6
- throw new Error("Paddle failed to initialize");
7
- }
8
- paddle.Checkout.open({
9
- items,
10
- });
11
- }
@@ -1,8 +0,0 @@
1
- export interface CreatePortalSessionOptions {
2
- customerId: string;
3
- returnUrl?: string;
4
- }
5
- export interface PortalSessionResult {
6
- url: string;
7
- }
8
- export declare function createCustomerPortalSession({ customerId, returnUrl, }: CreatePortalSessionOptions): Promise<PortalSessionResult>;
@@ -1,28 +0,0 @@
1
- export async function createCustomerPortalSession({ customerId, returnUrl, }) {
2
- const apiKey = process.env.PADDLE_API_KEY;
3
- if (!apiKey) {
4
- throw new Error("Missing PADDLE_API_KEY");
5
- }
6
- const response = await fetch("https://api.paddle.com/customer-portal-sessions", {
7
- method: "POST",
8
- headers: {
9
- Authorization: `Bearer ${apiKey}`,
10
- "Content-Type": "application/json",
11
- },
12
- body: JSON.stringify({
13
- customer_id: customerId,
14
- urls: returnUrl
15
- ? { return_url: returnUrl }
16
- : undefined,
17
- }),
18
- });
19
- if (!response.ok) {
20
- throw new Error("Failed to create Paddle customer portal session");
21
- }
22
- const data = (await response.json());
23
- const url = data.data?.urls?.general;
24
- if (!url) {
25
- throw new Error("Paddle portal URL missing from response");
26
- }
27
- return { url };
28
- }
@@ -1,20 +0,0 @@
1
- export interface PaddleSubscription {
2
- id: string;
3
- status: string;
4
- customer_id?: string;
5
- current_billing_period?: {
6
- ends_at?: string;
7
- };
8
- custom_data?: {
9
- userId?: string;
10
- plan?: "free" | "starter" | "pro" | "business";
11
- };
12
- }
13
- export interface PaddleSubscriptionResponse {
14
- data?: PaddleSubscription;
15
- }
16
- export interface PaddleSubscriptionListResponse {
17
- data?: PaddleSubscription[];
18
- }
19
- export declare function fetchPaddleSubscription(subscriptionId: string): Promise<PaddleSubscriptionResponse>;
20
- export declare function fetchPaddleSubscriptionsForCustomer(customerId: string): Promise<PaddleSubscriptionListResponse>;
@@ -1,10 +0,0 @@
1
- import { paddleApi } from "./api";
2
- export async function fetchPaddleSubscription(subscriptionId) {
3
- return paddleApi(`/subscriptions/${subscriptionId}`);
4
- }
5
- export async function fetchPaddleSubscriptionsForCustomer(customerId) {
6
- const params = new URLSearchParams({
7
- customer_id: customerId,
8
- });
9
- return paddleApi(`/subscriptions?${params.toString()}`);
10
- }