简体   繁体   English

如何在PayPal Javascript代码中使用PHP header()函数

[英]How can use PHP header() function inside PayPal Javascript code

I am trying to integrate Paypal with my website and now am facing problem to actually handle different messages sent by paypal like success, failed, cancelled and all 我正在尝试将Paypal与我的网站集成,现在正面临实际处理Paypal发送的不同消息(例如成功,失败,已取消等)的问题

I am pasting a small part of the paypal JS code where it handles the messages below 我将Paypal JS代码的一小部分粘贴到其中,用于处理以下消息

onAuthorize: function (data, actions) {
            return actions.payment.execute()
              .then(function (res2) {
                // Show a confirmation message to the buyer
                console.log(res2);
                console.log(res2.transactions[0].related_resources[0].sale.state);
                //state codes - completed, partially_refunded, pending, refunded, denied
                if(res2.transactions[0].related_resources[0].sale.state == 'completed'){

            //  alert("Payment received for the invoice number" + res2.transactions[0].invoice_number); 

                }   
              });
          },
          onCancel: function (data, actions) {
            // Show a cancel page or return to cart

            alert("Payment  cancelled");
          },
           onError: function (err) {
            // Show an error page here, when an error occurs

            alert("Payment  error");
          }

Now what I want is, Whenever the payment is "completed" i want php to append to URL something like 现在我想要的是,每当付款“完成”时,我都希望php将类似以下内容的内容附加到URL

order-placed.php?completed&invoice=$invoiceNumber

I tried placing PHP inside the JS code just above the Paypal alert messages but when i tried loading the page, It says "This page isn't working localhost redirected you too many times." 我尝试将PHP放在Paypal警报消息上方的JS代码中,但是当我尝试加载该页面时,它显示“此页面无法正常运行,localhost重定向了您太多次。” Can anyone guide me on this please? 有人可以指导我吗? Is there an alternative way in which i can handle different payment status messages? 有没有其他方法可以处理不同的付款状态消息? Thanks in advance 提前致谢

Don't use PHP header function inside the javascript code because that will not work.you can redirect your page via below code in javascript. 不要在javascript代码内使用PHP标头函数,因为这将无法正常工作。您可以通过以下javascript代码重定向页面。

location.href = 'http://youdomain.com/order-placed.php?completed&invoice=<?php echo $invoiceNumber ?>';

Hope this helps you. 希望这对您有所帮助。

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

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