You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native集成PayPal Payout遭遇400错误求助

PayPal Payout沙箱400错误排查方案

首先得拿到具体的错误详情,你现在的代码只打印了状态码,根本没法定位问题。修改else分支,把PayPal返回的错误信息打出来:

} else {
  const errorData = await response.json();
  console.log('Payout failed. Status:', response.status);
  console.log('Error details:', errorData); // 关键:打印具体错误内容
}

拿到详情后,对照下面的常见问题逐一排查:

  • Access Token有效性问题:确认你的token是用沙箱环境的Client ID和Secret生成的,且拥有payouts权限。可以去PayPal开发者平台的API凭证页面验证,或者重新生成一次token试试。
  • Sender Batch ID重复:每次请求的sender_batch_id必须唯一,你现在用的固定值Payouts_2020_100007,重复调用肯定会报错。改成动态生成的,比如:
    "sender_batch_id": "Payouts_" + Date.now(),
    
  • 接收方不是沙箱测试账号:沙箱环境不能用真实邮箱(哪怕是朋友的gmail),必须用PayPal开发者平台创建的沙箱个人测试账号的邮箱。去开发者后台的Sandbox Accounts里新建一个Personal类型的测试账号,用它的邮箱作为receiver值。
  • 币种支持问题:确认PHP是否在PayPal Payout沙箱支持的币种列表里。如果不确定,可以先换成USD测试,排除币种适配问题。
  • 参数格式错误:检查amount.value是不是合法的数字格式,有没有多余字符;recipient_wallet的值RECIPIENT_SELECTED是否适用于当前币种,部分币种可能要求指定具体钱包类型。
  • 账号权限未开启:你的沙箱商家账号必须启用Payouts功能。登录PayPal开发者平台,进入对应的商家沙箱账号设置,确认Payouts权限已经开启。

修改后的示例代码(优化了sender_batch_id和错误信息打印):

const makePayout = async () => { 
    try {
      const response = await fetch('https://api-m.sandbox.paypal.com/v1/payments/payouts', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'Authorization': 'Bearer <my access token>'
        },
        body: JSON.stringify({
          "sender_batch_header": {
            "sender_batch_id": "Payouts_" + Date.now(), // 动态生成唯一ID
            "email_subject": "You have a payout!",
            "email_message": "You have received a payout! Thanks for using our service!"
          },
          "items": [
            {
              "recipient_type": "EMAIL",
              "amount": {
                "value": "10.00",
                "currency": "PHP"
              },
              "note": "Thanks for your patronage!",
              "sender_item_id": "201403140001",
              "receiver": "<沙箱测试账号邮箱>", // 替换为沙箱接收账号邮箱
              "recipient_wallet": "RECIPIENT_SELECTED"
            }
          ]
        })
      });

      if (response.ok) {
        const data = await response.json();
        console.log('Payout success:', data);
      } else {
        const errorData = await response.json();
        console.log('Payout failed. Status:', response.status);
        console.log('Error details:', errorData); // 打印具体错误
      }
    } catch (error) {
      console.error('Payout error:', error.message);
    }
  };

内容的提问来源于stack exchange,提问作者kim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 07:07:41