@dodopayments/nuxt 0.1.0 → 0.1.2

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 CHANGED
@@ -1,75 +1,315 @@
1
- # Nuxt Minimal Starter
1
+ # `@dodopayments/nuxt`
2
2
 
3
- Look at the [Nuxt documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.
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
- ## Setup
5
+ > **AI Agent Integration Guide:** See the AI Agent Prompt section below for detailed instructions and guidance for AI assistants.
6
6
 
7
- Make sure to install dependencies:
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
- # npm
11
- npm install
16
+ npm install @dodopayments/nuxt
17
+ ```
18
+
19
+ ## Quick Start
12
20
 
13
- # pnpm
14
- pnpm install
21
+ ### 1. Register the Module
15
22
 
16
- # yarn
17
- yarn install
23
+ Add `@dodopayments/nuxt` to your `nuxt.config.ts`:
18
24
 
19
- # bun
20
- bun install
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
- ## Development Server
41
+ ### 2. Checkout API Route
24
42
 
25
- Start the development server on `http://localhost:3000`:
43
+ Create a new file at `server/routes/api/checkout.get.ts`:
26
44
 
27
- ```bash
28
- # npm
29
- npm run dev
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
- # yarn
35
- yarn dev
64
+ ### 3. Customer Portal API Route
36
65
 
37
- # bun
38
- bun run dev
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
- ## Production
83
+ - Accepts GET requests with `customer_id` as a query parameter.
84
+ - Returns 400 if `customer_id` is missing.
42
85
 
43
- Build the application for production:
86
+ ### 4. Webhook API Route
44
87
 
45
- ```bash
46
- # npm
47
- npm run build
88
+ Create a new file at `server/routes/api/webhook.post.ts`:
48
89
 
49
- # pnpm
50
- pnpm build
90
+ ```ts
91
+ export default defineEventHandler((event) => {
92
+ const {
93
+ private: { webhookKey }
94
+ } = useRuntimeConfig()
51
95
 
52
- # yarn
53
- yarn build
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
- Locally preview production build:
108
+ - Only POST requests are supported. Signature is verified using `webhookSecret`.
60
109
 
61
- ```bash
62
- # npm
63
- npm run preview
110
+ ## Environment Variable Setup
64
111
 
65
- # pnpm
66
- pnpm preview
112
+ Set the following environment variables in your Nuxt project's deployment environment:
67
113
 
68
- # yarn
69
- yarn preview
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
+
181
+ export default defineEventHandler((event) => {
182
+ const {
183
+ private: { bearerToken, environment, returnUrl },
184
+ } = useRuntimeConfig();
185
+
186
+ const handler = checkoutHandler({
187
+ bearerToken: bearerToken,
188
+ environment: environment,
189
+ returnUrl: returnUrl,
190
+ });
191
+
192
+ return handler(event);
193
+ });
194
+
195
+ Configuration & Usage:
196
+ - bearerToken: Your Dodo Payments API key. Set via the NUXT_PRIVATE_BEARER_TOKEN environment variable.
197
+ - returnUrl: (Optional) The URL to redirect the user to after a successful checkout.
198
+ - environment: (Optional) Set to your environment (e.g., "test_mode" or "live_mode").
199
+
200
+ Static Checkout (GET) Query Parameters:
201
+ - productId (required): Product identifier (e.g., ?productId=pdt_nZuwz45WAs64n3l07zpQR)
202
+ - quantity (optional): Quantity of the product
203
+ - Customer Fields (optional): fullName, firstName, lastName, email, country, addressLine, city, state, zipCode
204
+ - Disable Flags (optional, set to true to disable): disableFullName, disableFirstName, disableLastName, disableEmail, disableCountry, disableAddressLine, disableCity, disableState, disableZipCode
205
+ - Advanced Controls (optional): paymentCurrency, showCurrencySelector, paymentAmount, showDiscounts
206
+ - Metadata (optional): Any query parameter starting with metadata_ (e.g., ?metadata_userId=abc123)
207
+
208
+ 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:
209
+ - Docs - One Time Payment Product: https://docs.dodopayments.com/api-reference/payments/post-payments
210
+ - Docs - Subscription Product: https://docs.dodopayments.com/api-reference/subscriptions/post-subscriptions
211
+
212
+ Error Handling: If productId is missing or other query parameters are invalid, the handler will return a 400 response.
213
+
214
+ If Customer Portal API Route is selected:
215
+
216
+ Purpose: This route allows customers to access their Dodo Payments customer portal.
217
+ File Creation: Create a new file at server/routes/api/customer-portal.get.ts in your Nuxt project.
218
+
219
+ Code Snippet:
220
+
221
+ // server/routes/api/customer-portal.get.ts
222
+
223
+ export default defineEventHandler((event) => {
224
+ const {
225
+ private: { bearerToken, environment },
226
+ } = useRuntimeConfig();
227
+
228
+ const handler = customerPortalHandler({
229
+ bearerToken,
230
+ environment: environment,
231
+ });
232
+
233
+ return handler(event);
234
+ });
235
+
236
+ Query Parameters:
237
+ - customer_id (required): The customer ID for the portal session (e.g., ?customer_id=cus_123)
238
+ - send_email (optional, boolean): If set to true, sends an email to the customer with the portal link.
239
+ - Returns 400 if customer_id is missing.
240
+
241
+ If Webhook API Route is selected:
242
+
243
+ Purpose: This route processes incoming webhook events from Dodo Payments, allowing your application to react to events like successful payments, refunds, or subscription changes.
244
+ File Creation: Create a new file at server/routes/api/webhook.post.ts in your Nuxt project.
245
+
246
+ Code Snippet:
247
+
248
+ // server/routes/api/webhook.post.ts
249
+
250
+ export default defineEventHandler((event) => {
251
+ const {
252
+ private: { webhookKey },
253
+ } = useRuntimeConfig();
254
+
255
+ const handler = Webhooks({
256
+ webhookKey: webhookKey,
257
+ onPayload: async (payload) => {
258
+ // handle the payload
259
+ },
260
+ // ... other event handlers for granular control
261
+ });
262
+
263
+ return handler(event);
264
+ });
265
+
266
+ Handler Details:
267
+ - Method: Only POST requests are supported. Other methods return 405.
268
+ - Signature Verification: The handler verifies the webhook signature using webhookKey and returns 401 if verification fails.
269
+ - Payload Validation: The payload is validated with Zod. Returns 400 for invalid payloads.
270
+
271
+ Error Handling:
272
+ - 401: Invalid signature
273
+ - 400: Invalid payload
274
+ - 500: Internal error during verification
275
+
276
+ Event Routing: Calls the appropriate event handler based on the payload type. Supported event handlers include:
277
+ - onPayload?: (payload: WebhookPayload) => Promise<void>
278
+ - onPaymentSucceeded?: (payload: WebhookPayload) => Promise<void>
279
+ - onPaymentFailed?: (payload: WebhookPayload) => Promise<void>
280
+ - onPaymentProcessing?: (payload: WebhookPayload) => Promise<void>
281
+ - onPaymentCancelled?: (payload: WebhookPayload) => Promise<void>
282
+ - onRefundSucceeded?: (payload: WebhookPayload) => Promise<void>
283
+ - onRefundFailed?: (payload: WebhookPayload) => Promise<void>
284
+ - onDisputeOpened?: (payload: WebhookPayload) => Promise<void>
285
+ - onDisputeExpired?: (payload: WebhookPayload) => Promise<void>
286
+ - onDisputeAccepted?: (payload: WebhookPayload) => Promise<void>
287
+ - onDisputeCancelled?: (payload: WebhookPayload) => Promise<void>
288
+ - onDisputeChallenged?: (payload: WebhookPayload) => Promise<void>
289
+ - onDisputeWon?: (payload: WebhookPayload) => Promise<void>
290
+ - onDisputeLost?: (payload: WebhookPayload) => Promise<void>
291
+ - onSubscriptionActive?: (payload: WebhookPayload) => Promise<void>
292
+ - onSubscriptionOnHold?: (payload: WebhookPayload) => Promise<void>
293
+ - onSubscriptionRenewed?: (payload: WebhookPayload) => Promise<void>
294
+ - onSubscriptionPaused?: (payload: WebhookPayload) => Promise<void>
295
+ - onSubscriptionPlanChanged?: (payload: WebhookPayload) => Promise<void>
296
+ - onSubscriptionCancelled?: (payload: WebhookPayload) => Promise<void>
297
+ - onSubscriptionFailed?: (payload: WebhookPayload) => Promise<void>
298
+ - onSubscriptionExpired?: (payload: WebhookPayload) => Promise<void>
299
+ - onLicenseKeyCreated?: (payload: WebhookPayload) => Promise<void>
300
+
301
+ Environment Variable Setup:
302
+ 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.):
303
+ - NUXT_PRIVATE_BEARER_TOKEN: Your Dodo Payments API Key (required for Checkout and Customer Portal).
304
+ - NUXT_PRIVATE_WEBHOOK_KEY: Your Dodo Payments Webhook Secret (required for Webhook handler).
305
+ - NUXT_PRIVATE_ENVIRONMENT: (Optional) Set to your environment (e.g., "test_mode" or "live_mode").
306
+ - NUXT_PRIVATE_RETURNURL: (Optional) The URL to redirect to after a successful checkout (for Checkout handler).
307
+
308
+ Usage in your code:
309
+ bearerToken: useRuntimeConfig().private.bearerToken
310
+ webhookKey: useRuntimeConfig().private.webhookKey
311
+
312
+ Important: Never commit sensitive environment variables directly into your version control. Use environment variables for all sensitive information.
74
313
 
75
- Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.
314
+ 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.
315
+ ```
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dodopayments/nuxt",
3
3
  "configKey": "dodopayments",
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.1",
7
7
  "unbuild": "3.5.0"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dodopayments/nuxt",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
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",