Context
During review of PR #159, a reviewer pointed out that the test server endpoints (/api/protected, /api/extensions-echo) currently only return payment requirements but don't actually verify or settle payments.
Issue
The E2E test expects result.success and result.message from the server endpoints, but the server only returns payment requirements. There's missing middleware or handlers that should:
- Process payment headers from incoming requests
- Call the facilitator's verify method to validate payments
- Call the facilitator's settle method to execute settlements
- Return appropriate success/error responses
Proposed Solution
Implement proper payment verification and settlement in the test server:
- Add payment middleware to intercept requests with payment headers
- Integrate facilitator SDK to verify and settle payments
- Return proper responses based on verification/settlement results
Example Implementation Approach
// Add middleware to process payment headers
app.use('*', async (c, next) => {
const paymentHeader = c.req.header('X-PAYMENT');
if (paymentHeader) {
// Verify payment
const facilitator = createRouterSettlementFacilitator({
signer: contracts.accounts.facilitator,
allowedRouters: { "eip155:31337": [contracts.settlementRouter.address] },
rpcUrls: { "eip155:31337": `http://localhost:${TEST_CONFIG.anvilPort}` },
privateKey: FACILITATOR_PRIVATE_KEY
});
const result = await facilitator.verify(paymentPayload, paymentRequirements);
if (!result.isValid) {
return c.json({ success: false, error: result.invalidReason }, 402);
}
await facilitator.settle(paymentPayload, paymentRequirements);
c.set('payment', result);
}
await next();
});
Impact
This would make the E2E tests more complete by actually verifying and settling payments rather than just returning payment requirements.
Related PR
Deferred from PR #159 comment #2652058521
Context
During review of PR #159, a reviewer pointed out that the test server endpoints (
/api/protected,/api/extensions-echo) currently only return payment requirements but don't actually verify or settle payments.Issue
The E2E test expects
result.successandresult.messagefrom the server endpoints, but the server only returns payment requirements. There's missing middleware or handlers that should:Proposed Solution
Implement proper payment verification and settlement in the test server:
Example Implementation Approach
Impact
This would make the E2E tests more complete by actually verifying and settling payments rather than just returning payment requirements.
Related PR
Deferred from PR #159 comment #2652058521