SDKs & CLI

Official client libraries and CLI tool for integrating PayDirect settlement on Base mainnet.

Method Reference
Quick comparison of available methods across SDKs
OperationTypeScriptPythonCLI
Create paymentcreatePayment()create_payment()payments create
Get paymentgetPayment(id)get_payment(id)payments get
List paymentslistPayments()list_payments()payments list
Cancel paymentcancelPayment(id)cancel_payment(id)payments cancel
Verify paymentverifyPayment(id)verify_payment(id)payments verify
Create webhookcreateWebhook()create_webhook()webhooks create
List webhookslistWebhooks()list_webhooks()webhooks list
Delete webhookdeleteWebhook(id)delete_webhook(id)webhooks delete
List keyslistKeys()list_keys()keys list
Create keycreateKey()create_key()-
Revoke keyrevokeKey(id)revoke_key(id)-
Verify webhook sigverifyWebhookSignature()verify_signature()-
TypeScript
TypeScript SDK
@paydirect/sdk - Official TypeScript/JavaScript client

Installation

npm install @paydirect/sdk
# or
pnpm add @paydirect/sdk

Initialization

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 paydirect

Initialization

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"])  # True

Webhooks

# 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 body
CLI
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  # optional

The init command creates a .paydirect.json file in the current directory.

Commands

CommandDescription
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 listList webhooks
webhooks create <url> [events]Register a webhook
webhooks delete <id>Remove a webhook
keys listList API keys
statusShow 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.failed
x402 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/evm

Client Side (Agent Auto-Pay)

npm install @x402/fetch @x402/core @x402/evm

Quick 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.