【问题标题】:How to get IPN status after success full payment in paypal express checkout using checkout.js使用 checkout.js 在贝宝快速结帐中成功全额付款后如何获取 IPN 状态
【发布时间】:2017-07-04 12:30:01
【问题描述】:

我已经实施了新的贝宝快速结账。我想将我的 success_ipn.php URL 和 cancelled.php URL 传递给 checkout.js。

我做了很多谷歌和官方文档Paypal DOC

下面是我的文件代码:

<!DOCTYPE html>

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <script src="https://www.paypalobjects.com/api/checkout.js"></script>
</head>

<body>
    <div id="paypal-button-container"></div>

    <script>
        var EXECUTE_PAYMENT_URL = 'http://example.com/success_ipn.php';
        paypal.Button.render({

            env: 'sandbox', // sandbox | production

            // PayPal Client IDs - replace with your own
            // Create a PayPal app: https://developer.paypal.com/developer/applications/create
            client: {
                sandbox:    'My Sandbox Client ID here.',
                //production: '<insert production client id>'
            },

            // Show the buyer a 'Pay Now' button in the checkout flow
            commit: true,

            // payment() is called when the button is clicked
            payment: function(data, actions) {

                // Make a call to the REST api to create the payment
                return actions.payment.create({
                    payment: {
                        transactions: [
                            {
                                amount: { total: '0.01', currency: 'USD' }
                            }
                        ]
                    }
                });
            },

            // onAuthorize() is called when the buyer approves the payment
            onAuthorize: function(data, actions) {
                return paypal.request.post(EXECUTE_PAYMENT_URL, {
                    paymentID: data.paymentID,
                    payerID:   data.payerID
                }).then(function() {
                        window.alert('Payment Complete!');
                });
            }

        }, '#paypal-button-container');

    </script>
</body>
</html>

它工作正常,但是我如何传递我的 IPN 文件 URL 和取消 URL。

在对此做更多的谷歌之后,我只能得到以下变量而不是交易 ID 等:

paymentID: data.paymentID,
payerID:   data.payerID

请帮帮我。

【问题讨论】:

    标签: php paypal-sandbox paypal-ipn paypal


    【解决方案1】:

    在尝试过并对此进行谷歌搜索后,我找到了解决方案。

    checckout.js 最新版本之后,贝宝已弃用 Express Checkout - NVP/SOAP。因此,GetExpressCheckoutDetailsDoExpressCheckoutPayment 也已被弃用。

    现在,所有工作都将在 Rest API 上完成。

    以下是更新代码,我们如何以 json 格式获取付款人信息和交易详细信息。得到 json 响应后,我们也可以使用 aJax 更新我们的数据库记录。

    <script src="https://www.paypalobjects.com/api/checkout.js"></script>
      <div id="paypal-button-container"></div>
    
    <script>
      var EXECUTE_PAYMENT_URL = 'http://example.com/success_checkout.php';
    
      paypal.Button.render({
    
          env: 'sandbox', // sandbox | production
    
          // PayPal Client IDs - replace with your own
          // Create a PayPal app: https://developer.paypal.com/developer/applications/create
          client: {
              sandbox:    '',
              //production: '<insert production client id>'
          },
    
          // Show the buyer a 'Pay Now' button in the checkout flow
          commit: true,
    
          // payment() is called when the button is clicked
          payment: function(data, actions) {
    
              // Make a call to the REST api to create the payment
              return actions.payment.create({
                  payment: {
                      transactions: [
                          {
                              amount: { total: '10', currency: 'USD' },
                              custom: 'custom value here'
                          }
                      ]
                  }
              });
          },
          onAuthorize: function(data, actions) {
            return actions.payment.get().then(function(payment) {
                //debugger;
                console.log(payment);
                var txn_id = payment.cart;
                var bookID = payment.transactions[0].custom;
                var currency = payment.transactions[0].amount["currency"];
                var amount = payment.transactions[0].amount["total"];
                var payerID = payment.payer.payer_info["payer_id"];
                var pstatus = payment.payer.status;
    
                var successUrl = EXECUTE_PAYMENT_URL+'?txn_id='+txn_id+'&bookID='+bookID+'&currency='+currency+'&amount='+amount+'&payerID='+payerID+'&pstatus='+pstatus;
                //console.log(newUrl);
               window.location.replace(successUrl);
            });
          },
          onCancel: function(data, actions) {
            var cancelUrl = "http://example.com/cancelled.php";
            //console.log(newUrl);
            window.location.replace(cancelUrl);
          }    
    
      }, '#paypal-button-container');
    
    </script>
    

    您将在 success_checkout.php 中得到响应,如下所示:

    <?php
    echo '<pre>' print_r($_REQUEST); 
    
    // do your stuff here
    
    header('Location: thanks.php');
    ?>
    

    希望这对其他开发者有所帮助。

    【讨论】:

      猜你喜欢
      • 2013-12-11
      • 2015-05-03
      • 2016-05-27
      • 2011-10-18
      • 1970-01-01
      • 2015-06-09
      • 2018-11-24
      • 1970-01-01
      • 2016-10-01
      相关资源
      最近更新 更多