@@ -13,17 +13,13 @@ const BACKEND_WALLET_ADDRESS = process.env.ENGINE_BACKEND_WALLET as string;
1313const ENGINE_VAULT_ACCESS_TOKEN = process . env
1414 . ENGINE_VAULT_ACCESS_TOKEN as string ;
1515const API_URL = `https://${ process . env . NEXT_PUBLIC_API_URL || "api.thirdweb.com" } ` ;
16- function createFacilitator (
17- waitUntil : "simulated" | "submitted" | "confirmed" = "simulated" ,
18- ) {
19- return facilitator ( {
20- baseUrl : `${ API_URL } /v1/payments/x402` ,
21- client,
22- serverWalletAddress : BACKEND_WALLET_ADDRESS ,
23- vaultAccessToken : ENGINE_VAULT_ACCESS_TOKEN ,
24- waitUtil : waitUntil ,
25- } ) ;
26- }
16+
17+ const twFacilitator = facilitator ( {
18+ baseUrl : `${ API_URL } /v1/payments/x402` ,
19+ client,
20+ serverWalletAddress : BACKEND_WALLET_ADDRESS ,
21+ vaultAccessToken : ENGINE_VAULT_ACCESS_TOKEN ,
22+ } ) ;
2723
2824export async function middleware ( request : NextRequest ) {
2925 const pathname = request . nextUrl . pathname ;
@@ -33,9 +29,8 @@ export async function middleware(request: NextRequest) {
3329 const queryParams = request . nextUrl . searchParams ;
3430
3531 const chainId = queryParams . get ( "chainId" ) ;
36- const payTo = queryParams . get ( "payTo" ) ;
3732
38- if ( ! chainId || ! payTo ) {
33+ if ( ! chainId ) {
3934 return NextResponse . json (
4035 { error : "Missing required parameters" } ,
4136 { status : 400 } ,
@@ -53,7 +48,6 @@ export async function middleware(request: NextRequest) {
5348 resourceUrl,
5449 method,
5550 paymentData,
56- payTo : payTo as `0x${string } `,
5751 network : defineChain ( Number ( chainId ) ) ,
5852 price : {
5953 amount : toUnits ( amount , parseInt ( decimals ) ) . toString ( ) ,
@@ -65,7 +59,8 @@ export async function middleware(request: NextRequest) {
6559 routeConfig : {
6660 description : "Access to paid content" ,
6761 } ,
68- facilitator : createFacilitator ( waitUntil ) ,
62+ waitUntil,
63+ facilitator : twFacilitator ,
6964 } ) ;
7065
7166 if ( result . status === 200 ) {
0 commit comments