Skip to content

Commit 36550e3

Browse files
committed
it works
1 parent 659e69f commit 36550e3

File tree

13 files changed

+144
-105
lines changed

13 files changed

+144
-105
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ yarn-error.log*
2828
# local env files
2929
.env*.local
3030
.env
31+
.env.development
32+
.env.local
3133

3234
# vercel
3335
.vercel

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
## Usage
44

5+
Install [Node.js](https://nodejs.org/) and [pnpm](https://pnpm.io/).
6+
57
Use [clovyr.app](https://clovyr.app/)'s free plan (7-day free trial) for [testing BTCPayServer](https://clovyr.app/apps/btcpayserver).
68

79
After testing, you can use Lunanode or [Voltage Cloud's hosted BTCPayServer](https://www.youtube.com/playlist?list=PLuMtKGSqizH2sxmKdy52gdbqSVKkyLX-t) Plan for $8/month or buy a VPS from Kyun Host ($16/month) to self-host it yourself using [btcpayserver-docker](https://github.com/btcpayserver/btcpayserver-docker).
810

9-
Use [Sparrow Wallet](https://bitcoiner.guide/sparrow/) to test Bitcoin Payments using [testnet](https://www.youtube.com/watch?v=7JJkLW4SHKQ).
11+
Use [Sparrow Wallet](https://bitcoiner.guide/sparrow/) to test Bitcoin Payments using [testnet](https://www.youtube.com/watch?v=7JJkLW4SHKQ) with [bitcoin testnet faucet](https://coinfaucet.eu/en/btc-testnet/).
1012

11-
### .env
13+
### .env.development
1214

1315
```bash
1416
NODE_ENV=development
@@ -29,6 +31,6 @@ NEXT_PUBLIC_EBOOK_PRICE=57
2931
NEXT_TELEMETRY_DISABLED=1
3032
```
3133

32-
Run `pnpm dev` in one terminal and `pnpm ngrok:listen` in another terminal. `ngrok` is needed for webhooks as webhooks don't work on http, they need https.
34+
Run `pnpm dev` (or `pnpm turbo`) in one terminal and `pnpm ngrok:listen` in another terminal. `ngrok` is needed for webhooks as webhooks don't work on http, they need https.
3335

3436
> Make sure to set up [ngrok](https://ngrok.com) with [static domain](https://ngrok.com/blog-post/free-static-domains-ngrok-users).

package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"private": true,
55
"scripts": {
66
"dev": "next dev",
7+
"turbo": "next dev --turbo",
78
"build": "next build",
89
"start": "next start",
910
"lint": "next lint",
@@ -13,20 +14,20 @@
1314
"dependencies": {
1415
"@paralleldrive/cuid2": "^2.2.2",
1516
"next": "14.0.4",
16-
"react": "^18",
17-
"react-dom": "^18",
17+
"react": "^18.2.0",
18+
"react-dom": "^18.2.0",
1819
"valibot": "^0.25.0"
1920
},
2021
"devDependencies": {
21-
"@types/node": "^20",
22-
"@types/react": "^18",
23-
"@types/react-dom": "^18",
24-
"autoprefixer": "^10.0.1",
25-
"eslint": "^8",
22+
"@types/node": "^20.10.6",
23+
"@types/react": "^18.2.46",
24+
"@types/react-dom": "^18.2.18",
25+
"autoprefixer": "^10.4.16",
26+
"eslint": "^8.56.0",
2627
"eslint-config-next": "14.0.4",
27-
"postcss": "^8",
28+
"postcss": "^8.4.32",
2829
"rimraf": "^5.0.5",
29-
"tailwindcss": "^3.3.0",
30-
"typescript": "^5"
30+
"tailwindcss": "^3.4.0",
31+
"typescript": "^5.3.3"
3132
}
3233
}

pnpm-lock.yaml

Lines changed: 41 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/api/btcpayserver/checkout/route.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ export const POST = async (request: NextRequest, response: NextResponse) => {
1313
const req = await request.json()
1414
console.info('🏁 POST /api/btcpayserver/checkout/route')
1515

16+
if (
17+
typeof BASE_URL === 'undefined' ||
18+
typeof EBOOK_PRICE === 'undefined' ||
19+
typeof BTCPAY_API_KEY === 'undefined' ||
20+
typeof BTCPAY_STORE_ID === 'undefined' ||
21+
typeof BTCPAY_URL === 'undefined'
22+
) {
23+
throw new Error('Env variables are not defined')
24+
}
25+
1626
const btcpayserverSchema = object({
1727
email: string([email()]),
1828
})
@@ -21,6 +31,7 @@ export const POST = async (request: NextRequest, response: NextResponse) => {
2131

2232
const project_name = 'BTC Ebook'
2333
const amount = ((EBOOK_PRICE || 97) as number) - 20
34+
const currency = 'USD'
2435

2536
try {
2637
const { email } = parse(btcpayserverSchema, req)
@@ -29,7 +40,6 @@ export const POST = async (request: NextRequest, response: NextResponse) => {
2940
orderId: createId(),
3041
project_name,
3142
buyerEmail: email,
32-
amount,
3343
}
3444

3545
const response = await fetch(
@@ -48,7 +58,7 @@ export const POST = async (request: NextRequest, response: NextResponse) => {
4858
body: JSON.stringify({
4959
amount,
5060
email,
51-
currency: 'USD',
61+
currency,
5262
metadata,
5363
checkout: { redirectURL },
5464
}),

0 commit comments

Comments
 (0)