@dodopayments/hono 0.1.2 → 0.2.0
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 +56 -25
- package/dist/checkout/checkout.d.ts +3 -1
- package/dist/checkout/checkout.d.ts.map +1 -1
- package/dist/customer-portal/customer-portal.d.ts +1 -1
- package/dist/index.cjs +4165 -1465
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +4165 -1465
- package/dist/index.js.map +1 -1
- package/dist/webhooks/webhooks.d.ts.map +1 -1
- package/package.json +2 -6
package/README.md
CHANGED
|
@@ -18,22 +18,43 @@ npm install @dodopayments/hono
|
|
|
18
18
|
|
|
19
19
|
## Quick Start
|
|
20
20
|
|
|
21
|
-
|
|
22
21
|
### 1. Checkout
|
|
23
22
|
|
|
24
23
|
```typescript
|
|
25
|
-
|
|
26
|
-
import {
|
|
24
|
+
// route.ts
|
|
25
|
+
import { Checkout } from "@dodopayments/hono";
|
|
26
|
+
import Hono from "hono";
|
|
27
|
+
|
|
28
|
+
const app = new Hono();
|
|
27
29
|
|
|
28
|
-
const app = new Hono()
|
|
29
30
|
app.get(
|
|
30
31
|
"/api/checkout",
|
|
31
32
|
Checkout({
|
|
32
33
|
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
|
|
33
34
|
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
34
35
|
returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
|
|
35
|
-
type:
|
|
36
|
-
})
|
|
36
|
+
type: "static",
|
|
37
|
+
}),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
app.post(
|
|
41
|
+
"/api/checkout",
|
|
42
|
+
Checkout({
|
|
43
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
|
|
44
|
+
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
45
|
+
returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
|
|
46
|
+
type: "dynamic",
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
app.post(
|
|
51
|
+
"/api/checkout",
|
|
52
|
+
Checkout({
|
|
53
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
|
|
54
|
+
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
55
|
+
returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
|
|
56
|
+
type: "session",
|
|
57
|
+
}),
|
|
37
58
|
);
|
|
38
59
|
```
|
|
39
60
|
|
|
@@ -43,18 +64,16 @@ app.get(
|
|
|
43
64
|
|
|
44
65
|
```typescript
|
|
45
66
|
import { CustomerPortal } from "@dodopayments/hono";
|
|
46
|
-
import { Hono } from
|
|
67
|
+
import { Hono } from "hono";
|
|
47
68
|
|
|
48
|
-
const app = new Hono()
|
|
69
|
+
const app = new Hono();
|
|
49
70
|
app.get(
|
|
50
71
|
"/api/customer-portal",
|
|
51
72
|
CustomerPortal({
|
|
52
73
|
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
|
|
53
|
-
environment: process.env.DODO_PAYMENTS_ENVIRONMENT
|
|
54
|
-
})
|
|
74
|
+
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
75
|
+
}),
|
|
55
76
|
);
|
|
56
|
-
|
|
57
|
-
|
|
58
77
|
```
|
|
59
78
|
|
|
60
79
|
#### Query Parameters
|
|
@@ -69,23 +88,20 @@ Returns 400 if `customer_id` is missing.
|
|
|
69
88
|
### 3. Webhook Route Handler
|
|
70
89
|
|
|
71
90
|
```typescript
|
|
91
|
+
import { Hono } from "hono";
|
|
92
|
+
import { Webhooks } from "@dodopayments/hono";
|
|
72
93
|
|
|
73
|
-
|
|
74
|
-
import { Webhooks } from '@dodopayments/hono'
|
|
75
|
-
|
|
76
|
-
const app = new Hono()
|
|
94
|
+
const app = new Hono();
|
|
77
95
|
app.post(
|
|
78
96
|
"/api/webhooks",
|
|
79
97
|
Webhooks({
|
|
80
98
|
webhookKey: process.env.DODO_PAYMENTS_WEBHOOK_KEY,
|
|
81
99
|
onPayload: async (payload) => {
|
|
82
100
|
// Handle Payload Here
|
|
83
|
-
console.log(payload)
|
|
84
|
-
}
|
|
85
|
-
})
|
|
101
|
+
console.log(payload);
|
|
102
|
+
},
|
|
103
|
+
}),
|
|
86
104
|
);
|
|
87
|
-
|
|
88
|
-
|
|
89
105
|
```
|
|
90
106
|
|
|
91
107
|
---
|
|
@@ -149,7 +165,7 @@ app.post(
|
|
|
149
165
|
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
|
|
150
166
|
environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
|
|
151
167
|
returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
|
|
152
|
-
type: 'dynamic'
|
|
168
|
+
type: 'session' // or 'dynamic' for dynamic link
|
|
153
169
|
})
|
|
154
170
|
);
|
|
155
171
|
|
|
@@ -162,7 +178,7 @@ Config Options:
|
|
|
162
178
|
|
|
163
179
|
environment: "test_mode" or "live_mode"
|
|
164
180
|
|
|
165
|
-
type: "static" (GET) or "dynamic" (POST)
|
|
181
|
+
type: "static" (GET) or "dynamic" (POST) or "session" (POST)
|
|
166
182
|
|
|
167
183
|
GET (static checkout) expects query parameters:
|
|
168
184
|
|
|
@@ -176,6 +192,20 @@ POST (dynamic checkout) expects a JSON body with payment details (one-time or su
|
|
|
176
192
|
|
|
177
193
|
Subscriptions: https://docs.dodopayments.com/api-reference/subscriptions/post-subscriptions
|
|
178
194
|
|
|
195
|
+
POST (checkout sessions) - (Recommended) A more customizable checkout experience:
|
|
196
|
+
|
|
197
|
+
Expects a JSON body with product_cart array and customer details.
|
|
198
|
+
|
|
199
|
+
One-time payments: https://docs.dodopayments.com/api-reference/payments/post-payments
|
|
200
|
+
|
|
201
|
+
Subscriptions: https://docs.dodopayments.com/api-reference/subscriptions/post-subscriptions
|
|
202
|
+
|
|
203
|
+
Required fields for checkout sessions:
|
|
204
|
+
product_cart (array): Array of products with product_id and quantity
|
|
205
|
+
|
|
206
|
+
Returns: {"checkout_url": "https://checkout.dodopayments.com/session/..."}
|
|
207
|
+
|
|
208
|
+
|
|
179
209
|
If Customer Portal Route Handler is selected:
|
|
180
210
|
|
|
181
211
|
Purpose: This route allows customers to manage their subscriptions via the Dodo Payments portal.
|
|
@@ -264,11 +294,12 @@ Make sure to define these environment variables in your project:
|
|
|
264
294
|
DODO_PAYMENTS_API_KEY=your-api-key
|
|
265
295
|
DODO_PAYMENTS_RETURN_URL=https://yourapp.com/success
|
|
266
296
|
DODO_PAYMENTS_WEBHOOK_KEY=your-webhook-secret
|
|
267
|
-
DODO_PAYMENTS_ENVIRONMENT="
|
|
297
|
+
DODO_PAYMENTS_ENVIRONMENT="test_mode" or "live_mode""
|
|
268
298
|
|
|
269
299
|
Use these inside your code as:
|
|
270
300
|
|
|
271
301
|
process.env.DODO_PAYMENTS_API_KEY
|
|
272
302
|
process.env.DODO_PAYMENTS_WEBHOOK_KEY
|
|
273
303
|
|
|
274
|
-
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.).
|
|
304
|
+
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.).
|
|
305
|
+
```
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Context } from "hono";
|
|
2
2
|
import { CheckoutHandlerConfig } from "@dodopayments/core/checkout";
|
|
3
|
-
export declare const Checkout: (config: CheckoutHandlerConfig) => (c: Context) => Promise<(Response & import("hono").TypedResponse<any, 400, "text">) | (Response & import("hono").TypedResponse<
|
|
3
|
+
export declare const Checkout: (config: CheckoutHandlerConfig) => (c: Context) => Promise<(Response & import("hono").TypedResponse<any, 400, "text">) | (Response & import("hono").TypedResponse<{
|
|
4
|
+
checkout_url: string;
|
|
5
|
+
}, import("hono/utils/http-status").ContentfulStatusCode, "json">)>;
|
|
4
6
|
//# sourceMappingURL=checkout.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../src/checkout/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAEL,qBAAqB,
|
|
1
|
+
{"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../src/checkout/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAEL,qBAAqB,EAItB,MAAM,6BAA6B,CAAC;AAErC,eAAO,MAAM,QAAQ,GAAI,QAAQ,qBAAqB,MAkF5C,GAAG,OAAO;;mEAMnB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context } from "hono";
|
|
2
2
|
import { ClientOptions } from "dodopayments";
|
|
3
3
|
export type CustomerPortalConfig = Pick<ClientOptions, "environment" | "bearerToken">;
|
|
4
|
-
export declare const CustomerPortal: ({ bearerToken, environment, }: CustomerPortalConfig) => (c: Context) => Promise<(Response & import("hono").TypedResponse<
|
|
4
|
+
export declare const CustomerPortal: ({ bearerToken, environment, }: CustomerPortalConfig) => (c: Context) => Promise<(Response & import("hono").TypedResponse<"Missing customerId in query parameters", 400, "text">) | (Response & import("hono").TypedResponse<undefined, 302, "redirect">) | (Response & import("hono").TypedResponse<`Failed to create customer portal session: ${any}`, 500, "text">)>;
|
|
5
5
|
//# sourceMappingURL=customer-portal.d.ts.map
|