【发布时间】: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)。
【问题讨论】: