@dodopayments/nextjs 0.1.7 → 0.1.9
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 +44 -17
- package/dist/checkout/checkout.d.ts.map +1 -1
- package/dist/index.cjs +385 -60
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +385 -60
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,10 +27,24 @@ All the examples below assume you're using Next.js App Router.
|
|
|
27
27
|
import { Checkout } from "@dodopayments/nextjs";
|
|
28
28
|
|
|
29
29
|
export const GET = Checkout({
|
|
30
|
-
bearerToken: process.env.DODO_PAYMENTS_API_KEY
|
|
31
|
-
returnUrl: process.env.
|
|
32
|
-
environment:
|
|
33
|
-
type: "static", //
|
|
30
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
|
|
31
|
+
returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
|
|
32
|
+
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
33
|
+
type: "static", // optional, defaults to 'static'
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export const POST = Checkout({
|
|
37
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
|
|
38
|
+
returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
|
|
39
|
+
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
40
|
+
type: "dynamic", // for dynamic checkout
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const POST = Checkout({
|
|
44
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
|
|
45
|
+
returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
|
|
46
|
+
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
47
|
+
type: "session", // for checkout sessions
|
|
34
48
|
});
|
|
35
49
|
```
|
|
36
50
|
|
|
@@ -104,7 +118,7 @@ Here's how you should structure your response:
|
|
|
104
118
|
|
|
105
119
|
If Checkout Route Handler is selected:
|
|
106
120
|
|
|
107
|
-
Purpose: This handler
|
|
121
|
+
Purpose: This handler manages different types of checkout flows. All checkout types (static, dynamic, and sessions) return JSON responses with checkout URLs for programmatic handling.
|
|
108
122
|
File Creation: Create a new file at app/checkout/route.ts in your Next.js project.
|
|
109
123
|
|
|
110
124
|
Code Snippet:
|
|
@@ -114,16 +128,16 @@ import { Checkout } from '@dodopayments/nextjs'
|
|
|
114
128
|
|
|
115
129
|
export const GET = Checkout({
|
|
116
130
|
bearerToken: process.env.DODO_PAYMENTS_API_KEY!,
|
|
117
|
-
returnUrl: process.env.
|
|
118
|
-
environment:
|
|
131
|
+
returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
|
|
132
|
+
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
119
133
|
type: "static",
|
|
120
134
|
});
|
|
121
135
|
|
|
122
136
|
export const POST = Checkout({
|
|
123
137
|
bearerToken: process.env.DODO_PAYMENTS_API_KEY!,
|
|
124
|
-
returnUrl: process.env.
|
|
125
|
-
environment:
|
|
126
|
-
type: "dynamic"
|
|
138
|
+
returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
|
|
139
|
+
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
140
|
+
type: "session", // or "dynamic" for dynamic link
|
|
127
141
|
});
|
|
128
142
|
|
|
129
143
|
Configuration & Usage:
|
|
@@ -134,7 +148,7 @@ Configuration & Usage:
|
|
|
134
148
|
|
|
135
149
|
environment: (Optional) Set to "test_mode" for testing, or omit/set to "live_mode" for production.
|
|
136
150
|
|
|
137
|
-
type: (Optional) Set to "static" for GET/static checkout, "dynamic" for POST/dynamic checkout
|
|
151
|
+
type: (Optional) Set to "static" for GET/static checkout, "dynamic" for POST/dynamic checkout, or "session" for POST/checkout sessions.
|
|
138
152
|
|
|
139
153
|
Static Checkout (GET) Query Parameters:
|
|
140
154
|
|
|
@@ -150,13 +164,24 @@ Static Checkout (GET) Query Parameters:
|
|
|
150
164
|
|
|
151
165
|
Metadata (optional): Any query parameter starting with metadata_ (e.g., ?metadata_userId=abc123)
|
|
152
166
|
|
|
153
|
-
|
|
167
|
+
Returns: {"checkout_url": "https://checkout.dodopayments.com/..."}
|
|
168
|
+
|
|
169
|
+
Dynamic Checkout (POST) - Returns JSON with checkout_url: Parameters are sent as a JSON body. Supports both one-time and recurring payments. Returns: {"checkout_url": "https://checkout.dodopayments.com/..."}. For a complete list of supported POST body fields, refer to:
|
|
170
|
+
|
|
171
|
+
Docs - One Time Payment Product: https://docs.dodopayments.com/api-reference/payments/post-payments
|
|
172
|
+
|
|
173
|
+
Docs - Subscription Product: https://docs.dodopayments.com/api-reference/subscriptions/post-subscriptions
|
|
174
|
+
|
|
175
|
+
Checkout Sessions (POST) - (Recommended) A more customizable checkout experience. Returns JSON with checkout_url: Parameters are sent as a JSON body. Supports both one-time and recurring payments. Returns: {"checkout_url": "https://checkout.dodopayments.com/..."}. For a complete list of supported POST body fields, refer to:
|
|
154
176
|
|
|
155
177
|
Docs - One Time Payment Product: https://docs.dodopayments.com/api-reference/payments/post-payments
|
|
156
178
|
|
|
157
179
|
Docs - Subscription Product: https://docs.dodopayments.com/api-reference/subscriptions/post-subscriptions
|
|
158
180
|
|
|
159
|
-
|
|
181
|
+
Required fields for checkout sessions:
|
|
182
|
+
product_cart (array): Array of products with product_id and quantity
|
|
183
|
+
|
|
184
|
+
Error Handling: If productId is missing or other parameters are invalid, the handler will return a 400 response.
|
|
160
185
|
|
|
161
186
|
If Customer Portal Route Handler is selected:
|
|
162
187
|
|
|
@@ -192,7 +217,7 @@ Code Snippet:
|
|
|
192
217
|
import { Webhooks } from '@dodopayments/nextjs'
|
|
193
218
|
|
|
194
219
|
export const POST = Webhooks({
|
|
195
|
-
webhookKey: process.env.
|
|
220
|
+
webhookKey: process.env.DODO_WEBHOOK_SECRET!,
|
|
196
221
|
onPayload: async (payload) => {
|
|
197
222
|
// handle the payload
|
|
198
223
|
},
|
|
@@ -273,17 +298,19 @@ To ensure the adapter functions correctly, you will need to manually set up the
|
|
|
273
298
|
|
|
274
299
|
RETURN_URL: (Optional) The URL to redirect to after a successful checkout (for Checkout handler).
|
|
275
300
|
|
|
276
|
-
|
|
301
|
+
DODO_WEBHOOK_SECRET: Your Dodo Payments Webhook Secret (required for Webhook handler).
|
|
277
302
|
|
|
278
303
|
Example .env file:
|
|
279
304
|
|
|
280
305
|
DODO_PAYMENTS_API_KEY=your-api-key
|
|
281
|
-
|
|
306
|
+
DODO_PAYMENTS_WEBHOOK_KEY=your-webhook-secret
|
|
307
|
+
DODO_PAYMENTS_ENVIRONMENT="test_mode" or "live_mode"
|
|
308
|
+
DODO_PAYMENTS_RETURN_URL=your-return-url
|
|
282
309
|
|
|
283
310
|
Usage in your code:
|
|
284
311
|
|
|
285
312
|
bearerToken: process.env.DODO_PAYMENTS_API_KEY!
|
|
286
|
-
webhookKey: process.env.
|
|
313
|
+
webhookKey: process.env.DODO_WEBHOOK_SECRET!
|
|
287
314
|
|
|
288
315
|
Important: Never commit sensitive environment variables directly into your version control. Use environment variables for all sensitive information.
|
|
289
316
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../src/checkout/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAEL,qBAAqB,
|
|
1
|
+
{"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../src/checkout/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAEL,qBAAqB,EAItB,MAAM,6BAA6B,CAAC;AAErC,eAAO,MAAM,QAAQ,GAAI,QAAQ,qBAAqB,MA4F5C,KAAK,WAAW,mCAMzB,CAAC"}
|