@dodopayments/nuxt 0.1.0 → 0.1.1
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/README.md +288 -45
- package/dist/module.json +1 -1
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -1,75 +1,318 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@dodopayments/nuxt`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A Nuxt module that provides composables and server routes for integrating Dodo Payments Checkout, Customer Portal, and Webhook functionalities into your Nuxt application.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> **AI Agent Integration Guide:** See the AI Agent Prompt section below for detailed instructions and guidance for AI assistants.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Documentation
|
|
8
|
+
|
|
9
|
+
Detailed documentation can be found at [Dodo Payments Nuxt adaptor](https://docs.dodopayments.com/developer-resources/nuxt-adaptor)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
You can install this package via npm or any other package manager of your choice:
|
|
8
14
|
|
|
9
15
|
```bash
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
npm install @dodopayments/nuxt
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
12
20
|
|
|
13
|
-
|
|
14
|
-
pnpm install
|
|
21
|
+
### 1. Register the Module
|
|
15
22
|
|
|
16
|
-
|
|
17
|
-
yarn install
|
|
23
|
+
Add `@dodopayments/nuxt` to your `nuxt.config.ts`:
|
|
18
24
|
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
```ts
|
|
26
|
+
export default defineNuxtConfig({
|
|
27
|
+
modules: ["@dodopayments/nuxt"],
|
|
28
|
+
devtools: { enabled: true },
|
|
29
|
+
compatibilityDate: "2025-02-25",
|
|
30
|
+
runtimeConfig: {
|
|
31
|
+
private: {
|
|
32
|
+
bearerToken: process.env.NUXT_PRIVATE_BEARER_TOKEN,
|
|
33
|
+
webhookKey: process.env.NUXT_PRIVATE_BEARER_TOKEN,
|
|
34
|
+
environment: process.env.NUXT_PRIVATE_ENVIRONMENT,
|
|
35
|
+
returnUrl: process.env.NUXT_PRIVATE_RETURNURL
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
});
|
|
21
39
|
```
|
|
22
40
|
|
|
23
|
-
|
|
41
|
+
### 2. Checkout API Route
|
|
24
42
|
|
|
25
|
-
|
|
43
|
+
Create a new file at `server/routes/api/checkout.get.ts`:
|
|
26
44
|
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
|
|
45
|
+
```ts
|
|
46
|
+
export default defineEventHandler((event) => {
|
|
47
|
+
const {
|
|
48
|
+
private: { bearerToken, environment, returnUrl },
|
|
49
|
+
} = useRuntimeConfig();
|
|
50
|
+
|
|
51
|
+
const handler = checkoutHandler({
|
|
52
|
+
bearerToken: bearerToken,
|
|
53
|
+
environment: env,
|
|
54
|
+
returnUrl: returnUrl
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return handler(event);
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
- Accepts GET requests with `productId` as a query parameter.
|
|
30
62
|
|
|
31
|
-
# pnpm
|
|
32
|
-
pnpm dev
|
|
33
63
|
|
|
34
|
-
|
|
35
|
-
yarn dev
|
|
64
|
+
### 3. Customer Portal API Route
|
|
36
65
|
|
|
37
|
-
|
|
38
|
-
|
|
66
|
+
Create a new file at `server/routes/api/customer-portal.get.ts`:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
export default defineEventHandler((event) => {
|
|
70
|
+
const {
|
|
71
|
+
private: { bearerToken, environment }
|
|
72
|
+
} = useRuntimeConfig()
|
|
73
|
+
|
|
74
|
+
const handler = customerPortalHandler({
|
|
75
|
+
bearerToken,
|
|
76
|
+
environment: environment,
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
return handler(event)
|
|
80
|
+
})
|
|
39
81
|
```
|
|
40
82
|
|
|
41
|
-
|
|
83
|
+
- Accepts GET requests with `customer_id` as a query parameter.
|
|
84
|
+
- Returns 400 if `customer_id` is missing.
|
|
42
85
|
|
|
43
|
-
|
|
86
|
+
### 4. Webhook API Route
|
|
44
87
|
|
|
45
|
-
|
|
46
|
-
# npm
|
|
47
|
-
npm run build
|
|
88
|
+
Create a new file at `server/routes/api/webhook.post.ts`:
|
|
48
89
|
|
|
49
|
-
|
|
50
|
-
|
|
90
|
+
```ts
|
|
91
|
+
export default defineEventHandler((event) => {
|
|
92
|
+
const {
|
|
93
|
+
private: { webhookKey }
|
|
94
|
+
} = useRuntimeConfig()
|
|
51
95
|
|
|
52
|
-
|
|
53
|
-
|
|
96
|
+
const handler = Webhooks({
|
|
97
|
+
webhookKey: webhookKey,
|
|
98
|
+
onPayload: async (payload: any) => {
|
|
99
|
+
// Handle here
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
return handler(event)
|
|
104
|
+
})
|
|
54
105
|
|
|
55
|
-
# bun
|
|
56
|
-
bun run build
|
|
57
106
|
```
|
|
58
107
|
|
|
59
|
-
|
|
108
|
+
- Only POST requests are supported. Signature is verified using `webhookSecret`.
|
|
60
109
|
|
|
61
|
-
|
|
62
|
-
# npm
|
|
63
|
-
npm run preview
|
|
110
|
+
## Environment Variable Setup
|
|
64
111
|
|
|
65
|
-
|
|
66
|
-
pnpm preview
|
|
112
|
+
Set the following environment variables in your Nuxt project's deployment environment:
|
|
67
113
|
|
|
68
|
-
|
|
69
|
-
|
|
114
|
+
```
|
|
115
|
+
NUXT_PRIVATE_BEARER_TOKEN="""
|
|
116
|
+
NUXT_PRIVATE_ENVIRONMENT=""
|
|
117
|
+
NUXT_PRIVATE_WEBHOOK_KEY=""
|
|
118
|
+
NUXT_PRIVATE_RETURN_URL=""
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
- `NUXT_PRIVATE_BEARER_TOKEN`: Your Dodo Payments API Key (required for Checkout and Customer Portal).
|
|
122
|
+
- `NUXT_PRIVATE_WEBHOOK_KEY`: Your Dodo Payments Webhook Secret (required for Webhook handler).
|
|
123
|
+
- `NUXT_PRIVATE_ENVIRONMENT`
|
|
124
|
+
- `NUXT_PRIVATE_RETURN_URL`: (Optional) The URL to redirect to after a successful checkout.
|
|
125
|
+
|
|
126
|
+
**Important:** Never commit sensitive environment variables to version control.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
## Prompt for LLM
|
|
70
132
|
|
|
71
|
-
# bun
|
|
72
|
-
bun run preview
|
|
73
133
|
```
|
|
134
|
+
You are an expert Nuxt developer assistant. Your task is to guide a user through integrating the @dodopayments/nuxt module into their existing Nuxt project.
|
|
135
|
+
|
|
136
|
+
The @dodopayments/nuxt module provides API route handlers for Dodo Payments' Checkout, Customer Portal, and Webhook functionalities, designed for Nuxt 3 server routes.
|
|
137
|
+
|
|
138
|
+
First, install the necessary package:
|
|
139
|
+
|
|
140
|
+
npm install @dodopayments/nuxt
|
|
141
|
+
|
|
142
|
+
Second, add the configuration to nuxt.config.ts
|
|
143
|
+
|
|
144
|
+
export default defineNuxtConfig({
|
|
145
|
+
modules: ["@dodopayments/nuxt"],
|
|
146
|
+
devtools: { enabled: true },
|
|
147
|
+
compatibilityDate: "2025-02-25",
|
|
148
|
+
runtimeConfig: {
|
|
149
|
+
private: {
|
|
150
|
+
bearerToken: process.env.NUXT_PRIVATE_BEARER_TOKEN,
|
|
151
|
+
webhookKey: process.env.NUXT_PRIVATE_BEARER_TOKEN,
|
|
152
|
+
environment: process.env.NUXT_PRIVATE_ENVIRONMENT,
|
|
153
|
+
returnUrl: process.env.NUXT_PRIVATE_RETURNURL
|
|
154
|
+
},
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
Here's how you should structure your response:
|
|
160
|
+
|
|
161
|
+
Ask the user which functionalities they want to integrate.
|
|
162
|
+
|
|
163
|
+
"Which parts of the @dodopayments/nuxt module would you like to integrate into your project? You can choose one or more of the following:
|
|
164
|
+
|
|
165
|
+
Checkout API Route (for handling product checkouts)
|
|
166
|
+
Customer Portal API Route (for managing customer subscriptions/details)
|
|
167
|
+
Webhook API Route (for receiving Dodo Payments webhook events)
|
|
168
|
+
All (integrate all three)"
|
|
169
|
+
|
|
170
|
+
Based on the user's selection, provide detailed integration steps for each chosen functionality.
|
|
171
|
+
|
|
172
|
+
If Checkout API Route is selected:
|
|
173
|
+
|
|
174
|
+
Purpose: This route redirects users to the Dodo Payments checkout page.
|
|
175
|
+
File Creation: Create a new file at server/routes/api/checkout.get.ts in your Nuxt project.
|
|
176
|
+
|
|
177
|
+
Code Snippet:
|
|
178
|
+
|
|
179
|
+
// server/routes/api/checkout.get.ts
|
|
180
|
+
import { checkoutHandler } from '@dodopayments/nuxt/server';
|
|
181
|
+
|
|
182
|
+
export default defineEventHandler((event) => {
|
|
183
|
+
const {
|
|
184
|
+
private: { bearerToken, environment, returnUrl },
|
|
185
|
+
} = useRuntimeConfig();
|
|
186
|
+
|
|
187
|
+
const handler = checkoutHandler({
|
|
188
|
+
bearerToken: bearerToken,
|
|
189
|
+
environment: environment,
|
|
190
|
+
returnUrl: returnUrl,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
return handler(event);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
Configuration & Usage:
|
|
197
|
+
- bearerToken: Your Dodo Payments API key. Set via the NUXT_PRIVATE_BEARER_TOKEN environment variable.
|
|
198
|
+
- returnUrl: (Optional) The URL to redirect the user to after a successful checkout.
|
|
199
|
+
- environment: (Optional) Set to your environment (e.g., "test_mode" or "live_mode").
|
|
200
|
+
|
|
201
|
+
Static Checkout (GET) Query Parameters:
|
|
202
|
+
- productId (required): Product identifier (e.g., ?productId=pdt_nZuwz45WAs64n3l07zpQR)
|
|
203
|
+
- quantity (optional): Quantity of the product
|
|
204
|
+
- Customer Fields (optional): fullName, firstName, lastName, email, country, addressLine, city, state, zipCode
|
|
205
|
+
- Disable Flags (optional, set to true to disable): disableFullName, disableFirstName, disableLastName, disableEmail, disableCountry, disableAddressLine, disableCity, disableState, disableZipCode
|
|
206
|
+
- Advanced Controls (optional): paymentCurrency, showCurrencySelector, paymentAmount, showDiscounts
|
|
207
|
+
- Metadata (optional): Any query parameter starting with metadata_ (e.g., ?metadata_userId=abc123)
|
|
208
|
+
|
|
209
|
+
Dynamic Checkout (POST): Parameters are sent as a JSON body. Supports both one-time and recurring payments. For a complete list of supported POST body fields, refer to:
|
|
210
|
+
- Docs - One Time Payment Product: https://docs.dodopayments.com/api-reference/payments/post-payments
|
|
211
|
+
- Docs - Subscription Product: https://docs.dodopayments.com/api-reference/subscriptions/post-subscriptions
|
|
212
|
+
|
|
213
|
+
Error Handling: If productId is missing or other query parameters are invalid, the handler will return a 400 response.
|
|
214
|
+
|
|
215
|
+
If Customer Portal API Route is selected:
|
|
216
|
+
|
|
217
|
+
Purpose: This route allows customers to access their Dodo Payments customer portal.
|
|
218
|
+
File Creation: Create a new file at server/routes/api/customer-portal.get.ts in your Nuxt project.
|
|
219
|
+
|
|
220
|
+
Code Snippet:
|
|
221
|
+
|
|
222
|
+
// server/routes/api/customer-portal.get.ts
|
|
223
|
+
import { customerPortalHandler } from '@dodopayments/nuxt/server';
|
|
224
|
+
|
|
225
|
+
export default defineEventHandler((event) => {
|
|
226
|
+
const {
|
|
227
|
+
private: { bearerToken, environment },
|
|
228
|
+
} = useRuntimeConfig();
|
|
229
|
+
|
|
230
|
+
const handler = customerPortalHandler({
|
|
231
|
+
bearerToken,
|
|
232
|
+
environment: environment,
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
return handler(event);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
Query Parameters:
|
|
239
|
+
- customer_id (required): The customer ID for the portal session (e.g., ?customer_id=cus_123)
|
|
240
|
+
- send_email (optional, boolean): If set to true, sends an email to the customer with the portal link.
|
|
241
|
+
- Returns 400 if customer_id is missing.
|
|
242
|
+
|
|
243
|
+
If Webhook API Route is selected:
|
|
244
|
+
|
|
245
|
+
Purpose: This route processes incoming webhook events from Dodo Payments, allowing your application to react to events like successful payments, refunds, or subscription changes.
|
|
246
|
+
File Creation: Create a new file at server/routes/api/webhook.post.ts in your Nuxt project.
|
|
247
|
+
|
|
248
|
+
Code Snippet:
|
|
249
|
+
|
|
250
|
+
// server/routes/api/webhook.post.ts
|
|
251
|
+
import { Webhooks } from '@dodopayments/nuxt/server';
|
|
252
|
+
|
|
253
|
+
export default defineEventHandler((event) => {
|
|
254
|
+
const {
|
|
255
|
+
private: { webhookKey },
|
|
256
|
+
} = useRuntimeConfig();
|
|
257
|
+
|
|
258
|
+
const handler = Webhooks({
|
|
259
|
+
webhookKey: webhookKey,
|
|
260
|
+
onPayload: async (payload) => {
|
|
261
|
+
// handle the payload
|
|
262
|
+
},
|
|
263
|
+
// ... other event handlers for granular control
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
return handler(event);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
Handler Details:
|
|
270
|
+
- Method: Only POST requests are supported. Other methods return 405.
|
|
271
|
+
- Signature Verification: The handler verifies the webhook signature using webhookKey and returns 401 if verification fails.
|
|
272
|
+
- Payload Validation: The payload is validated with Zod. Returns 400 for invalid payloads.
|
|
273
|
+
|
|
274
|
+
Error Handling:
|
|
275
|
+
- 401: Invalid signature
|
|
276
|
+
- 400: Invalid payload
|
|
277
|
+
- 500: Internal error during verification
|
|
278
|
+
|
|
279
|
+
Event Routing: Calls the appropriate event handler based on the payload type. Supported event handlers include:
|
|
280
|
+
- onPayload?: (payload: WebhookPayload) => Promise<void>
|
|
281
|
+
- onPaymentSucceeded?: (payload: WebhookPayload) => Promise<void>
|
|
282
|
+
- onPaymentFailed?: (payload: WebhookPayload) => Promise<void>
|
|
283
|
+
- onPaymentProcessing?: (payload: WebhookPayload) => Promise<void>
|
|
284
|
+
- onPaymentCancelled?: (payload: WebhookPayload) => Promise<void>
|
|
285
|
+
- onRefundSucceeded?: (payload: WebhookPayload) => Promise<void>
|
|
286
|
+
- onRefundFailed?: (payload: WebhookPayload) => Promise<void>
|
|
287
|
+
- onDisputeOpened?: (payload: WebhookPayload) => Promise<void>
|
|
288
|
+
- onDisputeExpired?: (payload: WebhookPayload) => Promise<void>
|
|
289
|
+
- onDisputeAccepted?: (payload: WebhookPayload) => Promise<void>
|
|
290
|
+
- onDisputeCancelled?: (payload: WebhookPayload) => Promise<void>
|
|
291
|
+
- onDisputeChallenged?: (payload: WebhookPayload) => Promise<void>
|
|
292
|
+
- onDisputeWon?: (payload: WebhookPayload) => Promise<void>
|
|
293
|
+
- onDisputeLost?: (payload: WebhookPayload) => Promise<void>
|
|
294
|
+
- onSubscriptionActive?: (payload: WebhookPayload) => Promise<void>
|
|
295
|
+
- onSubscriptionOnHold?: (payload: WebhookPayload) => Promise<void>
|
|
296
|
+
- onSubscriptionRenewed?: (payload: WebhookPayload) => Promise<void>
|
|
297
|
+
- onSubscriptionPaused?: (payload: WebhookPayload) => Promise<void>
|
|
298
|
+
- onSubscriptionPlanChanged?: (payload: WebhookPayload) => Promise<void>
|
|
299
|
+
- onSubscriptionCancelled?: (payload: WebhookPayload) => Promise<void>
|
|
300
|
+
- onSubscriptionFailed?: (payload: WebhookPayload) => Promise<void>
|
|
301
|
+
- onSubscriptionExpired?: (payload: WebhookPayload) => Promise<void>
|
|
302
|
+
- onLicenseKeyCreated?: (payload: WebhookPayload) => Promise<void>
|
|
303
|
+
|
|
304
|
+
Environment Variable Setup:
|
|
305
|
+
To ensure the module functions correctly, set up the following environment variables in your Nuxt project's deployment environment (e.g., Vercel, Netlify, AWS, etc.):
|
|
306
|
+
- NUXT_PRIVATE_BEARER_TOKEN: Your Dodo Payments API Key (required for Checkout and Customer Portal).
|
|
307
|
+
- NUXT_PRIVATE_WEBHOOK_KEY: Your Dodo Payments Webhook Secret (required for Webhook handler).
|
|
308
|
+
- NUXT_PRIVATE_ENVIRONMENT: (Optional) Set to your environment (e.g., "test_mode" or "live_mode").
|
|
309
|
+
- NUXT_PRIVATE_RETURNURL: (Optional) The URL to redirect to after a successful checkout (for Checkout handler).
|
|
310
|
+
|
|
311
|
+
Usage in your code:
|
|
312
|
+
bearerToken: useRuntimeConfig().private.bearerToken
|
|
313
|
+
webhookKey: useRuntimeConfig().private.webhookKey
|
|
314
|
+
|
|
315
|
+
Important: Never commit sensitive environment variables directly into your version control. Use environment variables for all sensitive information.
|
|
74
316
|
|
|
75
|
-
|
|
317
|
+
If the user needs assistance setting up environment variables for their specific deployment environment, ask them what platform they are using (e.g., Vercel, Netlify, AWS, etc.), and provide guidance.
|
|
318
|
+
```
|
package/dist/module.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dodopayments/nuxt",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Dodo Payments Nuxt integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
},
|
|
40
40
|
"keywords": [
|
|
41
41
|
"payments",
|
|
42
|
-
"dodo",
|
|
43
42
|
"nuxt",
|
|
44
43
|
"webhooks",
|
|
45
44
|
"checkout",
|