@dodopayments/tanstack 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 CHANGED
@@ -27,18 +27,24 @@ All the examples below assume you're using Tanstack App Router.
27
27
  import { Checkout } from "@dodopayments/tanstack";
28
28
  import { createServerFileRoute } from "@tanstack/react-start/server";
29
29
 
30
- export const ServerRoute = createServerFileRoute("/api/checkout")
31
- .methods({
32
- GET: async ({ request }) => {
33
- return Checkout({
34
- bearerToken: process.env.DODO_PAYMENTS_API_KEY,
35
- returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
36
- environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
37
- type: "static", // optional, defaults to 'static'
38
- })(request)
39
- }
40
- })
41
-
30
+ export const ServerRoute = createServerFileRoute("/api/checkout").methods({
31
+ GET: async ({ request }) => {
32
+ return Checkout({
33
+ bearerToken: process.env.DODO_PAYMENTS_API_KEY,
34
+ returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
35
+ environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
36
+ type: "static", // optional, defaults to 'static'
37
+ })(request);
38
+ },
39
+ POST: async ({ request }) => {
40
+ return Checkout({
41
+ bearerToken: process.env.DODO_PAYMENTS_API_KEY,
42
+ returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
43
+ environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
44
+ type: "session", // or "dynamic" for dynamic link
45
+ })(request);
46
+ },
47
+ });
42
48
  ```
43
49
 
44
50
  ---
@@ -51,16 +57,16 @@ export const ServerRoute = createServerFileRoute("/api/checkout")
51
57
  import { CustomerPortal } from "@dodopayments/tanstack";
52
58
  import { createServerFileRoute } from "@tanstack/react-start/server";
53
59
 
54
- export const ServerRoute = createServerFileRoute('/api/customer-portal')
55
- .methods({
56
- GET: async ({ request }) => {
57
- return CustomerPortal({
58
- bearerToken: process.env.DODO_PAYMENTS_API_KEY,
59
- environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
60
- })(request)
61
- }
62
- })
63
-
60
+ export const ServerRoute = createServerFileRoute(
61
+ "/api/customer-portal",
62
+ ).methods({
63
+ GET: async ({ request }) => {
64
+ return CustomerPortal({
65
+ bearerToken: process.env.DODO_PAYMENTS_API_KEY,
66
+ environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
67
+ })(request);
68
+ },
69
+ });
64
70
  ```
65
71
 
66
72
  #### Query Parameters
@@ -79,19 +85,17 @@ Returns 400 if `customer_id` is missing.
79
85
  import { Webhooks } from "@dodopayments/tanstack";
80
86
  import { createServerFileRoute } from "@tanstack/react-start/server";
81
87
 
82
- export const ServerRoute = createServerFileRoute('/api/webhook')
83
- .methods({
84
- POST: async ({ request }) => {
85
- return Webhooks({
86
- webhookKey: process.env.DODO_PAYMENTS_WEBHOOK_KEY,
87
- onPayload: async (payload) => {
88
- // Handle Payload here
89
- console.log(payload)
90
- }
91
- })(request)
92
- }
93
- })
94
-
88
+ export const ServerRoute = createServerFileRoute("/api/webhook").methods({
89
+ POST: async ({ request }) => {
90
+ return Webhooks({
91
+ webhookKey: process.env.DODO_PAYMENTS_WEBHOOK_KEY,
92
+ onPayload: async (payload) => {
93
+ // Handle Payload here
94
+ console.log(payload);
95
+ },
96
+ })(request);
97
+ },
98
+ });
95
99
  ```
96
100
 
97
101
  ---
@@ -150,7 +154,7 @@ export const ServerRoute = createServerFileRoute("/api/checkout")
150
154
  bearerToken: process.env.DODO_PAYMENTS_API_KEY,
151
155
  returnUrl: process.env.DODO_PAYMENTS_RETURN_URL,
152
156
  environment: process.env.DODO_PAYMENTS_ENVIRONMENT,
153
- type: "dynamic", // for dynamic checkout
157
+ type: "session", // or "dynamic" for dynamic link
154
158
  })(request)
155
159
  }
156
160
  })
@@ -164,7 +168,7 @@ Configuration & Usage:
164
168
 
165
169
  environment: (Optional) Set to "test_mode" for testing, or omit/set to "live_mode" for production.
166
170
 
167
- type: (Optional) Set to "static" for GET/static checkout, "dynamic" for POST/dynamic checkout. Defaults to "static".
171
+ type: (Optional) Set to "static" for GET/static checkout, "dynamic" for POST/dynamic checkout, or "session" for POST/checkout sessions.
168
172
 
169
173
  Static Checkout (GET) Query Parameters:
170
174
 
@@ -180,12 +184,23 @@ Static Checkout (GET) Query Parameters:
180
184
 
181
185
  Metadata (optional): Any query parameter starting with metadata_ (e.g., ?metadata_userId=abc123)
182
186
 
183
- 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:
187
+ Returns: {"checkout_url": "https://checkout.dodopayments.com/..."}
188
+
189
+ 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:
190
+
191
+ Docs - One Time Payment Product: https://docs.dodopayments.com/api-reference/payments/post-payments
192
+
193
+ Docs - Subscription Product: https://docs.dodopayments.com/api-reference/subscriptions/post-subscriptions
194
+
195
+ 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/session/..."}. For a complete list of supported POST body fields, refer to:
184
196
 
185
197
  Docs - One Time Payment Product: https://docs.dodopayments.com/api-reference/payments/post-payments
186
198
 
187
199
  Docs - Subscription Product: https://docs.dodopayments.com/api-reference/subscriptions/post-subscriptions
188
200
 
201
+ Required fields for checkout sessions:
202
+ product_cart (array): Array of products with product_id and quantity
203
+
189
204
  Error Handling: If productId is missing or other query parameters are invalid, the handler will return a 400 response.
190
205
 
191
206
  If Customer Portal Route Handler is selected:
@@ -225,7 +240,6 @@ File Creation: Create a new file at app/api/webhook/dodo-payments/route.ts in yo
225
240
  Code Snippet:
226
241
 
227
242
  // src/routes/api/webhook.ts
228
- // routes/api/checkout.ts
229
243
  import { Webhooks } from "@dodopayments/tanstack";
230
244
  import { createServerFileRoute } from "@tanstack/react-start/server";
231
245
 
@@ -322,7 +336,7 @@ Example .env file:
322
336
  DODO_PAYMENTS_API_KEY=your-api-key
323
337
  DODO_PAYMENTS_WEBHOOK_KEY=your-webhook-secret
324
338
  DODO_PAYMENTS_RETURN_URL=your-return-url
325
- DODO_PAYMENTS_ENVIRONMENT="test" or "live"
339
+ DODO_PAYMENTS_ENVIRONMENT="test_mode" or "live_mode"
326
340
 
327
341
  Usage in your code:
328
342
 
@@ -1 +1 @@
1
- {"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../src/checkout/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,qBAAqB,EAGtB,MAAM,6BAA6B,CAAC;AAErC;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,qBAAqB,IAC7B,SAAS,OAAO,8CAwDxC"}
1
+ {"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../src/checkout/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,qBAAqB,EAItB,MAAM,6BAA6B,CAAC;AAErC;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,qBAAqB,IAC7B,SAAS,OAAO,8CAyFxC"}