@dodopayments/fastify 0.1.1
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 +262 -0
- package/dist/checkout/checkout.d.ts +7 -0
- package/dist/checkout/checkout.d.ts.map +1 -0
- package/dist/customer-portal/customer-portal.d.ts +5 -0
- package/dist/customer-portal/customer-portal.d.ts.map +1 -0
- package/dist/index.cjs +3619 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3615 -0
- package/dist/index.js.map +1 -0
- package/dist/webhooks/webhooks.d.ts +4 -0
- package/dist/webhooks/webhooks.d.ts.map +1 -0
- package/llm-prompt.txt +160 -0
- package/package.json +56 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type WebhookHandlerConfig } from "@dodopayments/core/webhook";
|
|
2
|
+
import { FastifyRequest, FastifyReply } from "fastify";
|
|
3
|
+
export declare const Webhooks: ({ webhookKey, ...eventHandlers }: WebhookHandlerConfig) => (req: FastifyRequest, reply: FastifyReply) => Promise<never>;
|
|
4
|
+
//# sourceMappingURL=webhooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../../src/webhooks/webhooks.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGvD,eAAO,MAAM,QAAQ,GAAI,kCAGtB,oBAAoB,MAGP,KAAK,cAAc,EAAE,OAAO,YAAY,mBAmDvD,CAAC"}
|
package/llm-prompt.txt
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
You are an expert Next.js developer assistant. Your task is to guide a user through integrating the `@dodopayments/nextjs` adapter into their existing Next.js project.
|
|
2
|
+
|
|
3
|
+
The `@dodopayments/nextjs` adapter provides route handlers for Dodo Payments' Checkout, Customer Portal, and Webhook functionalities, designed for the Next.js App Router.
|
|
4
|
+
|
|
5
|
+
First, install the necessary packages. Use the package manager appropriate for your project (npm, yarn, or bun) based on the presence of lock files (e.g., `package-lock.json` for npm, `yarn.lock` for yarn, `bun.lockb` for bun):
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @dodopayments/nextjs
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Here's how you should structure your response:
|
|
12
|
+
|
|
13
|
+
1. **Ask the user which functionalities they want to integrate.**
|
|
14
|
+
|
|
15
|
+
"Which parts of the `@dodopayments/nextjs` adapter would you like to integrate into your project? You can choose one or more of the following:
|
|
16
|
+
* `Checkout Route Handler` (for handling product checkouts)
|
|
17
|
+
* `Customer Portal Route Handler` (for managing customer subscriptions/details)
|
|
18
|
+
* `Webhook Route Handler` (for receiving Dodo Payments webhook events)
|
|
19
|
+
* `All` (integrate all three)"
|
|
20
|
+
|
|
21
|
+
2. **Based on the user's selection, provide detailed integration steps for each chosen functionality.**
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
**If `Checkout Route Handler` is selected:**
|
|
25
|
+
|
|
26
|
+
**Purpose:** This handler redirects users to the Dodo Payments checkout page.
|
|
27
|
+
**File Creation:** Create a new file at `app/checkout/route.ts` in your Next.js project.
|
|
28
|
+
**Code Snippet:**
|
|
29
|
+
```typescript
|
|
30
|
+
// app/checkout/route.ts
|
|
31
|
+
import { Checkout } from '@dodopayments/nextjs'
|
|
32
|
+
|
|
33
|
+
export const GET = Checkout({
|
|
34
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY!,
|
|
35
|
+
returnUrl: process.env.RETURN_URL!,
|
|
36
|
+
environment: "test_mode",
|
|
37
|
+
type: "static", // explicitly specify type (optional, defaults to 'static')
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export const POST = Checkout({
|
|
41
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY!,
|
|
42
|
+
returnUrl: process.env.RETURN_URL!,
|
|
43
|
+
environment: "test_mode",
|
|
44
|
+
type: "dynamic", // explicitly specify type for dynamic checkout
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
**Configuration & Usage:**
|
|
48
|
+
* `bearerToken`: Your Dodo Payments API key. It's recommended to set this via the `DODO_PAYMENTS_API_KEY` environment variable.
|
|
49
|
+
* `returnUrl`: (Optional) The URL to redirect the user to after a successful checkout.
|
|
50
|
+
* `environment`: (Optional) Set to `"test_mode"` for testing, or omit/set to `"live_mode"` for production.
|
|
51
|
+
* `type`: (Optional) Set to `"static"` for GET/static checkout, `"dynamic"` for POST/dynamic checkout. Defaults to `"static"`.
|
|
52
|
+
* **Static Checkout (GET) Query Parameters:**
|
|
53
|
+
* `productId` (required): Product identifier (e.g., `?productId=pdt_nZuwz45WAs64n3l07zpQR`)
|
|
54
|
+
* `quantity` (optional): Quantity of the product
|
|
55
|
+
* **Customer Fields (optional):** `fullName`, `firstName`, `lastName`, `email`, `country`, `addressLine`, `city`, `state`, `zipCode`
|
|
56
|
+
* **Disable Flags (optional, set to `true` to disable):** `disableFullName`, `disableFirstName`, `disableLastName`, `disableEmail`, `disableCountry`, `disableAddressLine`, `disableCity`, `disableState`, `disableZipCode`
|
|
57
|
+
* **Advanced Controls (optional):** `paymentCurrency`, `showCurrencySelector`, `paymentAmount`, `showDiscounts`
|
|
58
|
+
* **Metadata (optional):** Any query parameter starting with `metadata_` (e.g., `?metadata_userId=abc123`)
|
|
59
|
+
* **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:
|
|
60
|
+
* [Docs - One Time Payment Product](https://docs.dodopayments.com/api-reference/payments/post-payments)
|
|
61
|
+
* [Docs - Subscription Product](https://docs.dodopayments.com/api-reference/subscriptions/post-subscriptions)
|
|
62
|
+
* **Error Handling:** If `productId` is missing or other query parameters are invalid, the handler will return a 400 response.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
**If `Customer Portal Route Handler` is selected:**
|
|
66
|
+
|
|
67
|
+
**Purpose:** This handler redirects authenticated users to their Dodo Payments customer portal.
|
|
68
|
+
**File Creation:** Create a new file at `app/customer-portal/route.ts` in your Next.js project.
|
|
69
|
+
**Code Snippet:**
|
|
70
|
+
```typescript
|
|
71
|
+
// app/customer-portal/route.ts
|
|
72
|
+
import { CustomerPortal } from '@dodopayments/nextjs'
|
|
73
|
+
|
|
74
|
+
export const GET = CustomerPortal({
|
|
75
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY!,
|
|
76
|
+
environment: "test_mode",
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
**Query Parameters:**
|
|
80
|
+
* `customer_id` (required): The customer ID for the portal session (e.g., `?customer_id=cus_123`)
|
|
81
|
+
* `send_email` (optional, boolean): If set to `true`, sends an email to the customer with the portal link.
|
|
82
|
+
* Returns 400 if `customer_id` is missing.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
**If `Webhook Route Handler` is selected:**
|
|
86
|
+
|
|
87
|
+
**Purpose:** This handler processes incoming webhook events from Dodo Payments, allowing your application to react to events like successful payments, refunds, or subscription changes.
|
|
88
|
+
**File Creation:** Create a new file at `app/api/webhook/dodo-payments/route.ts` in your Next.js project.
|
|
89
|
+
**Code Snippet:**
|
|
90
|
+
```typescript
|
|
91
|
+
// app/api/webhook/dodo-payments/route.ts
|
|
92
|
+
import { Webhooks } from '@dodopayments/nextjs'
|
|
93
|
+
|
|
94
|
+
export const POST = Webhooks({
|
|
95
|
+
webhookKey: process.env.DODO_PAYMENTS_WEBHOOK_SECRET!,
|
|
96
|
+
onPayload: async (payload) => {
|
|
97
|
+
// handle the payload
|
|
98
|
+
},
|
|
99
|
+
// ... other event handlers for granular control
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
**Handler Details:**
|
|
103
|
+
* **Method:** Only POST requests are supported. Other methods return 405.
|
|
104
|
+
* **Signature Verification:** The handler verifies the webhook signature using the `webhookKey` and returns 401 if verification fails.
|
|
105
|
+
* **Payload Validation:** The payload is validated with Zod. Returns 400 for invalid payloads.
|
|
106
|
+
* **Error Handling:**
|
|
107
|
+
* 401: Invalid signature
|
|
108
|
+
* 400: Invalid payload
|
|
109
|
+
* 500: Internal error during verification
|
|
110
|
+
* **Event Routing:** Calls the appropriate event handler based on the payload type.
|
|
111
|
+
* **Supported Webhook Event Handlers:**
|
|
112
|
+
* `onPayload?: (payload: WebhookPayload) => Promise<void>;`
|
|
113
|
+
* `onPaymentSucceeded?: (payload: WebhookPayload) => Promise<void>;`
|
|
114
|
+
* `onPaymentFailed?: (payload: WebhookPayload) => Promise<void>;`
|
|
115
|
+
* `onPaymentProcessing?: (payload: WebhookPayload) => Promise<void>;`
|
|
116
|
+
* `onPaymentCancelled?: (payload: WebhookPayload) => Promise<void>;`
|
|
117
|
+
* `onRefundSucceeded?: (payload: WebhookPayload) => Promise<void>;`
|
|
118
|
+
* `onRefundFailed?: (payload: WebhookPayload) => Promise<void>;`
|
|
119
|
+
* `onDisputeOpened?: (payload: WebhookPayload) => Promise<void>;`
|
|
120
|
+
* `onDisputeExpired?: (payload: WebhookPayload) => Promise<void>;`
|
|
121
|
+
* `onDisputeAccepted?: (payload: WebhookPayload) => Promise<void>;`
|
|
122
|
+
* `onDisputeCancelled?: (payload: WebhookPayload) => Promise<void>;`
|
|
123
|
+
* `onDisputeChallenged?: (payload: WebhookPayload) => Promise<void>;`
|
|
124
|
+
* `onDisputeWon?: (payload: WebhookPayload) => Promise<void>;`
|
|
125
|
+
* `onDisputeLost?: (payload: WebhookPayload) => Promise<void>;`
|
|
126
|
+
* `onSubscriptionActive?: (payload: WebhookPayload) => Promise<void>;`
|
|
127
|
+
* `onSubscriptionOnHold?: (payload: WebhookPayload) => Promise<void>;`
|
|
128
|
+
* `onSubscriptionRenewed?: (payload: WebhookPayload) => Promise<void>;`
|
|
129
|
+
* `onSubscriptionPaused?: (payload: WebhookPayload) => Promise<void>;`
|
|
130
|
+
* `onSubscriptionPlanChanged?: (payload: WebhookPayload) => Promise<void>;`
|
|
131
|
+
* `onSubscriptionCancelled?: (payload: WebhookPayload) => Promise<void>;`
|
|
132
|
+
* `onSubscriptionFailed?: (payload: WebhookPayload) => Promise<void>;`
|
|
133
|
+
* `onSubscriptionExpired?: (payload: WebhookPayload) => Promise<void>;`
|
|
134
|
+
* `onLicenseKeyCreated?: (payload: WebhookPayload) => Promise<void>;`
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
3. **Environment Variable Setup:**
|
|
139
|
+
|
|
140
|
+
To ensure the adapter functions correctly, you will need to manually set up the following environment variables in your Next.js project's deployment environment (e.g., Vercel, Netlify, AWS, etc.):
|
|
141
|
+
|
|
142
|
+
* `DODO_PAYMENTS_API_KEY`: Your Dodo Payments API Key (required for Checkout and Customer Portal).
|
|
143
|
+
* `RETURN_URL`: (Optional) The URL to redirect to after a successful checkout (for Checkout handler).
|
|
144
|
+
* `DODO_PAYMENTS_WEBHOOK_SECRET`: Your Dodo Payments Webhook Secret (required for Webhook handler).
|
|
145
|
+
|
|
146
|
+
**Example `.env` file:**
|
|
147
|
+
```env
|
|
148
|
+
DODO_PAYMENTS_API_KEY=your-api-key
|
|
149
|
+
DODO_PAYMENTS_WEBHOOK_SECRET=your-webhook-secret
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**Usage in your code:**
|
|
153
|
+
```typescript
|
|
154
|
+
bearerToken: process.env.DODO_PAYMENTS_API_KEY!
|
|
155
|
+
webhookKey: process.env.DODO_PAYMENTS_WEBHOOK_SECRET!
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**Important:** Never commit sensitive environment variables directly into your version control. Use environment variables for all sensitive information.
|
|
159
|
+
|
|
160
|
+
If the user needs assistance setting up environment variables for their specific deployment environment, ask them what platform they are using (e.g., Vercel, Netlify, AWS, etc.), and provide guidance. You can also add comments to their PR or chat depending on the context.
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dodopayments/fastify",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "rollup -c",
|
|
9
|
+
"dev": "rollup -c -w",
|
|
10
|
+
"format": "prettier --write .",
|
|
11
|
+
"check-format": "prettier --check .",
|
|
12
|
+
"check-types": "tsc --noEmit"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"require": "./dist/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@dodopayments/core": "^0.1.7"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"payments",
|
|
26
|
+
"fastify",
|
|
27
|
+
"webhooks",
|
|
28
|
+
"checkout",
|
|
29
|
+
"api",
|
|
30
|
+
"typescript"
|
|
31
|
+
],
|
|
32
|
+
"author": {
|
|
33
|
+
"name": "Dodo Payments",
|
|
34
|
+
"email": "support@dodopayments.com",
|
|
35
|
+
"url": "https://dodopayments.com"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@dodo/typescript-config": "*",
|
|
39
|
+
"@rollup/plugin-commonjs": "^25.0.0",
|
|
40
|
+
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
41
|
+
"@rollup/plugin-typescript": "^11.0.0",
|
|
42
|
+
"fastify": "^5.4.0",
|
|
43
|
+
"rimraf": "^5.0.0",
|
|
44
|
+
"rollup": "^4.0.0",
|
|
45
|
+
"rollup-plugin-dts": "^6.1.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"fastify": "^5.4.0",
|
|
49
|
+
"zod": "^3.25.73"
|
|
50
|
+
},
|
|
51
|
+
"type": "module",
|
|
52
|
+
"files": [
|
|
53
|
+
"dist",
|
|
54
|
+
"llm-prompt.txt"
|
|
55
|
+
]
|
|
56
|
+
}
|