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

巴基斯坦地区如何测试Node.js集成的PayPal Payout API?

解决巴基斯坦地区测试PayPal Payout API的方案

一、用PayPal沙箱(Sandbox)环境完成测试

PayPal沙箱是官方提供的隔离测试环境,无需真实银行账户、SNS信息,完全适配你的测试需求:

  • 注册全球通用的PayPal开发者账号,不受地区PayPal服务限制
  • 创建沙箱测试账户:
    • 登录开发者平台后,进入Sandbox > Accounts页面
    • 创建两类测试账户:1个**Business(商家)账户(作为转账发起方),1个Personal(个人)**账户(作为收款方)
    • 每个沙箱账户的Email地址就是你需要的paypalID(接收方标识),也可在账户详情页查看完整账户ID

二、调整Node.js代码适配沙箱环境

确保PayPal SDK配置为沙箱模式,同时优化异步逻辑写法:

const paypal = require('@paypal/checkout-server-sdk');

// 沙箱环境客户端配置
const environment = new paypal.core.SandboxEnvironment(
  '你的沙箱客户端ID',
  '你的沙箱客户端密钥'
);
const client = new paypal.core.PayPalHttpClient(environment);

// 优化后的异步处理逻辑
const paypalPayouts = async (req, res) => {
  const { paypalID, amount, currency, note } = req.body;

  if (!paypalID || !amount || !currency) {
    return res
      .status(400)
      .json({ message: "paypalID, amount, and currency are required" });
  }

  const payout = {
    sender_batch_header: {
      // 建议用业务唯一标识,比如订单前缀+时间戳,避免重复
      sender_batch_id: `Payout_${Date.now()}_${Math.random().toString(36).substring(9)}`,
      email_subject: "You have a payout!",
      email_message: "You have received a payout! Thanks for using our paypal payout service!!",
    },
    items: [
      {
        recipient_type: "PAYPAL_ID",
        amount: {
          value: amount,
          currency: currency,
        },
        receiver: paypalID,
        note: note || "Thank you.",
        sender_item_id: `Item_${Date.now()}_${Math.random().toString(36).substring(9)}`,
      },
    ],
  };

  try {
    const payoutResponse = await client.execute(new paypal.payouts.PayoutsCreateRequest().requestBody(payout));
    console.log("paypal Payout response=>", payoutResponse);
    return res
      .status(200)
      .json({ message: "Payout created successfully", payout: payoutResponse });
  } catch (error) {
    console.error(error);
    return res
      .status(500)
      .json({ message: "Error creating payout", error: error.response?.data || error.message });
  }
};

三、验证测试结果

  • 发起测试请求后,可在开发者平台Sandbox > Activity页面查看转账记录
  • 用沙箱个人账户的邮箱和密码(在Sandbox Accounts页的Profile中查看)登录沙箱前台,能直接看到收款明细

内容的提问来源于stack exchange,提问作者حمزہ لیاقت

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 06:22:08