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.
- package/bin/paddle-checkout-accelerator.js +247 -0
- package/dist/index.cjs +1150 -0
- package/dist/index.d.cts +290 -0
- package/dist/index.d.ts +290 -0
- package/dist/index.js +1079 -0
- package/package.json +14 -7
- package/recipes/nextjs/app/billing.ts +1 -1
- package/dist/package/index.d.ts +0 -28
- package/dist/package/index.js +0 -28
- package/dist/src/components/paddle/BillingHistory.d.ts +0 -1
- package/dist/src/components/paddle/BillingHistory.js +0 -17
- package/dist/src/components/paddle/CustomerPortal.d.ts +0 -1
- package/dist/src/components/paddle/CustomerPortal.js +0 -5
- package/dist/src/components/paddle/CustomerPortalButton.d.ts +0 -1
- package/dist/src/components/paddle/CustomerPortalButton.js +0 -31
- package/dist/src/components/paddle/InlineCheckout.d.ts +0 -5
- package/dist/src/components/paddle/InlineCheckout.js +0 -13
- package/dist/src/components/paddle/PricingTable.d.ts +0 -1
- package/dist/src/components/paddle/PricingTable.js +0 -27
- package/dist/src/components/paddle/SubscriptionCard.d.ts +0 -6
- package/dist/src/components/paddle/SubscriptionCard.js +0 -5
- package/dist/src/components/paddle/TrialBanner.d.ts +0 -5
- package/dist/src/components/paddle/TrialBanner.js +0 -5
- package/dist/src/components/paddle/UpgradeModal.d.ts +0 -11
- package/dist/src/components/paddle/UpgradeModal.js +0 -35
- package/dist/src/components/paddle/UsageMeter.d.ts +0 -6
- package/dist/src/components/paddle/UsageMeter.js +0 -8
- package/dist/src/components/paddle/gates/SubscriptionGate.d.ts +0 -7
- package/dist/src/components/paddle/gates/SubscriptionGate.js +0 -8
- package/dist/src/lib/billing/adapters/index.d.ts +0 -3
- package/dist/src/lib/billing/adapters/index.js +0 -3
- package/dist/src/lib/billing/adapters/memory.d.ts +0 -2
- package/dist/src/lib/billing/adapters/memory.js +0 -41
- package/dist/src/lib/billing/adapters/prisma/index.d.ts +0 -28
- package/dist/src/lib/billing/adapters/prisma/index.js +0 -80
- package/dist/src/lib/billing/adapters/types.d.ts +0 -13
- package/dist/src/lib/billing/adapters/types.js +0 -1
- package/dist/src/lib/billing/configure.d.ts +0 -6
- package/dist/src/lib/billing/configure.js +0 -13
- package/dist/src/lib/billing/customer-repair.d.ts +0 -4
- package/dist/src/lib/billing/customer-repair.js +0 -19
- package/dist/src/lib/billing/demo-seed.d.ts +0 -1
- package/dist/src/lib/billing/demo-seed.js +0 -13
- package/dist/src/lib/billing/entitlements.d.ts +0 -3
- package/dist/src/lib/billing/entitlements.js +0 -16
- package/dist/src/lib/billing/events.d.ts +0 -12
- package/dist/src/lib/billing/events.js +0 -20
- package/dist/src/lib/billing/plans.d.ts +0 -9
- package/dist/src/lib/billing/plans.js +0 -41
- package/dist/src/lib/billing/protection.d.ts +0 -6
- package/dist/src/lib/billing/protection.js +0 -16
- package/dist/src/lib/billing/refresh.d.ts +0 -1
- package/dist/src/lib/billing/refresh.js +0 -32
- package/dist/src/lib/billing/subscriptions.d.ts +0 -16
- package/dist/src/lib/billing/subscriptions.js +0 -36
- package/dist/src/lib/billing/teams.d.ts +0 -42
- package/dist/src/lib/billing/teams.js +0 -104
- package/dist/src/lib/billing/usage.d.ts +0 -17
- package/dist/src/lib/billing/usage.js +0 -40
- package/dist/src/lib/billing/webhook-sync.d.ts +0 -26
- package/dist/src/lib/billing/webhook-sync.js +0 -39
- package/dist/src/lib/paddle/api.d.ts +0 -1
- package/dist/src/lib/paddle/api.js +0 -21
- package/dist/src/lib/paddle/client.d.ts +0 -1
- package/dist/src/lib/paddle/client.js +0 -13
- package/dist/src/lib/paddle/customers.d.ts +0 -15
- package/dist/src/lib/paddle/customers.js +0 -14
- package/dist/src/lib/paddle/events.d.ts +0 -10
- package/dist/src/lib/paddle/events.js +0 -11
- package/dist/src/lib/paddle/hooks.d.ts +0 -4
- package/dist/src/lib/paddle/hooks.js +0 -11
- package/dist/src/lib/paddle/portal.d.ts +0 -8
- package/dist/src/lib/paddle/portal.js +0 -28
- package/dist/src/lib/paddle/subscriptions.d.ts +0 -20
- package/dist/src/lib/paddle/subscriptions.js +0 -10
- package/dist/src/lib/paddle/types.d.ts +0 -8
- package/dist/src/lib/paddle/types.js +0 -1
- package/dist/src/lib/paddle/webhook.d.ts +0 -1
- package/dist/src/lib/paddle/webhook.js +0 -8
- package/dist/src/lib/utils.d.ts +0 -2
- package/dist/src/lib/utils.js +0 -5
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
const cwd = process.cwd();
|
|
7
|
+
|
|
8
|
+
function writeFileSafe(filePath, content) {
|
|
9
|
+
const absolutePath = path.join(cwd, filePath);
|
|
10
|
+
const dir = path.dirname(absolutePath);
|
|
11
|
+
|
|
12
|
+
fs.mkdirSync(dir, {
|
|
13
|
+
recursive: true,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
if (fs.existsSync(absolutePath)) {
|
|
17
|
+
console.log(`Skipped ${filePath} because it already exists`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
fs.writeFileSync(absolutePath, content);
|
|
22
|
+
console.log(`Created ${filePath}`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function appendEnvSafe(content) {
|
|
26
|
+
const envPath = path.join(cwd, ".env.local");
|
|
27
|
+
|
|
28
|
+
if (!fs.existsSync(envPath)) {
|
|
29
|
+
fs.writeFileSync(envPath, content);
|
|
30
|
+
console.log("Created .env.local");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const current = fs.readFileSync(envPath, "utf8");
|
|
35
|
+
|
|
36
|
+
const nextLines = content
|
|
37
|
+
.split("\n")
|
|
38
|
+
.filter(Boolean)
|
|
39
|
+
.filter((line) => {
|
|
40
|
+
const key = line.split("=")[0];
|
|
41
|
+
return !current.includes(`${key}=`);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (nextLines.length === 0) {
|
|
45
|
+
console.log("Skipped .env.local because Paddle keys already exist");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fs.appendFileSync(
|
|
50
|
+
envPath,
|
|
51
|
+
`\n${nextLines.join("\n")}\n`
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
console.log("Updated .env.local");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const command = process.argv[2];
|
|
58
|
+
|
|
59
|
+
if (!command || command === "--help" || command === "-h") {
|
|
60
|
+
console.log(`
|
|
61
|
+
Paddle Checkout Accelerator
|
|
62
|
+
|
|
63
|
+
Usage:
|
|
64
|
+
npx paddle-checkout-accelerator init
|
|
65
|
+
|
|
66
|
+
This creates:
|
|
67
|
+
- src/lib/billing.ts
|
|
68
|
+
- src/app/api/paddle/webhook/route.ts
|
|
69
|
+
- src/app/api/paddle/portal-session/route.ts
|
|
70
|
+
- src/app/api/paddle/refresh-subscription/route.ts
|
|
71
|
+
- src/app/api/paddle/repair-by-email/route.ts
|
|
72
|
+
- .env.local placeholders
|
|
73
|
+
`);
|
|
74
|
+
process.exit(0);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (command !== "init") {
|
|
78
|
+
console.error(`Unknown command: ${command}`);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
writeFileSafe(
|
|
83
|
+
"src/lib/billing.ts",
|
|
84
|
+
`import {
|
|
85
|
+
configureBilling,
|
|
86
|
+
memoryBillingAdapter,
|
|
87
|
+
} from "paddle-checkout-accelerator";
|
|
88
|
+
|
|
89
|
+
export const billing =
|
|
90
|
+
configureBilling({
|
|
91
|
+
adapter: memoryBillingAdapter,
|
|
92
|
+
});
|
|
93
|
+
`
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
writeFileSafe(
|
|
97
|
+
"src/app/api/paddle/webhook/route.ts",
|
|
98
|
+
`import { NextRequest, NextResponse } from "next/server";
|
|
99
|
+
import {
|
|
100
|
+
syncPaddleEvent,
|
|
101
|
+
verifyPaddleWebhook,
|
|
102
|
+
} from "paddle-checkout-accelerator";
|
|
103
|
+
|
|
104
|
+
export async function POST(request: NextRequest) {
|
|
105
|
+
const rawBody = await request.text();
|
|
106
|
+
|
|
107
|
+
const signature =
|
|
108
|
+
request.headers.get("paddle-signature");
|
|
109
|
+
|
|
110
|
+
if (!signature) {
|
|
111
|
+
return NextResponse.json(
|
|
112
|
+
{ error: "Missing Paddle signature" },
|
|
113
|
+
{ status: 400 }
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
const event =
|
|
119
|
+
await verifyPaddleWebhook(
|
|
120
|
+
rawBody,
|
|
121
|
+
signature
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
await syncPaddleEvent(event);
|
|
125
|
+
|
|
126
|
+
return NextResponse.json({
|
|
127
|
+
success: true,
|
|
128
|
+
});
|
|
129
|
+
} catch (error) {
|
|
130
|
+
return NextResponse.json(
|
|
131
|
+
{
|
|
132
|
+
error:
|
|
133
|
+
error instanceof Error
|
|
134
|
+
? error.message
|
|
135
|
+
: "Webhook verification failed",
|
|
136
|
+
},
|
|
137
|
+
{ status: 401 }
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
`
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
writeFileSafe(
|
|
145
|
+
"src/app/api/paddle/portal-session/route.ts",
|
|
146
|
+
`import { NextRequest, NextResponse } from "next/server";
|
|
147
|
+
import {
|
|
148
|
+
createCustomerPortalSession,
|
|
149
|
+
} from "paddle-checkout-accelerator";
|
|
150
|
+
|
|
151
|
+
export async function POST(request: NextRequest) {
|
|
152
|
+
const body =
|
|
153
|
+
(await request.json()) as {
|
|
154
|
+
customerId?: string;
|
|
155
|
+
returnUrl?: string;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
if (!body.customerId) {
|
|
159
|
+
return NextResponse.json(
|
|
160
|
+
{ error: "Missing customerId" },
|
|
161
|
+
{ status: 400 }
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const session =
|
|
166
|
+
await createCustomerPortalSession({
|
|
167
|
+
customerId: body.customerId,
|
|
168
|
+
returnUrl: body.returnUrl,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
return NextResponse.json(session);
|
|
172
|
+
}
|
|
173
|
+
`
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
writeFileSafe(
|
|
177
|
+
"src/app/api/paddle/refresh-subscription/route.ts",
|
|
178
|
+
`import { NextRequest, NextResponse } from "next/server";
|
|
179
|
+
import {
|
|
180
|
+
refreshSubscriptionFromPaddle,
|
|
181
|
+
} from "paddle-checkout-accelerator";
|
|
182
|
+
|
|
183
|
+
export async function POST(request: NextRequest) {
|
|
184
|
+
const body =
|
|
185
|
+
(await request.json()) as {
|
|
186
|
+
subscriptionId?: string;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
if (!body.subscriptionId) {
|
|
190
|
+
return NextResponse.json(
|
|
191
|
+
{ error: "Missing subscriptionId" },
|
|
192
|
+
{ status: 400 }
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const subscription =
|
|
197
|
+
await refreshSubscriptionFromPaddle(
|
|
198
|
+
body.subscriptionId
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
return NextResponse.json(subscription);
|
|
202
|
+
}
|
|
203
|
+
`
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
writeFileSafe(
|
|
207
|
+
"src/app/api/paddle/repair-by-email/route.ts",
|
|
208
|
+
`import { NextRequest, NextResponse } from "next/server";
|
|
209
|
+
import {
|
|
210
|
+
repairSubscriptionByEmail,
|
|
211
|
+
} from "paddle-checkout-accelerator";
|
|
212
|
+
|
|
213
|
+
export async function POST(request: NextRequest) {
|
|
214
|
+
const body =
|
|
215
|
+
(await request.json()) as {
|
|
216
|
+
email?: string;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
if (!body.email) {
|
|
220
|
+
return NextResponse.json(
|
|
221
|
+
{ error: "Missing email" },
|
|
222
|
+
{ status: 400 }
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const result =
|
|
227
|
+
await repairSubscriptionByEmail(
|
|
228
|
+
body.email
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
return NextResponse.json(result);
|
|
232
|
+
}
|
|
233
|
+
`
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
appendEnvSafe(`NEXT_PUBLIC_PADDLE_CLIENT_TOKEN=
|
|
237
|
+
PADDLE_API_KEY=
|
|
238
|
+
PADDLE_WEBHOOK_SECRET=
|
|
239
|
+
`);
|
|
240
|
+
|
|
241
|
+
console.log("");
|
|
242
|
+
console.log("Paddle Checkout Accelerator installed.");
|
|
243
|
+
console.log("");
|
|
244
|
+
console.log("Next:");
|
|
245
|
+
console.log("1. Add your Paddle keys to .env.local");
|
|
246
|
+
console.log("2. Replace memoryBillingAdapter with Prisma adapter for production");
|
|
247
|
+
console.log("3. Configure Paddle webhook URL: /api/paddle/webhook");
|