Skip to content

Commit b88919c

Browse files
[SDK] Rename verifyPayment() to processPayment() for x402 payments
1 parent a81899d commit b88919c

File tree

9 files changed

+516
-186
lines changed

9 files changed

+516
-186
lines changed

.changeset/some-moons-burn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"thirdweb": minor
33
---
44

5-
Accept arbitrary chain ids for x402 payments with new verifyPayment() backend utility
5+
Accept arbitrary chain ids for x402 payments with new settlePayment() backend utility

apps/playground-web/src/app/payments/x402/page.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function ServerCodeExample() {
5757
className="h-full rounded-none border-none"
5858
code={`// src/middleware.ts
5959
60-
import { facilitator, verifyPayment } from "thirdweb/x402";
60+
import { facilitator, settlePayment } from "thirdweb/x402";
6161
import { createThirdwebClient } from "thirdweb";
6262
6363
const client = createThirdwebClient({ secretKey: "your-secret-key" });
@@ -71,16 +71,13 @@ export async function middleware(request: NextRequest) {
7171
const resourceUrl = request.nextUrl.toString();
7272
const paymentData = request.headers.get("X-PAYMENT");
7373
74-
const result = await verifyPayment({
74+
const result = await settlePayment({
7575
resourceUrl,
7676
method,
7777
paymentData,
7878
payTo: "0xYourWalletAddress",
7979
network: "eip155:11155111", // or any other chain id
8080
price: "$0.01", // can also be a ERC20 token amount
81-
routeConfig: {
82-
description: "Access to paid content",
83-
},
8481
facilitator: thirdwebX402Facilitator,
8582
});
8683

apps/playground-web/src/middleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type NextRequest, NextResponse } from "next/server";
22
import { createThirdwebClient } from "thirdweb";
33
import { arbitrumSepolia } from "thirdweb/chains";
4-
import { facilitator, verifyPayment } from "thirdweb/x402";
4+
import { facilitator, settlePayment } from "thirdweb/x402";
55

66
const client = createThirdwebClient({
77
secretKey: process.env.THIRDWEB_SECRET_KEY as string,
@@ -26,7 +26,7 @@ export async function middleware(request: NextRequest) {
2626
const resourceUrl = `${request.nextUrl.protocol}//${request.nextUrl.host}${pathname}`;
2727
const paymentData = request.headers.get("X-PAYMENT");
2828

29-
const result = await verifyPayment({
29+
const result = await settlePayment({
3030
resourceUrl,
3131
method,
3232
paymentData,

apps/portal/src/app/payments/x402/page.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ const response = await fetchWithPay('https://api.example.com/paid-endpoint');
4141

4242
## Server Side
4343

44-
To make your API calls payable, you can use the `verifyPayment` function in a simple middleware or in your endpoint directly.
44+
To make your API calls payable, you can use the `settlePayment` function in a middleware or in your endpoint directly.
4545

46-
Use the `facilitator` configuration function settle transactions with your thirdweb server wallet gaslessly and pass it to the `verifyPayment` function.
46+
Use the `facilitator` configuration function settle transactions with your thirdweb server wallet gaslessly and pass it to the `settlePayment` function.
4747

4848
Here's an example with a Next.js middleware:
4949

5050
```typescript
5151
import { createThirdwebClient } from "thirdweb";
52-
import { facilitator, verifyPayment } from "thirdweb/x402";
52+
import { facilitator, settlePayment } from "thirdweb/x402";
5353

5454
const client = createThirdwebClient({ secretKey: "your-secret-key" });
5555
const thirdwebX402Facilitator = facilitator({
@@ -62,7 +62,7 @@ export async function middleware(request: NextRequest) {
6262
const resourceUrl = request.nextUrl.toString();
6363
const paymentData = request.headers.get("X-PAYMENT");
6464

65-
const result = await verifyPayment({
65+
const result = await settlePayment({
6666
resourceUrl,
6767
method,
6868
paymentData,
@@ -97,3 +97,5 @@ export const config = {
9797
matcher: ["/api/paid-endpoint"],
9898
};
9999
```
100+
101+
You can also use the `verifyPayment` function to verify the payment before settling it. This lets you do the work that requires payment first and then settle the payment.

packages/thirdweb/src/exports/x402.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@ export {
44
type ThirdwebX402FacilitatorConfig,
55
} from "../x402/facilitator.js";
66
export { wrapFetchWithPayment } from "../x402/fetchWithPayment.js";
7-
export {
8-
type VerifyPaymentArgs,
9-
type VerifyPaymentResult,
10-
verifyPayment,
11-
} from "../x402/verify-payment.js";
7+
export { settlePayment } from "../x402/settle-payment.js";
8+
export type { PaymentArgs, SettlePaymentResult } from "../x402/types.js";

packages/thirdweb/src/x402/facilitator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const DEFAULT_BASE_URL = "https://api.thirdweb.com/v1/payments/x402";
1919

2020
/**
2121
* Creates a facilitator for the x402 payment protocol.
22-
* You can use this with `verifyPayment` or with any x402 middleware to enable settling transactions with your thirdweb server wallet.
22+
* You can use this with `settlePayment` or with any x402 middleware to enable settling transactions with your thirdweb server wallet.
2323
*
2424
* @param config - The configuration for the facilitator
2525
* @returns a x402 compatible FacilitatorConfig

0 commit comments

Comments
 (0)