@dodopayments/nuxt 0.1.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 +75 -0
- package/dist/module.d.mts +7 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +16 -0
- package/dist/runtime/server/checkout.d.ts +0 -0
- package/dist/runtime/server/checkout.js +43 -0
- package/dist/runtime/server/customer-portal.d.ts +0 -0
- package/dist/runtime/server/customer-portal.js +26 -0
- package/dist/runtime/server/index.d.ts +0 -0
- package/dist/runtime/server/index.js +3 -0
- package/dist/runtime/server/webhooks.d.ts +0 -0
- package/dist/runtime/server/webhooks.js +56 -0
- package/dist/types.d.mts +3 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Nuxt Minimal Starter
|
|
2
|
+
|
|
3
|
+
Look at the [Nuxt documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
Make sure to install dependencies:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# npm
|
|
11
|
+
npm install
|
|
12
|
+
|
|
13
|
+
# pnpm
|
|
14
|
+
pnpm install
|
|
15
|
+
|
|
16
|
+
# yarn
|
|
17
|
+
yarn install
|
|
18
|
+
|
|
19
|
+
# bun
|
|
20
|
+
bun install
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Development Server
|
|
24
|
+
|
|
25
|
+
Start the development server on `http://localhost:3000`:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# npm
|
|
29
|
+
npm run dev
|
|
30
|
+
|
|
31
|
+
# pnpm
|
|
32
|
+
pnpm dev
|
|
33
|
+
|
|
34
|
+
# yarn
|
|
35
|
+
yarn dev
|
|
36
|
+
|
|
37
|
+
# bun
|
|
38
|
+
bun run dev
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Production
|
|
42
|
+
|
|
43
|
+
Build the application for production:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# npm
|
|
47
|
+
npm run build
|
|
48
|
+
|
|
49
|
+
# pnpm
|
|
50
|
+
pnpm build
|
|
51
|
+
|
|
52
|
+
# yarn
|
|
53
|
+
yarn build
|
|
54
|
+
|
|
55
|
+
# bun
|
|
56
|
+
bun run build
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Locally preview production build:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# npm
|
|
63
|
+
npm run preview
|
|
64
|
+
|
|
65
|
+
# pnpm
|
|
66
|
+
pnpm preview
|
|
67
|
+
|
|
68
|
+
# yarn
|
|
69
|
+
yarn preview
|
|
70
|
+
|
|
71
|
+
# bun
|
|
72
|
+
bun run preview
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.
|
package/dist/module.json
ADDED
package/dist/module.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineNuxtModule, createResolver, addServerImportsDir } from '@nuxt/kit';
|
|
2
|
+
|
|
3
|
+
const module = defineNuxtModule({
|
|
4
|
+
meta: {
|
|
5
|
+
name: "@dodopayments/nuxt",
|
|
6
|
+
configKey: "dodopayments"
|
|
7
|
+
},
|
|
8
|
+
// Default configuration options of the Nuxt module
|
|
9
|
+
defaults: {},
|
|
10
|
+
setup(_options, _nuxt) {
|
|
11
|
+
const resolver = createResolver(import.meta.url);
|
|
12
|
+
addServerImportsDir(resolver.resolve("./runtime/server"));
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export { module as default };
|
|
File without changes
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildCheckoutUrl,
|
|
3
|
+
checkoutQuerySchema,
|
|
4
|
+
dynamicCheckoutBodySchema
|
|
5
|
+
} from "@dodopayments/core/checkout";
|
|
6
|
+
import { getQuery, readBody, sendRedirect, createError } from "h3";
|
|
7
|
+
export function checkoutHandler(config) {
|
|
8
|
+
return async (event) => {
|
|
9
|
+
if (event.method === "POST") {
|
|
10
|
+
const body = await readBody(event);
|
|
11
|
+
const { success, data, error } = dynamicCheckoutBodySchema.safeParse(body);
|
|
12
|
+
if (!success) {
|
|
13
|
+
throw createError({
|
|
14
|
+
statusCode: 400,
|
|
15
|
+
statusMessage: "Invalid request body",
|
|
16
|
+
data: error.format()
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const url = await buildCheckoutUrl({ body: data, ...config, type: "dynamic" });
|
|
21
|
+
return sendRedirect(event, url, 302);
|
|
22
|
+
} catch (error2) {
|
|
23
|
+
throw createError({ statusCode: 400, statusMessage: error2.message });
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
const queryParams = getQuery(event);
|
|
27
|
+
const { success, data, error } = checkoutQuerySchema.safeParse(queryParams);
|
|
28
|
+
if (!success) {
|
|
29
|
+
throw createError({
|
|
30
|
+
statusCode: 400,
|
|
31
|
+
statusMessage: "Invalid query parameters",
|
|
32
|
+
data: error.format()
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const url = await buildCheckoutUrl({ queryParams: data, ...config });
|
|
37
|
+
return sendRedirect(event, url, 302);
|
|
38
|
+
} catch (error2) {
|
|
39
|
+
throw createError({ statusCode: 400, statusMessage: error2.message });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import DodoPayments from "dodopayments";
|
|
2
|
+
import { getQuery, sendRedirect } from "h3";
|
|
3
|
+
export function customerPortalHandler(config) {
|
|
4
|
+
return async (event) => {
|
|
5
|
+
const query = getQuery(event);
|
|
6
|
+
const customerId = query.customer_id;
|
|
7
|
+
const sendEmail = query.send_email === "true";
|
|
8
|
+
const params = { send_email: sendEmail };
|
|
9
|
+
if (!customerId) {
|
|
10
|
+
return { status: 400, body: "Missing customer_id in query parameters" };
|
|
11
|
+
}
|
|
12
|
+
const dodopayments = new DodoPayments({
|
|
13
|
+
bearerToken: config.bearerToken,
|
|
14
|
+
environment: config.environment
|
|
15
|
+
});
|
|
16
|
+
try {
|
|
17
|
+
const session = await dodopayments.customers.customerPortal.create(
|
|
18
|
+
customerId,
|
|
19
|
+
params
|
|
20
|
+
);
|
|
21
|
+
return sendRedirect(event, session.link, 302);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
return { status: 500, body: `Failed to create customer portal session: ${error.message}` };
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Webhook as StandardWebhook,
|
|
3
|
+
WebhookVerificationError
|
|
4
|
+
} from "standardwebhooks";
|
|
5
|
+
import {
|
|
6
|
+
handleWebhookPayload
|
|
7
|
+
} from "@dodopayments/core/webhook";
|
|
8
|
+
import { readRawBody, createError, send, setResponseStatus } from "h3";
|
|
9
|
+
import { WebhookPayloadSchema } from "@dodopayments/core/schemas";
|
|
10
|
+
export function Webhooks(config) {
|
|
11
|
+
const standardWebhook = new StandardWebhook(config.webhookKey);
|
|
12
|
+
return async (event) => {
|
|
13
|
+
if (event.method !== "POST") {
|
|
14
|
+
throw createError({
|
|
15
|
+
statusCode: 405,
|
|
16
|
+
statusMessage: "Method Not Allowed: Only POST is supported"
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const headers = Object.fromEntries(
|
|
20
|
+
Object.entries(event.node.req.headers).map(([key, val]) => [
|
|
21
|
+
key,
|
|
22
|
+
Array.isArray(val) ? val.join(",") : val ?? ""
|
|
23
|
+
])
|
|
24
|
+
);
|
|
25
|
+
const rawBody = await readRawBody(event);
|
|
26
|
+
const rawString = rawBody?.toString() || "";
|
|
27
|
+
try {
|
|
28
|
+
standardWebhook.verify(rawString, headers);
|
|
29
|
+
} catch (err) {
|
|
30
|
+
if (err instanceof WebhookVerificationError) {
|
|
31
|
+
throw createError({ statusCode: 401, statusMessage: err.message });
|
|
32
|
+
}
|
|
33
|
+
throw createError({
|
|
34
|
+
statusCode: 500,
|
|
35
|
+
statusMessage: "Unexpected error while verifying webhook"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
let payload;
|
|
39
|
+
try {
|
|
40
|
+
payload = JSON.parse(rawString);
|
|
41
|
+
} catch {
|
|
42
|
+
throw createError({ statusCode: 400, statusMessage: "Invalid JSON payload" });
|
|
43
|
+
}
|
|
44
|
+
const { success, data, error } = WebhookPayloadSchema.safeParse(payload);
|
|
45
|
+
if (!success) {
|
|
46
|
+
throw createError({
|
|
47
|
+
statusCode: 400,
|
|
48
|
+
statusMessage: "Error parsing webhook payload",
|
|
49
|
+
data: error.format()
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
await handleWebhookPayload(data, config);
|
|
53
|
+
setResponseStatus(event, 200);
|
|
54
|
+
return send(event, "");
|
|
55
|
+
};
|
|
56
|
+
}
|
package/dist/types.d.mts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dodopayments/nuxt",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Dodo Payments Nuxt integration",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/module.mjs",
|
|
12
|
+
"types": "./dist/module.d.mts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "nuxt-module-build build",
|
|
20
|
+
"dev": "rollup -c -w"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@dodopayments/core": "^0.1.13",
|
|
24
|
+
"@nuxt/module-builder": "^1.0.1"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@rollup/plugin-commonjs": "^25.0.0",
|
|
28
|
+
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
29
|
+
"@rollup/plugin-typescript": "^11.0.0",
|
|
30
|
+
"rimraf": "^5.0.0",
|
|
31
|
+
"rollup": "^4.0.0",
|
|
32
|
+
"rollup-plugin-dts": "^6.1.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"nuxt": "^4.0.0",
|
|
36
|
+
"vue": "^3.5.17",
|
|
37
|
+
"vue-router": "^4.5.1",
|
|
38
|
+
"zod": "^3.25.74"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"payments",
|
|
42
|
+
"dodo",
|
|
43
|
+
"nuxt",
|
|
44
|
+
"webhooks",
|
|
45
|
+
"checkout",
|
|
46
|
+
"api",
|
|
47
|
+
"typescript"
|
|
48
|
+
],
|
|
49
|
+
"author": {
|
|
50
|
+
"name": "Dodo Payments",
|
|
51
|
+
"email": "support@dodopayments.com",
|
|
52
|
+
"url": "https://dodopayments.com"
|
|
53
|
+
},
|
|
54
|
+
"license": "Apache-2.0"
|
|
55
|
+
}
|