@dodopayments/express 0.1.2 → 0.1.4
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 +92 -46
- package/dist/checkout/checkout.d.ts +1 -1
- package/dist/index.cjs +382 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +382 -57
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,25 +18,40 @@ npm install @dodopayments/express
|
|
|
18
18
|
|
|
19
19
|
## Quick Start
|
|
20
20
|
|
|
21
|
-
|
|
22
21
|
### 1. Checkout
|
|
23
22
|
|
|
24
23
|
```typescript
|
|
25
|
-
import { checkoutHandler } from
|
|
26
|
-
|
|
27
|
-
app.get(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
import { checkoutHandler } from "@dodopayments/express";
|
|
25
|
+
|
|
26
|
+
app.get(
|
|
27
|
+
"/api/checkout",
|
|
28
|
+
checkoutHandler({
|
|
29
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
|
|
30
|
+
returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
|
|
31
|
+
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
32
|
+
type: "static",
|
|
33
|
+
}),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
app.post(
|
|
37
|
+
"/api/checkout",
|
|
38
|
+
checkoutHandler({
|
|
39
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
|
|
40
|
+
returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
|
|
41
|
+
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
42
|
+
type: "dynamic",
|
|
43
|
+
}),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
app.post(
|
|
47
|
+
"/api/checkout",
|
|
48
|
+
checkoutHandler({
|
|
49
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
|
|
50
|
+
returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
|
|
51
|
+
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
52
|
+
type: "session",
|
|
53
|
+
}),
|
|
54
|
+
);
|
|
40
55
|
```
|
|
41
56
|
|
|
42
57
|
---
|
|
@@ -46,11 +61,13 @@ app.post('/api/checkout', checkoutHandler({
|
|
|
46
61
|
```typescript
|
|
47
62
|
import { CustomerPortal } from "@dodopayments/express";
|
|
48
63
|
|
|
49
|
-
app.get(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
64
|
+
app.get(
|
|
65
|
+
"/api/customer-portal",
|
|
66
|
+
CustomerPortal({
|
|
67
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY!,
|
|
68
|
+
environment: "test_mode",
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
54
71
|
```
|
|
55
72
|
|
|
56
73
|
#### Query Parameters
|
|
@@ -68,14 +85,16 @@ Returns 400 if `customer_id` is missing.
|
|
|
68
85
|
// app/api/webhook/dodo-payments/route.ts
|
|
69
86
|
import { Webhooks } from "@dodopayments/express";
|
|
70
87
|
|
|
71
|
-
app.post(
|
|
88
|
+
app.post(
|
|
89
|
+
"/api/webhook",
|
|
72
90
|
Webhooks({
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
})
|
|
91
|
+
webhookKey: process.env.DODO_PAYMENTS_WEBHOOK_SECRET!,
|
|
92
|
+
onPayload: async (payload) => {
|
|
93
|
+
// handle the payload
|
|
94
|
+
},
|
|
95
|
+
// ... other event handlers for granular control
|
|
96
|
+
}),
|
|
97
|
+
);
|
|
79
98
|
```
|
|
80
99
|
|
|
81
100
|
---
|
|
@@ -112,28 +131,36 @@ Here's how you should structure your response:
|
|
|
112
131
|
|
|
113
132
|
**If Checkout Route Handler is selected:**
|
|
114
133
|
|
|
115
|
-
**Purpose**: This handler
|
|
134
|
+
**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.
|
|
116
135
|
|
|
117
136
|
**Integration**:
|
|
118
|
-
Create
|
|
137
|
+
Create routes in your Express app for static (GET), dynamic (POST), and checkout sessions (POST).
|
|
119
138
|
|
|
120
139
|
|
|
121
140
|
import { checkoutHandler } from '@dodopayments/express';
|
|
122
141
|
|
|
123
142
|
app.get('/api/checkout', checkoutHandler({
|
|
124
|
-
bearerToken: process.env.DODO_PAYMENTS_API_KEY
|
|
125
|
-
returnUrl: process.env.
|
|
126
|
-
environment:
|
|
143
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
|
|
144
|
+
returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
|
|
145
|
+
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
127
146
|
type: "static"
|
|
128
147
|
}));
|
|
129
148
|
|
|
130
149
|
app.post('/api/checkout', checkoutHandler({
|
|
131
|
-
bearerToken: process.env.DODO_PAYMENTS_API_KEY
|
|
132
|
-
returnUrl: process.env.
|
|
133
|
-
environment:
|
|
150
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
|
|
151
|
+
returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
|
|
152
|
+
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
134
153
|
type: "dynamic"
|
|
135
154
|
}));
|
|
136
155
|
|
|
156
|
+
// For checkout sessions
|
|
157
|
+
app.post('/api/checkout', checkoutHandler({
|
|
158
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
|
|
159
|
+
returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
|
|
160
|
+
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
161
|
+
type: "session"
|
|
162
|
+
}));
|
|
163
|
+
|
|
137
164
|
Config Options:
|
|
138
165
|
|
|
139
166
|
bearerToken: Your Dodo Payments API key (recommended to be stored in DODO_PAYMENTS_API_KEY env variable).
|
|
@@ -142,7 +169,7 @@ Config Options:
|
|
|
142
169
|
|
|
143
170
|
environment: "test_mode" or "live_mode"
|
|
144
171
|
|
|
145
|
-
type: "static" (GET) or "
|
|
172
|
+
type: "static" (GET), "dynamic" (POST), or "session" (POST)
|
|
146
173
|
|
|
147
174
|
GET (static checkout) expects query parameters:
|
|
148
175
|
|
|
@@ -150,12 +177,29 @@ GET (static checkout) expects query parameters:
|
|
|
150
177
|
|
|
151
178
|
quantity, customer fields (fullName, email, etc.), and metadata (metadata_*) are optional.
|
|
152
179
|
|
|
180
|
+
Returns: {"checkout_url": "https://checkout.dodopayments.com/..."}
|
|
181
|
+
|
|
153
182
|
POST (dynamic checkout) expects a JSON body with payment details (one-time or subscription). Reference the docs for the full POST schema:
|
|
154
183
|
|
|
155
184
|
One-time payments: https://docs.dodopayments.com/api-reference/payments/post-payments
|
|
156
185
|
|
|
157
186
|
Subscriptions: https://docs.dodopayments.com/api-reference/subscriptions/post-subscriptions
|
|
158
187
|
|
|
188
|
+
Returns: {"checkout_url": "https://checkout.dodopayments.com/..."}
|
|
189
|
+
|
|
190
|
+
POST (checkout sessions) - (Recommended) A more customizable checkout experience:
|
|
191
|
+
|
|
192
|
+
Expects a JSON body with product_cart array and customer details.
|
|
193
|
+
|
|
194
|
+
One-time payments: https://docs.dodopayments.com/api-reference/payments/post-payments
|
|
195
|
+
|
|
196
|
+
Subscriptions: https://docs.dodopayments.com/api-reference/subscriptions/post-subscriptions
|
|
197
|
+
|
|
198
|
+
Required fields for checkout sessions:
|
|
199
|
+
product_cart (array): Array of products with product_id and quantity
|
|
200
|
+
|
|
201
|
+
Returns: {"checkout_url": "https://checkout.dodopayments.com/session/..."}
|
|
202
|
+
|
|
159
203
|
If Customer Portal Route Handler is selected:
|
|
160
204
|
|
|
161
205
|
Purpose: This route allows customers to manage their subscriptions via the Dodo Payments portal.
|
|
@@ -165,8 +209,8 @@ Integration:
|
|
|
165
209
|
import { CustomerPortal } from "@dodopayments/express";
|
|
166
210
|
|
|
167
211
|
app.get('/api/customer-portal', CustomerPortal({
|
|
168
|
-
bearerToken: process.env.DODO_PAYMENTS_API_KEY
|
|
169
|
-
environment:
|
|
212
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
|
|
213
|
+
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
170
214
|
}));
|
|
171
215
|
|
|
172
216
|
Query Parameters:
|
|
@@ -186,7 +230,7 @@ Integration:
|
|
|
186
230
|
import { Webhooks } from "@dodopayments/express";
|
|
187
231
|
|
|
188
232
|
app.post('/api/webhook', Webhooks({
|
|
189
|
-
webhookKey: process.env.
|
|
233
|
+
webhookKey: process.env.DODO_PAYMENTS_WEBHOOK_KEY,
|
|
190
234
|
onPayload: async (payload) => {
|
|
191
235
|
// Handle generic payload
|
|
192
236
|
},
|
|
@@ -223,7 +267,7 @@ You may pass in any of the following handlers:
|
|
|
223
267
|
|
|
224
268
|
onDisputeOpened, onDisputeExpired, onDisputeAccepted, onDisputeCancelled, onDisputeChallenged, onDisputeWon, onDisputeLost
|
|
225
269
|
|
|
226
|
-
onSubscriptionActive, onSubscriptionOnHold, onSubscriptionRenewed,
|
|
270
|
+
onSubscriptionActive, onSubscriptionOnHold, onSubscriptionRenewed, onSubscriptionPlanChanged, onSubscriptionCancelled, onSubscriptionFailed, onSubscriptionExpired
|
|
227
271
|
|
|
228
272
|
onLicenseKeyCreated
|
|
229
273
|
|
|
@@ -232,12 +276,14 @@ Environment Variable Setup:
|
|
|
232
276
|
Make sure to define these environment variables in your project:
|
|
233
277
|
|
|
234
278
|
DODO_PAYMENTS_API_KEY=your-api-key
|
|
235
|
-
|
|
236
|
-
|
|
279
|
+
DODO_PAYMENTS_WEBHOOK_KEY=your-webhook-secret
|
|
280
|
+
DODO_PAYMENTS_ENVIRONMENT="test_mode" or "live_mode"
|
|
281
|
+
DODO_PAYMENTS_RETURN_URL=your-return-url
|
|
237
282
|
|
|
238
283
|
Use these inside your code as:
|
|
239
284
|
|
|
240
|
-
process.env.DODO_PAYMENTS_API_KEY
|
|
241
|
-
process.env.DODO_PAYMENTS_WEBHOOK_SECRET
|
|
285
|
+
process.env.DODO_PAYMENTS_API_KEY
|
|
286
|
+
process.env.DODO_PAYMENTS_WEBHOOK_SECRET
|
|
242
287
|
|
|
243
|
-
Security Note: Do NOT commit secrets to version control. Use .env files locally and secrets managers in deployment environments (e.g., AWS, Vercel, Heroku, etc.).
|
|
288
|
+
Security Note: Do NOT commit secrets to version control. Use .env files locally and secrets managers in deployment environments (e.g., AWS, Vercel, Heroku, etc.).
|
|
289
|
+
```
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Request, Response } from "express";
|
|
2
2
|
import { CheckoutHandlerConfig } from "@dodopayments/core/checkout";
|
|
3
|
-
export declare function checkoutHandler(config: CheckoutHandlerConfig): (req: Request, res: Response) => Response<any, Record<string, any>> | Promise<
|
|
3
|
+
export declare function checkoutHandler(config: CheckoutHandlerConfig): (req: Request, res: Response) => Response<any, Record<string, any>> | Promise<Response<any, Record<string, any>>>;
|