如何批准创建订单响应中的贝宝批准链接?
Posted
技术标签:
【中文标题】如何批准创建订单响应中的贝宝批准链接?【英文标题】:How to approve the paypal approval link in the create order response? 【发布时间】:2020-06-23 02:09:07 【问题描述】:我在服务器端(nodejs)创建了 paypal 的 OrderCreateRequest,并且我有批准链接“https://www.sandbox.paypal.com/checkoutnow?token=88K34845N63744150”。我需要批准此批准链接。我该怎么做?我的客户端是 Reactjs。我所拥有的是:
服务器端
payment.js
import paypal from "@paypal/checkout-server-sdk";
const clientId = "CLIENT_ID";
const clientSecret = "SECRET";
const environment = new paypal.core.SandboxEnvironment(clientId, clientSecret);
const client = new paypal.core.PayPalHttpClient(environment);
export const processInvoicePaypalPayment = async (user, data) =>
let request = new paypal.orders.OrdersCreateRequest();
try
request.body =
intent: "CAPTURE",
redirect_urls:
return_url: "http://localhost:3000",
cancel_url: "http://localhost:3000"
,
purchase_units: [
amount:
currency_code: "USD",
value: "**AMOUNT***"
,
description: "This is the payment transaction description."
];
const createOrder = async () =>
const response = await client.execute(request);
console.log(`Order: $JSON.stringify(response.result)`);// This response.result.links contain approval links
return ok: true, data: payment: response.result ;
const result = await createOrder();
return result;
catch(err)
客户端(反应 js)
test.js
onSuccess = (paymt, details) =>
const
payment, // This contained the data which retured from server ie links
processInvoicePaypalPayment
= this.props;
let links = ;
payment.paypalDetails.payment.links.forEach(linkObj =>
links[linkObj.rel] =
href: linkObj.href,
method: linkObj.method
;
);
if (links.approve)
window.open(links.approve.href, "windowName", "height=400,width=400"); // Here i try to approve that approval link.
由于我对此比较陌生,因此我担心这是批准链接的正确方法。如果不是我怎么能做到这一点?以这种打开新弹出窗口的方式实际上给了我,在我登录和支付过程完成后,它不会重定向回我的网站。我得到的是:
我该如何解决这个问题?
【问题讨论】:
【参考方案1】:最好的方法是将 orderID/令牌传递给 PayPal Checkout 集成的客户端 UI:https://developer.paypal.com/docs/checkout/
这是一个演示模式:https://developer.paypal.com/demo/checkout/#/pattern/server
作为画龙点睛的一笔,一旦一切顺利,不要忽视处理/传播资金失败,以便在付款捕获/执行失败时买家可以选择不同的资金(例如,如果他们的第一张卡被拒绝) ):https://developer.paypal.com/docs/checkout/integration-features/funding-failure/
【讨论】:
以上是关于如何批准创建订单响应中的贝宝批准链接?的主要内容,如果未能解决你的问题,请参考以下文章