-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayment.jsx
More file actions
32 lines (28 loc) · 1.02 KB
/
payment.jsx
File metadata and controls
32 lines (28 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { createThirdwebClient } from "thirdweb";
import { facilitator, settlePayment } from "thirdweb/x402";
import { arbitrumSepolia } from "thirdweb/chains";
const client = createThirdwebClient({ secretKey: "Hs2PxCHRqJhJDgosj_34swOVxNELj3wLScpCELckqgYJ8j-MMhk2PdOQPK5lxtExMk5wKNduLfd-obBCaDoxmQ" });
const thirdwebX402Facilitator = facilitator({
client,
serverWalletAddress: "0x18F0CC62ABA5C51Fc28070484821d4bea75Bd4cE",
});
export async function GET(request: Request) {
// process the payment
const result = await settlePayment({
resourceUrl: "https://api.example.com/premium-content",
method: "GET",
paymentData: request.headers.get("x-payment"),
network: arbitrumSepolia,
price: "$0.01",
facilitator: thirdwebX402Facilitator,
});
if (result.status === 200) {
// Payment successful, continue to app logic
return Response.json({ data: "premium content" });
} else {
return Response.json(result.responseBody, {
status: result.status,
headers: result.responseHeaders,
});
}
}