@dodopayments/fastify 0.1.1 → 0.1.3
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 +75 -34
- package/dist/checkout/checkout.d.ts.map +1 -1
- package/dist/customer-portal/customer-portal.d.ts.map +1 -1
- package/dist/index.cjs +400 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +400 -67
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,21 +18,38 @@ npm install @dodopayments/fastify
|
|
|
18
18
|
|
|
19
19
|
## Quick Start
|
|
20
20
|
|
|
21
|
-
|
|
22
21
|
### 1. Checkout
|
|
23
22
|
|
|
24
23
|
```typescript
|
|
25
|
-
|
|
24
|
+
// route.ts
|
|
25
|
+
import { Checkout } from "@dodopayments/fastify";
|
|
26
|
+
import Fastify from "fastify";
|
|
26
27
|
|
|
27
|
-
const fastify = Fastify({})
|
|
28
|
+
const fastify = Fastify({});
|
|
28
29
|
const checkoutGet = Checkout({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
|
|
31
|
+
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
32
|
+
returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
|
|
33
|
+
type: "static",
|
|
33
34
|
});
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
const checkoutPost = Checkout({
|
|
37
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
|
|
38
|
+
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
39
|
+
returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
|
|
40
|
+
type: "dynamic",
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const checkoutSession = Checkout({
|
|
44
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
|
|
45
|
+
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
46
|
+
returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
|
|
47
|
+
type: "session",
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
fastify.get("/api/checkout", checkoutGet.getHandler);
|
|
51
|
+
fastify.post("/api/checkout", checkoutPost.postHandler);
|
|
52
|
+
fastify.post("/api/checkout-session", checkoutSession.postHandler);
|
|
36
53
|
```
|
|
37
54
|
|
|
38
55
|
---
|
|
@@ -42,13 +59,12 @@ fastify.get('/api/checkout', checkoutGet.getHandler);
|
|
|
42
59
|
```typescript
|
|
43
60
|
import { CustomerPortal } from "@dodopayments/fastify";
|
|
44
61
|
|
|
45
|
-
const fastify = Fastify({})
|
|
62
|
+
const fastify = Fastify({});
|
|
46
63
|
const customerPortalHandler = CustomerPortal({
|
|
47
|
-
|
|
48
|
-
|
|
64
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
|
|
65
|
+
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
49
66
|
});
|
|
50
|
-
fastify.get(
|
|
51
|
-
|
|
67
|
+
fastify.get("/api/customer-portal", customerPortalHandler);
|
|
52
68
|
```
|
|
53
69
|
|
|
54
70
|
#### Query Parameters
|
|
@@ -63,22 +79,27 @@ Returns 400 if `customer_id` is missing.
|
|
|
63
79
|
### 3. Webhook Route Handler
|
|
64
80
|
|
|
65
81
|
```typescript
|
|
66
|
-
|
|
67
|
-
import
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
import Fastify from "fastify";
|
|
83
|
+
import { Webhooks } from "@dodopayments/fastify";
|
|
84
|
+
|
|
85
|
+
const fastify = Fastify({});
|
|
86
|
+
fastify.addContentTypeParser(
|
|
87
|
+
"application/json",
|
|
88
|
+
{ parseAs: "string" },
|
|
89
|
+
function (req, body, done) {
|
|
90
|
+
done(null, body);
|
|
91
|
+
},
|
|
92
|
+
);
|
|
93
|
+
fastify.post(
|
|
94
|
+
"/api/webhooks",
|
|
95
|
+
Webhooks({
|
|
96
|
+
webhookKey: process.env.DODO_PAYMENTS_WEBHOOK_KEY,
|
|
97
|
+
onPayload: async (payload) => {
|
|
98
|
+
// Handle Payload Here
|
|
99
|
+
console.log(payload);
|
|
100
|
+
},
|
|
101
|
+
}),
|
|
102
|
+
);
|
|
82
103
|
```
|
|
83
104
|
|
|
84
105
|
---
|
|
@@ -139,8 +160,16 @@ const checkoutPost = Checkout({
|
|
|
139
160
|
type: 'dynamic'
|
|
140
161
|
});
|
|
141
162
|
|
|
163
|
+
const checkoutSession = Checkout({
|
|
164
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
|
|
165
|
+
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
166
|
+
returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
|
|
167
|
+
type: 'session'
|
|
168
|
+
});
|
|
169
|
+
|
|
142
170
|
fastify.get('/api/checkout', checkoutGet.getHandler);
|
|
143
|
-
fastify.post('/api/checkout',
|
|
171
|
+
fastify.post('/api/checkout', checkoutPost.postHandler);
|
|
172
|
+
fastify.post('/api/checkout-session', checkoutSession.postHandler);
|
|
144
173
|
|
|
145
174
|
|
|
146
175
|
Config Options:
|
|
@@ -151,7 +180,7 @@ Config Options:
|
|
|
151
180
|
|
|
152
181
|
environment: "test_mode" or "live_mode"
|
|
153
182
|
|
|
154
|
-
type: "static" (GET) or "
|
|
183
|
+
type: "static" (GET), "dynamic" (POST), or "session" (POST)
|
|
155
184
|
|
|
156
185
|
GET (static checkout) expects query parameters:
|
|
157
186
|
|
|
@@ -159,12 +188,23 @@ GET (static checkout) expects query parameters:
|
|
|
159
188
|
|
|
160
189
|
quantity, customer fields (fullName, email, etc.), and metadata (metadata_*) are optional.
|
|
161
190
|
|
|
162
|
-
|
|
191
|
+
Returns: {"checkout_url": "https://checkout.dodopayments.com/..."}
|
|
192
|
+
|
|
193
|
+
POST (dynamic checkout) expects a JSON body with payment details (one-time or subscription). Returns: {"checkout_url": "https://checkout.dodopayments.com/..."}. Reference the docs for the full POST schema:
|
|
163
194
|
|
|
164
195
|
One-time payments: https://docs.dodopayments.com/api-reference/payments/post-payments
|
|
165
196
|
|
|
166
197
|
Subscriptions: https://docs.dodopayments.com/api-reference/subscriptions/post-subscriptions
|
|
167
198
|
|
|
199
|
+
POST (checkout sessions) - (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/session/..."}. For a complete list of supported POST body fields, refer to:
|
|
200
|
+
|
|
201
|
+
One-time payments: https://docs.dodopayments.com/api-reference/payments/post-payments
|
|
202
|
+
|
|
203
|
+
Subscriptions: https://docs.dodopayments.com/api-reference/subscriptions/post-subscriptions
|
|
204
|
+
|
|
205
|
+
Required fields for checkout sessions:
|
|
206
|
+
product_cart (array): Array of products with product_id and quantity
|
|
207
|
+
|
|
168
208
|
If Customer Portal Route Handler is selected:
|
|
169
209
|
|
|
170
210
|
Purpose: This route allows customers to manage their subscriptions via the Dodo Payments portal.
|
|
@@ -252,11 +292,12 @@ Make sure to define these environment variables in your project:
|
|
|
252
292
|
DODO_PAYMENTS_API_KEY=your-api-key
|
|
253
293
|
DODO_PAYMENTS_RETURN_URL=https://yourapp.com/success
|
|
254
294
|
DODO_PAYMENTS_WEBHOOK_KEY=your-webhook-secret
|
|
255
|
-
DODO_PAYMENTS_ENVIRONMENT="
|
|
295
|
+
DODO_PAYMENTS_ENVIRONMENT="test_mode" or "live_mode""
|
|
256
296
|
|
|
257
297
|
Use these inside your code as:
|
|
258
298
|
|
|
259
299
|
process.env.DODO_PAYMENTS_API_KEY
|
|
260
300
|
process.env.DODO_PAYMENTS_WEBHOOK_KEY
|
|
261
301
|
|
|
262
|
-
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.).
|
|
302
|
+
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.).
|
|
303
|
+
```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../src/checkout/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,EAEL,qBAAqB,
|
|
1
|
+
{"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../src/checkout/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,EAEL,qBAAqB,EAItB,MAAM,6BAA6B,CAAC;AAErC,eAAO,MAAM,QAAQ,GAAI,QAAQ,qBAAqB;0BAEjB,cAAc,SAAS,YAAY;2BAgClC,cAAc,SAAS,YAAY;CAwDxE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customer-portal.d.ts","sourceRoot":"","sources":["../../src/customer-portal/customer-portal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvD,OAAqB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE3D,MAAM,MAAM,oBAAoB,GAAG,IAAI,CACrC,aAAa,EACb,aAAa,GAAG,aAAa,CAC9B,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,+BAG5B,oBAAoB,eACc,cAAc,SAAS,YAAY,
|
|
1
|
+
{"version":3,"file":"customer-portal.d.ts","sourceRoot":"","sources":["../../src/customer-portal/customer-portal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvD,OAAqB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE3D,MAAM,MAAM,oBAAoB,GAAG,IAAI,CACrC,aAAa,EACb,aAAa,GAAG,aAAa,CAC9B,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,+BAG5B,oBAAoB,eACc,cAAc,SAAS,YAAY,mBAuCvE,CAAC"}
|