跳到主要内容

批量结算

通过将多笔支付聚合为批量结算来优化成本。

概述

批量结算将多笔已完成的支付合并为一笔链上交易,最高可降低 98% 的 Gas 费用。

工作原理

配置

结算计划

// 在控制台或通过 API 配置
await pelago.merchants.updateSettings({
settlementSchedule: {
mode: 'scheduled', // 'instant' | 'scheduled' | 'threshold'
frequency: 'daily', // 'hourly' | 'daily' | 'weekly'
time: '18:00', // 结算时间(UTC)
timezone: 'UTC',
minimumAmount: 100.00 // 最低批量金额
}
});

结算模式

模式描述费率
instant即时结算0.5%
scheduled按计划结算0.08%
threshold达到阈值时结算0.1%

手动批量结算

按需触发结算:

const settlement = await pelago.settlements.createBatch({
paymentIds: ['pay_abc123', 'pay_def456', 'pay_ghi789']
});

console.log('结算 ID:', settlement.id);
console.log('总额:', settlement.totalAmount);

批量报告

const batch = await pelago.settlements.retrieve('stl_abc123');

console.log('批次:', batch.id);
console.log('总额:', batch.totalAmount);
console.log('支付笔数:', batch.paymentCount);
console.log('手续费:', batch.totalFees);
console.log('交易哈希:', batch.transactionHash);

最佳实践

  1. 平衡频率与现金流 - 每日结算适合大多数商户
  2. 设置最低阈值 - 避免微额结算
  3. 监控失败结算 - 设置告警通知