【问题标题】:paypal: How to get order id and pass to transaction details pagepaypal:如何获取订单 ID 并传递到交易详情页面
【发布时间】:2020-06-20 12:53:43
【问题描述】:

我是 PayPal 集成的新手。我需要获取订单 ID 以获取交易详情,并希望在另一个页面上向客户显示交易详情。

以下是 javascript 代码。以下代码显示 OrderId = 0。

     <script>
 paypal.Buttons({
     createOrder: function (data, actions) {
         // This function sets up the details of the transaction, including the amount and line item details.
         return actions.order.create({
            application_context: {
                return_url: 'https://example.com',
                cancel_url: 'https://example.com'
            },
             purchase_units: [{
                 amount: {
                     currency_code: 'USD',
                     value: '<%=bookingAmount%>'
                 }
             }]
         });
     },

    onApprove: function (data, actions) {
        // Capture the transaction funds
        return actions.order.capture().then(function () {
            // Show a confirmation to the buyer
            alert('Transaction complete!' & data.orderID);
        });
    }

}).render('#paypal-button-container');   //This function displays Smart Payment Buttons on your web page. 
    </script>

问题:上面的代码不能按要求工作。如何解决?

【问题讨论】:

  • console.log(data);

标签: javascript paypal-sandbox


【解决方案1】:

使用以下代码行,我能够检索交易的详细信息。 -

“返回actions.order.capture().then(函数(详情)”

以下是完整的运行代码——

paypal.Buttons({
    createOrder: function (data, actions) {
        // This function sets up the details of the transaction, including the amount and line item details.
        return actions.order.create({
            purchase_units: [{
                amount: {
                    currency_code: 'USD',
                    value: '<%=bookingAmount%>'
                }
            }]
        });
    },
    onApprove: function (data, actions) {
        // Capture the transaction funds
        return actions.order.capture().then(function (details) {
            console.log(JSON.stringify(details));
        });
    }
}).render('#paypal-button-container');

【讨论】:

  • 请我使用 Angular 并且我已将此脚本与 component.ts 集成我想保留此返回的订单 ID,但我无法在 OnApprove 函数中访问我的 service.ts 变量
  • 我在我的 .NET 应用程序中使用上面的代码。对于 Angular 应用程序,尝试从 service.ts 中“导入”变量
  • 诀窍是像这样使用 ngZone link 这很有帮助
猜你喜欢
  • 2018-12-20
  • 2021-05-30
  • 2014-07-20
  • 2013-12-26
  • 2023-03-13
  • 1970-01-01
  • 2019-10-11
  • 2023-03-27
  • 2016-09-12
相关资源
最近更新 更多