SDKs & CLI
Official client libraries and CLI tool for integrating PayDirect settlement on Base mainnet.
Method Reference
Quick comparison of available methods across SDKs
| Operation | TypeScript | Python | CLI |
|---|---|---|---|
| Create payment | createPayment() | create_payment() | payments create |
| Get payment | getPayment(id) | get_payment(id) | payments get |
| List payments | listPayments() | list_payments() | payments list |
| Cancel payment | cancelPayment(id) | cancel_payment(id) | payments cancel |
| Verify payment | verifyPayment(id) | verify_payment(id) | payments verify |
| Create webhook | createWebhook() | create_webhook() | webhooks create |
| List webhooks | listWebhooks() | list_webhooks() | webhooks list |
| Delete webhook | deleteWebhook(id) | delete_webhook(id) | webhooks delete |
| List keys | listKeys() | list_keys() | keys list |
| Create key | createKey() | create_key() | - |
| Revoke key | revokeKey(id) | revoke_key(id) | - |
| Verify webhook sig | verifyWebhookSignature() | verify_signature() | - |
TypeScript
TypeScript SDK
@paydirect/sdk - Official TypeScript/JavaScript client
Installation
npm install @paydirect/sdk
# or
pnpm add @paydirect/sdkInitialization
import { PayDirectClient } from "@paydirect/sdk";
const client = new PayDirectClient({
apiKey: "pd_test_abc123...",
baseUrl: "https://paydirect.com/api/v1", // optional, this is the default
});Create a Payment
const { payment, receivingAddress } = await client.createPayment({
tokenSymbol: "USDC", // "USDC" | "ETH" | "ADAO"
amount: "100.00",
merchantWallet: "0xYourBase...",
description: "Invoice #1234", // optional
metadata: { orderId: "ORD_1" }, // optional
idempotencyKey: "order-1-v1", // optional
expiresInMinutes: 60, // optional, default 60
});List and Get Payments
// List with filters
const { payments, total } = await client.listPayments({
status: "forwarded",
environment: "sandbox",
limit: 20,
offset: 0,
});
// Get by ID
const { payment } = await client.getPayment("a1b2c3d4-...");
// Cancel
const { payment: cancelled } = await client.cancelPayment("a1b2c3d4-...");
// Verify settlement
const { verified, payment: p } = await client.verifyPayment("a1b2c3d4-...");Webhooks
// Create
const { webhook } = await client.createWebhook(
"https://yourapp.com/webhooks",
["payment.forwarded", "payment.failed"]
);
console.log(webhook.signingSecret); // "whsec_..." — store this!
// List
const { webhooks } = await client.listWebhooks();
// Delete
await client.deleteWebhook("7");Webhook Signature Verification
// Static method — no client instance needed
const isValid = PayDirectClient.verifyWebhookSignature(
"whsec_...", // signing secret
rawRequestBody, // string
signatureHeader // X-PayDirect-Signature value
);Error Handling
import { PayDirectError } from "@paydirect/sdk";
try {
await client.createPayment({ ... });
} catch (err) {
if (err instanceof PayDirectError) {
console.log(err.message); // human-readable error
console.log(err.status); // HTTP status code
console.log(err.data); // raw response body
}
}Python
Python SDK
paydirect - Official Python client
Installation
pip install paydirectInitialization
from paydirect import PayDirectClient
client = PayDirectClient(
api_key="pd_test_abc123...",
base_url="https://paydirect.com/api/v1", # optional default
)Create a Payment
result = client.create_payment(
token_symbol="USDC",
amount="100.00",
merchant_wallet="0xYourBase...",
description="Invoice #1234", # optional
metadata={"orderId": "ORD_1"}, # optional
idempotency_key="order-1-v1", # optional
expires_in_minutes=60, # optional
)
payment = result["payment"]
receiving_address = result["receivingAddress"]List, Get, Cancel, Verify
# List
result = client.list_payments(status="forwarded", limit=20)
# Get
result = client.get_payment("a1b2c3d4-...")
# Cancel
result = client.cancel_payment("a1b2c3d4-...")
# Verify
result = client.verify_payment("a1b2c3d4-...")
print(result["verified"]) # TrueWebhooks
# Create
result = client.create_webhook(
url="https://yourapp.com/webhooks",
events=["payment.forwarded", "payment.failed"]
)
# List
result = client.list_webhooks()
# Delete
result = client.delete_webhook("7")Webhook Signature Verification
from paydirect.webhooks import verify_signature
is_valid = verify_signature(
secret="whsec_...",
payload=raw_request_body,
signature=request.headers["X-PayDirect-Signature"]
)Error Handling
from paydirect import PayDirectError
try:
client.create_payment(...)
except PayDirectError as e:
print(e) # error message
print(e.status) # HTTP status code
print(e.data) # raw response bodyCLI
Command Line Tool
paydirect CLI for terminal-based API interaction
Installation
npm install -g @paydirect/cli
# or use npx
npx @paydirect/cli <command>Configuration
# Option 1: Initialize config file
paydirect init pd_test_abc123...
# Option 2: Environment variable
export PAYDIRECT_API_KEY=pd_test_abc123...
export PAYDIRECT_BASE_URL=https://paydirect.com/api/v1 # optionalThe init command creates a .paydirect.json file in the current directory.
Commands
| Command | Description |
|---|---|
| init <key> | Save API key to .paydirect.json |
| payments create --token=USDC --amount=100 --wallet=0x... | Create a payment |
| payments list [--status=pending] | List payments with optional filter |
| payments get <id> | Get payment details |
| payments cancel <id> | Cancel a pending payment |
| payments verify <id> | Verify payment settlement |
| webhooks list | List webhooks |
| webhooks create <url> [events] | Register a webhook |
| webhooks delete <id> | Remove a webhook |
| keys list | List API keys |
| status | Show recent payments |
Examples
# Create a 50 USDC payment
paydirect payments create --token=USDC --amount=50 --wallet=0xABC...
# List pending payments
paydirect payments list --status=pending
# Verify a payment
paydirect payments verify a1b2c3d4-...
# Register a webhook for forwarded events
paydirect webhooks create https://myapp.com/hooks payment.forwarded,payment.failedx402 Protocol (by Coinbase)
Optional
HTTP-native payments for AI agents. Install these alongside the PayDirect SDK if you want to add x402 pay-per-request to your API endpoints.
Server Side (Protect API Routes)
npm install x402-next @x402/core @x402/evmClient Side (Agent Auto-Pay)
npm install @x402/fetch @x402/core @x402/evmQuick Example
// Protect a route with x402
import { withX402 } from "x402-next"
export const GET = withX402(
handler,
"0xYourWallet",
{ price: "$0.01", network: "base-sepolia" },
{ url: "https://x402.org/facilitator" }
)See the x402 Payments Guide for full setup instructions.
