繁体   English   中英

如何批准创建订单响应中的贝宝批准链接?

[英]How to approve the paypal approval link in the create order response?

我在服务器端(nodejs)创建了 paypal 的 OrderCreateRequest,并且我有批准链接“ https://www.sandbox.paypal.com/checkoutnow?token=88K34845N63744150 ”。 我需要批准此批准链接。 我该怎么做? 我的客户端是 Reactjs。 我所拥有的是:

服务器端

付款.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)

测试.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.
  }

}

由于我对此较新,因此我担心这是批准链接的正确方法。 如果不是,我怎么能做到这一点? 以这种打开新弹出窗口的方式实际上给了我这样的信息,在我登录和付款过程完成后,它不会重定向回我的网站。 我得到的是:

在此处输入图片说明

我该如何解决这个问题?

最好的方法是将订单 ID/令牌传递给 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/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM