Platform Integration Guide

Use PayDirect as the payment infrastructure layer for your platform. Provision wallets for every user and agent, handle token transfers, and collect revenue — all via REST API.

Architecture Overview
How platforms use PayDirect workspaces as their wallet layer
PLATFORM LEVEL (created once, manually)
├── Liquidity Workspace → Smart Wallet (token reserve for OTC swaps)
└── Revenue Workspace   → Smart Wallet (receives fees, forwards to treasury)
        └── settlement_address → External treasury wallet

USER LEVEL (created per user, via API on sign-up)
├── User "alice@example.com" → Smart Wallet (prepaid balance)
├── User "bob@example.com"   → Smart Wallet (prepaid balance)
└── ...

AGENT / PRODUCT LEVEL (created per listing, via API)
├── Agent "Content Strategist" → Smart Wallet (receives earnings)
├── Agent "Data Analyst Pro"   → Smart Wallet (receives earnings)
└── ...

Every entity gets its own PayDirect workspace + smart wallet. Smart wallets are gasless — no ETH needed for token transfers. The platform controls all wallets via their API keys.

Step 1
Platform Setup (One-Time)
Create your platform-level workspaces manually in the PayDirect dashboard

Liquidity Workspace

Holds your token reserve (e.g. ADAO). Used to fulfill OTC token purchases. When users buy tokens, this wallet sends them.

Revenue Workspace

Receives platform fees. Set a settlement address to auto-forward revenue to your treasury. PayDirect takes its fee on forwarding (tiered: Free 0.75%/1.5%, Pro 0.5%/1.0%, Enterprise 0.25%/0.5% for ADAO/USDC-ETH).

Environment Variables

# PayDirect API
PAYDIRECT_BASE_URL=https://www.paydirect.com
PAYDIRECT_ADMIN_SECRET=<your admin API secret>

# Liquidity Workspace (holds token reserve)
LIQUIDITY_WORKSPACE_ID=<workspace id>
LIQUIDITY_API_KEY=<pd_live_... key>
LIQUIDITY_WALLET=<smart wallet 0x address>

# Revenue Workspace (receives platform fees)
REVENUE_WORKSPACE_ID=<workspace id>
REVENUE_API_KEY=<pd_live_... key>
REVENUE_WALLET=<smart wallet 0x address>

# Token config
ADAO_TOKEN_ADDRESS=0x1ef7Be0aBff7d1490e952eC1C7476443A66d6b72
Step 2
User Onboarding
Provision a workspace + smart wallet when each user signs up
async function onUserSignUp(user: { name: string; email: string }) {
  // 1. Create PayDirect workspace
  const wsRes = await fetch(`${PAYDIRECT_URL}/api/v1/workspaces`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "Authorization": `Bearer ${ADMIN_SECRET}`,
    },
    body: JSON.stringify({
      name: `User — ${user.email}`,
      ownerEmail: user.email,
      platform: "yourplatform",
      webhookUrl: "https://yourplatform.com/api/webhooks/paydirect",
    }),
  });
  const { workspaceId, walletAddress, apiKeys } = await wsRes.json();

  // 2. Create smart wallet (gasless) + set as default
  const swRes = await fetch(
    `${PAYDIRECT_URL}/api/v1/workspaces/${workspaceId}/smart-wallet`,
    {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "Authorization": `Bearer ${ADMIN_SECRET}`,
      },
      body: JSON.stringify({ setDefault: true }),
    }
  );
  const { smartWallet } = await swRes.json();

  // 3. Store credentials in your database
  await db.users.update(user.id, {
    paydirectWorkspaceId: workspaceId,
    paydirectApiKey: apiKeys.live,
    walletAddress: smartWallet.address,
  });

  return smartWallet.address;
}

Two API calls per user: One to create the workspace (returns API keys), one to enable the smart wallet (returns wallet address). Both are idempotent.

Step 3
OTC Token Swap
Users pay USDC/ETH, receive ADAO from your liquidity pool
User clicks "Buy 500 ADAO" ($2.50 USDC)
    │
    ├─ Leg 1: DEBIT user
    │   POST /api/v1/payouts (user's API key)
    │   → $2.50 USDC from User Wallet → Revenue Wallet
    │
    ├─ Leg 2: CREDIT user
    │   POST /api/v1/payouts (liquidity API key)
    │   → 500 ADAO from Liquidity Wallet → User Wallet
    │
    └─ Leg 3: SETTLEMENT (automatic)
        Revenue Workspace forwards USDC → Your Treasury
        (PayDirect takes 1.5% settlement fee on USDC for Free tier)
async function buyTokens(userId: string, adaoAmount: number) {
  const user = await db.users.findById(userId);
  const usdcCost = (adaoAmount * ADAO_PRICE_USD).toFixed(2);

  // Leg 1: Debit USDC from user → revenue wallet
  await fetch(`${PAYDIRECT_URL}/api/v1/payouts`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "Authorization": `Bearer ${user.paydirectApiKey}`,
    },
    body: JSON.stringify({
      tokenSymbol: "USDC",
      amount: usdcCost,
      destinationAddress: REVENUE_WALLET,
      walletType: "smart_wallet",
      idempotencyKey: `swap-${userId}-${Date.now()}-debit`,
    }),
  });

  // Leg 2: Credit ADAO from liquidity → user wallet
  await fetch(`${PAYDIRECT_URL}/api/v1/payouts`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "Authorization": `Bearer ${LIQUIDITY_API_KEY}`,
    },
    body: JSON.stringify({
      tokenSymbol: "ADAO",
      amount: String(adaoAmount),
      destinationAddress: user.walletAddress,
      walletType: "smart_wallet",
      idempotencyKey: `swap-${userId}-${Date.now()}-credit`,
    }),
  });
}
Step 4
Recurring Billing
Monthly subscription debits from user wallets

No built-in subscriptions: PayDirect does not have a native recurring payment engine. Implement billing as a cron job on your backend that calls the payouts API monthly.

// Cron job: runs monthly (or daily to check due dates)
async function processSubscriptions() {
  const due = await db.subscriptions.findDue(); // WHERE next_billing_at <= NOW()

  for (const sub of due) {
    const user = await db.users.findById(sub.userId);

    // Check balance first
    const balRes = await fetch(`${PAYDIRECT_URL}/api/v1/wallet/balance`, {
      headers: { "Authorization": `Bearer ${user.paydirectApiKey}` },
    });
    const balance = await balRes.json();
    const adaoBalance = parseFloat(balance.smartWallet?.adao || balance.adao || "0");

    if (adaoBalance < sub.totalCost) {
      await db.subscriptions.pause(sub.id);
      await notifyUser(user, "Insufficient ADAO balance");
      continue;
    }

    // Pay agent (95%)
    const agentAmount = (sub.totalCost * 0.95).toFixed(4);
    await fetch(`${PAYDIRECT_URL}/api/v1/payouts`, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "Authorization": `Bearer ${user.paydirectApiKey}`,
      },
      body: JSON.stringify({
        tokenSymbol: "ADAO",
        amount: agentAmount,
        destinationAddress: sub.agentWalletAddress,
        walletType: "smart_wallet",
        idempotencyKey: `sub-${sub.id}-${sub.period}-agent`,
      }),
    });

    // Platform fee (5%)
    const feeAmount = (sub.totalCost * 0.05).toFixed(4);
    await fetch(`${PAYDIRECT_URL}/api/v1/payouts`, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "Authorization": `Bearer ${user.paydirectApiKey}`,
      },
      body: JSON.stringify({
        tokenSymbol: "ADAO",
        amount: feeAmount,
        destinationAddress: REVENUE_WALLET,
        walletType: "smart_wallet",
        idempotencyKey: `sub-${sub.id}-${sub.period}-fee`,
      }),
    });

    await db.subscriptions.markBilled(sub.id);
  }
}
Step 5
Balance Queries & Monitoring
Check wallet balances and listen for events
// Check a user's balance
const res = await fetch(`${PAYDIRECT_URL}/api/v1/wallet/balance`, {
  headers: { "Authorization": `Bearer ${user.paydirectApiKey}` },
});
const balance = await res.json();

// Response:
// {
//   "address": "0xEOA...",
//   "eth": "0.001",
//   "usdc": "50.00",
//   "adao": "10000.00",
//   "smartWallet": {
//     "address": "0xSmartWallet...",
//     "eth": "0.00",
//     "usdc": "25.00",
//     "adao": "5000.00"
//   },
//   "defaultWalletType": "smart_wallet"
// }
API Endpoints Used
All endpoints a platform integration typically needs

Workspace Management (admin auth)

POST
/api/v1/workspaces
POST
/api/v1/workspaces/:id/smart-wallet
GET
/api/v1/workspaces/:id/smart-wallet

Transfers (workspace API key auth)

POST
/api/v1/payouts
GET
/api/v1/wallet/balance
GET
/api/v1/payouts

Webhooks

POST
/api/v1/webhooks
Fee Model for Platforms
What PayDirect charges vs what you control
TransactionPayDirect FeeNotes
Payout (wallet → wallet)
0%
Direct transfers via /api/v1/payouts have no fee
Settlement forwarding (USDC)
1.5% Free / 1.0% Pro / 0.5% Enterprise
When revenue workspace forwards to your treasury
Settlement forwarding (ETH)
1.5% Free / 1.0% Pro / 0.5% Enterprise
When revenue workspace forwards to your treasury
Settlement forwarding (ADAO)
0.75% Free / 0.5% Pro / 0.25% Enterprise
Discounted rate for ADAO
Smart wallet creation
Free
No cost to create wallets
Gas (smart wallet)
Sponsored
CDP Paymaster covers gas for smart wallet transactions
Webhook Events
Events fired by PayDirect that your platform should handle
EventWhen
payout.completedToken transfer succeeded
payout.failedToken transfer failed
payment.detectedIncoming deposit detected on-chain
payment.confirmedBlock confirmations met
payment.forwardedSettlement forwarded to merchant
payment.failedSettlement failed

All webhooks include an X-PayDirect-Signature HMAC-SHA256 header for verification. See the Webhooks docs for details.

Rate Limits
Per API key, sliding window
PlanLimitNotes
Free100 req/minPer API key
Pro1,000 req/minPer API key

Each workspace gets its own API key with its own rate limit bucket. Admin secret requests are not rate-limited. Workspace creation has no explicit limit but should be staggered for best performance.