【问题标题】:Showing paypal transaction details after payment付款后显示贝宝交易详情
【发布时间】:2018-08-03 11:56:47
【问题描述】:

在我的网站上使用 Paypal 成功付款后,浏览器只显示警报:

// Execute the payment
  onAuthorize: function (data, actions) {
    return actions.payment.execute()
      .then(function () {
        // Show a confirmation message to the buyer

        window.alert('Compra realizada con éxito. Recibirá más detalles por email!');

      });
  }

我现在正在使用沙盒选项,但我知道如何向用户提供有关交易的更多详细信息。

我看到函数中有一个“数据”参数,有交易详情吗?如果是,我如何阅读它们以便稍后向用户展示?

【问题讨论】:

    标签: javascript ajax paypal-sandbox


    【解决方案1】:

    操作的结果被传递给回调函数,可以这样访问:

    .then( function(result) {
            console.log(result); // Logs all the stuff that gets back from Paypal
    });
    

    根据the doc

    // Execute the payment:
        // 1. Add an onAuthorize callback
        onAuthorize: function(data, actions) {
          // 2. Make a request to your server
          return actions.request.post('/my-api/execute-payment/', {
            paymentID: data.paymentID,
            payerID:   data.payerID
          })
            .then(function(res) {
              // 3. Show the buyer a confirmation message.
            });
        }
    

    【讨论】:

    • 我没有使用服务器端进行付款
    • 是的,你是对的,但是在你回答的第二部分中,有一个对服务器端的调用
    • 这只是从文档中复制粘贴。让它适应你的代码,当然
    【解决方案2】:

    成功的响应返回交易确认,带有已批准的状态和交易ID,或者您可以看到here

        // Wait for the payment to be authorized by the customer
    
     onAuthorize: function(data, actions) {
    
        // Get the payment details
    
        return actions.payment.get().then(function(data) {
    
            // Display the payment details and a confirmation button
    
            var shipping = data.payer.payer_info.shipping_address;
    
               // Execute the payment
    
                return actions.payment.execute().then(function() {
    
                    // Show a thank-you note
       window.alert('Compra realizada con éxito. Recibirá más detalles por email!');
                });
            });
        });
    }
    

    【讨论】:

    • data.payer.payer_info.shipping_address /v1/payments 端点已弃用。改用 /v2/payments 端点
    猜你喜欢
    • 2013-04-26
    • 2012-07-12
    • 1970-01-01
    • 2012-08-17
    • 2015-12-21
    • 2014-06-13
    • 2011-07-25
    • 2015-05-27
    • 2016-06-17
    相关资源
    最近更新 更多