跳转到主要内容

前提条件

创建付款之前,您需要:
  1. 预存账户 — 通过 POST /api/v2/customers/pre-fund/create 创建
  2. 足够的余额 — 通过 GET /api/v2/customers/balances 验证
  3. 收款方详情 — 收款人的银行账户、钱包地址或支付别名

设置预存账户

还没有预存账户?从这里开始。

完整付款流程

1

检查可用余额

在提交付款前确认有足够资金。
GET /api/v2/customers/balances
响应
[
  {
    "id": "balance-id",
    "currency": "COP",
    "amount": "10000000.00",
    "accountId": "prefund-account-id"
  }
]
2

创建付款

提交包含预存账户、金额和收款方的付款请求。
POST /api/v2/payouts
3

跟踪状态

轮询付款或监听 webhooks,直到达到终态(COMPLETEDERRORFAILEDREJECTEDREFUNDED)。

实现示例

curl -X POST https://sandbox.killb.app/api/v2/payouts \
  -H "Authorization: Bearer 您的TOKEN" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: payout-2024-001" \
  -d '{
    "preFundAccountId": "prefund-account-id",
    "amount": 500000,
    "externalId": "payout-2024-001",
    "beneficiary": {
      "type": "PSE",
      "account": {
        "firstName": "Maria",
        "lastName": "Garcia",
        "email": "[email protected]",
        "phone": "3001234567",
        "document": { "type": "CC", "number": "12345678" },
        "accountNumber": "123456789",
        "bankCode": "001",
        "type": "savings",
        "countryCode": "CO"
      }
    }
  }'
响应:
{
  "id": "payout-abc123",
  "amount": 500000,
  "currency": "COP",
  "status": "PENDING",
  "externalId": "payout-2024-001",
  "beneficiary": {
    "type": "PSE",
    "account": { ... }
  },
  "createdAt": "2024-01-15T10:30:00.000Z",
  "updatedAt": "2024-01-15T10:30:00.000Z"
}

收款方类型

通过 PSE 系统进行标准哥伦比亚银行账户转账。
{
  "type": "PSE",
  "account": {
    "firstName": "Maria",
    "lastName": "Garcia",
    "email": "[email protected]",
    "phone": "3001234567",
    "document": {
      "type": "CC",
      "number": "12345678"
    },
    "accountNumber": "123456789",
    "bankCode": "001",
    "type": "savings",
    "countryCode": "CO"
  }
}
必填字段: firstNamecompanyNamelastNameemailphonedocumentaccountNumberbankCodetypecountryCode使用 GET /api/v2/banks 查询有效的 bankCode 值。

付款前检查余额

在发送大额付款之前,始终验证可用余额:
const checkBalance = async (preFundAccountId, requiredAmount) => {
  const balances = await fetch('/api/v2/customers/balances', {
    headers: { 'Authorization': `Bearer ${token}` }
  }).then(r => r.json());

  const account = balances.find(b => b.accountId === preFundAccountId);

  if (!account || parseFloat(account.amount) < requiredAmount) {
    throw new Error(
      `余额不足。可用: ${account?.amount ?? 0},需要: ${requiredAmount}`
    );
  }

  return account;
};

幂等性

为防止网络重试时产生重复付款,每次创建付款请求时请传入唯一的 Idempotency-Key 请求头。如果相同的 key 被接收两次,KillB 将返回原始付款而不是创建新记录。
Idempotency-Key: <您的唯一付款参>
使用稳定唯一的标识符作为 key——您的内部付款 ID 或与业务交易绑定的 UUID 都是好的选择。

查询付款列表

使用可选筛选条件获取所有付款记录:
const listPayouts = async ({ status, externalId, page = 1, limit = 20 } = {}) => {
  const params = new URLSearchParams({ page, limit });
  if (status) params.set('status', status);
  if (externalId) params.set('externalId', externalId);

  const response = await fetch(
    `https://sandbox.killb.app/api/v2/payouts?${params}`,
    { headers: { 'Authorization': `Bearer ${token}` } }
  );

  return response.json(); // { payouts: [...], totalPage: N }
};

// 获取所有待处理的付款
const pending = await listPayouts({ status: 'PENDING' });

下一步

状态跟踪

通过轮询和 webhooks 监控付款

配置 Webhooks

配置 PAYOUT webhook 通知