-
Notifications
You must be signed in to change notification settings - Fork 619
[SDK] Fix waitUntil facilitator parameter not being respected #8184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
joaquim-verges
merged 1 commit into
main
from
_thirdweb_Fix_waitUntil_facilitator_parameter_not_being_respected
Oct 4, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "thirdweb": patch | ||
| --- | ||
|
|
||
| Fix waitUntil facilitator param not being respected |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| name: Auto Author Assign | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, reopened, ready_for_review] | ||
|
|
||
| permissions: | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| assign-author: | ||
| runs-on: ubuntu-latest | ||
| if: | | ||
| github.event.pull_request.author_association == 'MEMBER' || | ||
| github.event.pull_request.author_association == 'OWNER' || | ||
| github.event.pull_request.author_association == 'COLLABORATOR' || | ||
| github.event.pull_request.author_association == 'CONTRIBUTOR' | ||
| steps: | ||
| - uses: toshimaru/auto-author-assign@16f0022cf3d7970c106d8d1105f75a1165edb516 # v2.1.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,90 @@ | ||
| import { NextResponse } from "next/server"; | ||
| import { type NextRequest, NextResponse } from "next/server"; | ||
| import { createThirdwebClient, defineChain } from "thirdweb"; | ||
| import { toUnits } from "thirdweb/utils"; | ||
| import { facilitator, settlePayment } from "thirdweb/x402"; | ||
| import { token } from "../../payments/x402/components/constants"; | ||
|
|
||
| // Allow streaming responses up to 5 minutes | ||
| export const maxDuration = 300; | ||
|
|
||
| export async function GET(_req: Request) { | ||
| return NextResponse.json({ | ||
| success: true, | ||
| message: "Payment successful. You have accessed the protected route.", | ||
| export async function GET(request: NextRequest) { | ||
| const client = createThirdwebClient({ | ||
| secretKey: process.env.THIRDWEB_SECRET_KEY as string, | ||
| }); | ||
|
|
||
| const BACKEND_WALLET_ADDRESS = process.env.ENGINE_BACKEND_WALLET as string; | ||
| // const BACKEND_WALLET_ADDRESS = process.env.ENGINE_BACKEND_SMART_WALLET as string; | ||
| const ENGINE_VAULT_ACCESS_TOKEN = process.env | ||
| .ENGINE_VAULT_ACCESS_TOKEN as string; | ||
| const API_URL = `https://${process.env.NEXT_PUBLIC_API_URL || "api.thirdweb.com"}`; | ||
|
|
||
| const twFacilitator = facilitator({ | ||
| baseUrl: `${API_URL}/v1/payments/x402`, | ||
| client, | ||
| serverWalletAddress: BACKEND_WALLET_ADDRESS, | ||
| vaultAccessToken: ENGINE_VAULT_ACCESS_TOKEN, | ||
| }); | ||
|
|
||
| const paymentData = request.headers.get("X-PAYMENT"); | ||
| const queryParams = request.nextUrl.searchParams; | ||
|
|
||
| const chainId = queryParams.get("chainId"); | ||
|
|
||
| if (!chainId) { | ||
| return NextResponse.json( | ||
| { error: "Missing required parameters" }, | ||
| { status: 400 }, | ||
| ); | ||
| } | ||
|
|
||
| const amount = queryParams.get("amount") || "0.01"; | ||
| const tokenAddress = queryParams.get("tokenAddress") || token.address; | ||
| const decimals = queryParams.get("decimals") || token.decimals.toString(); | ||
| const waitUntil = | ||
| (queryParams.get("waitUntil") as "simulated" | "submitted" | "confirmed") || | ||
| "simulated"; | ||
|
|
||
| const result = await settlePayment({ | ||
| resourceUrl: "https://playground-web.thirdweb.com/api/paywall", | ||
| method: "GET", | ||
| paymentData, | ||
| network: defineChain(Number(chainId)), | ||
| price: { | ||
| amount: toUnits(amount, parseInt(decimals)).toString(), | ||
| asset: { | ||
| address: tokenAddress as `0x${string}`, | ||
| decimals: decimals ? parseInt(decimals) : token.decimals, | ||
| }, | ||
| }, | ||
| routeConfig: { | ||
| description: "Access to paid content", | ||
| }, | ||
| waitUntil, | ||
| facilitator: twFacilitator, | ||
| }); | ||
joaquim-verges marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (result.status === 200) { | ||
| // payment successful, execute the request | ||
| return NextResponse.json( | ||
| { | ||
| success: true, | ||
| message: "Payment successful. You have accessed the protected route.", | ||
| payment: { | ||
| amount, | ||
| tokenAddress, | ||
| }, | ||
| receipt: result.paymentReceipt, | ||
| }, | ||
| { | ||
| status: 200, | ||
| headers: result.responseHeaders, | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| // otherwise, request payment | ||
| return NextResponse.json(result.responseBody, { | ||
| status: result.status, | ||
| headers: result.responseHeaders, | ||
| }); | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.