@dodopayments/sveltekit 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 CHANGED
@@ -34,10 +34,19 @@ import {
34
34
  const checkoutGetHandler = Checkout({
35
35
  bearerToken: DODO_PAYMENTS_API_KEY,
36
36
  returnUrl: DODO_PAYMENTS_RETURN_URL,
37
- environment: environment,
38
- type: "static", // optional, defaults to 'static'
37
+ environment: DODO_PAYMENTS_ENVIRONMENT,
38
+ type: "static",
39
+ });
40
+
41
+ const checkoutPostHandler = Checkout({
42
+ bearerToken: DODO_PAYMENTS_API_KEY,
43
+ returnUrl: DODO_PAYMENTS_RETURN_URL,
44
+ environment: DODO_PAYMENTS_ENVIRONMENT,
45
+ type: "session", // or "dynamic" for dynamic link
39
46
  });
47
+
40
48
  export const GET = checkoutGetHandler.GET;
49
+ export const POST = checkoutPostHandler.POST;
41
50
  ```
42
51
 
43
52
  ---
@@ -125,7 +134,7 @@ Here's how you should structure your response:
125
134
 
126
135
  If Checkout Route Handler is selected:
127
136
 
128
- Purpose: This handler redirects users to the Dodo Payments checkout page.
137
+ 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.
129
138
  File Creation: Create a new file at app/checkout/route.ts in your SvelteKit project.
130
139
 
131
140
  Code Snippet:
@@ -137,15 +146,15 @@ import { DODO_PAYMENTS_API_KEY, DODO_PAYMENTS_RETURN_URL, DODO_PAYMENTS_ENVIRONM
137
146
  const checkoutGetHandler = Checkout({
138
147
  bearerToken: DODO_PAYMENTS_API_KEY,
139
148
  returnUrl: DODO_PAYMENTS_RETURN_URL,
140
- environment: environment,
141
- type: "static", // optional, defaults to 'static'
149
+ environment: DODO_PAYMENTS_ENVIRONMENT,
150
+ type: "static",
142
151
  });
143
152
 
144
153
  const checkoutPostHandler = Checkout({
145
154
  bearerToken: DODO_PAYMENTS_API_KEY,
146
155
  returnUrl: DODO_PAYMENTS_RETURN_URL,
147
- environment: environment,
148
- type: "dynamic", // optional, defaults to 'static'
156
+ environment: DODO_PAYMENTS_ENVIRONMENT,
157
+ type: "session", // or "dynamic" for dynamic link
149
158
  });
150
159
 
151
160
  export const GET = checkoutGetHandler.GET;
@@ -159,7 +168,7 @@ Configuration & Usage:
159
168
 
160
169
  environment: (Optional) Set to "test_mode" for testing, or omit/set to "live_mode" for production.
161
170
 
162
- 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.
163
172
 
164
173
  Static Checkout (GET) Query Parameters:
165
174
 
@@ -175,13 +184,24 @@ Static Checkout (GET) Query Parameters:
175
184
 
176
185
  Metadata (optional): Any query parameter starting with metadata_ (e.g., ?metadata_userId=abc123)
177
186
 
178
- 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:
179
190
 
180
191
  Docs - One Time Payment Product: https://docs.dodopayments.com/api-reference/payments/post-payments
181
192
 
182
193
  Docs - Subscription Product: https://docs.dodopayments.com/api-reference/subscriptions/post-subscriptions
183
194
 
184
- Error Handling: If productId is missing or other query parameters are invalid, the handler will return a 400 response.
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:
196
+
197
+ Docs - One Time Payment Product: https://docs.dodopayments.com/api-reference/payments/post-payments
198
+
199
+ Docs - Subscription Product: https://docs.dodopayments.com/api-reference/subscriptions/post-subscriptions
200
+
201
+ Required fields for checkout sessions:
202
+ product_cart (array): Array of products with product_id and quantity
203
+
204
+ Error Handling: If productId is missing or other parameters are invalid, the handler will return a 400 response.
185
205
 
186
206
  If Customer Portal Route Handler is selected:
187
207
 
@@ -196,7 +216,7 @@ import { DODO_PAYMENTS_API_KEY, DODO_PAYMENTS_RETURN_URL, DODO_PAYMENTS_ENVIRONM
196
216
 
197
217
  const customerPortalHandler = CustomerPortal({
198
218
  bearerToken: DODO_PAYMENTS_API_KEY,
199
- environment: environment,
219
+ environment: DODO_PAYMENTS_ENVIRONMENT,
200
220
  });
201
221
 
202
222
  export const GET = customerPortalHandler.GET;
@@ -309,7 +329,7 @@ Example .env file:
309
329
  DODO_PAYMENTS_API_KEY=your-api-key
310
330
  DODO_PAYMENTS_WEBHOOK_KEY=your-webhook-secret
311
331
  DODO_PAYMENTS_RETURN_URL=your-return-url
312
- DODO_PAYMENTS_ENVIRONMENT="test" or "live"
332
+ DODO_PAYMENTS_ENVIRONMENT="test_mode" or "live_mode"
313
333
 
314
334
  Usage in your code:
315
335
 
@@ -1 +1 @@
1
- {"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../src/checkout/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAEL,KAAK,qBAAqB,EAG3B,MAAM,6BAA6B,CAAC;AAErC,eAAO,MAAM,QAAQ,GAAI,QAAQ,qBAAqB;;;CAuErD,CAAC"}
1
+ {"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../src/checkout/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAEL,KAAK,qBAAqB,EAI3B,MAAM,6BAA6B,CAAC;AAErC,eAAO,MAAM,QAAQ,GAAI,QAAQ,qBAAqB;;;CAmGrD,CAAC"}