Paypal P2P 支付 API
Posted
技术标签:
【中文标题】Paypal P2P 支付 API【英文标题】:Paypal P2P payments API 【发布时间】:2020-08-10 18:33:18 【问题描述】:我想构建一个 web 应用程序,用户可以通过他们的 paypal 帐户向其他用户付款。
我想要的是类似于这样的东西: https://developer.paypal.com/demo/checkout/#/pattern/client
用户可以点击按钮以使用 Paypal 或信用卡付款的页面,其他用户。 但我看不出在这个例子中如何配置接收者帐户。付款似乎是我的帐户,但我希望付款给他选择的另一个用户。
我还查看了所有这些 API: https://developer.paypal.com/docs/api/rest-sdks/# 但我无法找到允许构建用户向另一个用户付款的客户端的示例。当然,我需要确认付款已完成。
编辑:
我已经尝试过这里的代码:https://www.npmjs.com/package/@paypal/checkout-server-sdk
并更新添加收款人字段:
exports.pay = function (req, res)
// 1. Set up your server to make calls to PayPal
// 1a. Import the SDK package
const paypal = require('@paypal/checkout-server-sdk');
// 1b. Add your client ID and secret
const PAYPAL_CLIENT = 'xxx';
const PAYPAL_SECRET = 'yyy';
// 1c. Set up the SDK client
const env = new paypal.core.SandboxEnvironment(PAYPAL_CLIENT, PAYPAL_SECRET);
const client = new paypal.core.PayPalHttpClient(env);
// 2. Set up your server to receive a call from the client
// 3. Call PayPal to set up a transaction with payee
const request = new paypal.orders.OrdersCreateRequest();
request.requestBody(
"intent": "CAPTURE",
"purchase_units": [
"amount":
"currency_code": "USD",
"value": "100.00"
,
"payee":
"email_address": "payee@gmail.com"
]
);
const createOrder = async function ()
const response = await client.execute(request);
console.log(`Response: $JSON.stringify(response)`);
// If call returns body in response, you can get the deserialized version from the result attribute of the response.
console.log(`Order: $JSON.stringify(response.result)`);
return res.status(200).json(response.result);
;
createOrder();
;
这将返回一个包含 4 个链接的列表。第二个似乎是将客户端重定向到(https://www.sandbox.paypal.com/checkoutnow?token=9RM83779YH010823U)的那个。但是如果我去那里,我仍然无法在“发送到”中看到收款人地址(payee@gmail.com)。
【问题讨论】:
【参考方案1】:你想要的是设置一个payee
对象:https://developer.paypal.com/docs/checkout/integration-features/custom-payee/
【讨论】:
我试过了,但是如果我在示例中添加收款人字段,它似乎没有做任何事情。 Paypal 模式中的“发送至”字段未显示指定的收款人 该字段在按照文档正确使用时有效。不正确的用法会被忽略。 我已经用一些代码更新了问题以帮助重现问题 它可以正常工作。我不知道你在抱怨什么。 我已经创建了示例jsfiddle.net/25q1L7ju ...并且...它可以工作...从用户A到用户B的交易成功进行。这个小提琴和我的唯一区别本地实例是收款人未显示在贝宝确认窗口的最顶部。我认为它应该出现在某个地方,以便付款人确定他向谁付款。不应该吗?以上是关于Paypal P2P 支付 API的主要内容,如果未能解决你的问题,请参考以下文章
自适应支付 paypal - 没有支付 api 操作的 pdt 数据
使用 paypal 自适应支付 api 如何将支付类型设置为个人?