Merchant SDKs
Description and purpose
The Merchant SDK is a library that intercepts your route handlers, manages the 402 challenge-and-response cycle and verifies the onchain payment, all in a few lines of code.
Available languages
- TypeScript
- Python (coming soon)
How to download the Merchant SDK
- Create an account in the Merchant Portal.
- Create API keys.
- Download the SDK in your preferred language (TypeScript for now).
Integrating the SDK into the resource server
The merchant is responsible for the integration. It uses the Merchant SDK directly in the code base of its resource server, and uses it to guide the agent step by step through the payment flow:
- Integrate the SDK. Wrap your endpoint or checkout route with the Merchant SDK.
- Send dynamic instructions (HTTP 402). When the agent requests access or attempts to check out, the middleware intercepts the call and builds a standardized
402 Payment Requiredresponse. ThePAYMENT-REQUIREDheader carries machine-readable instructions: the price, the asset (for example USDC or USD8), the recipient address and the payment scheme required (exact,upto,batchand so on). - Guide the next step. The agent reads the header and learns which scheme the merchant expects. It signs the corresponding payment payload with its session key and attaches it as
PAYMENT-SIGNATUREin the retry. - Verify automatically. The Merchant SDK on the merchant’s server receives the signed payload and routes it to the Facilitator for verification and settlement. When the Facilitator confirms the payment, the SDK unlocks the service and returns
PAYMENT-RESPONSE.