简体   繁体   中英

Paypal Smart Button: how to redirect to a PHP page after successfull payment?

I'm trying to integrate paypal payment into my web site.

EDIT:

After a sucessfull payment I want to redirect to a PHP page to manipulate payment data, for instance: Saving to db transaction and payment id, payer email, send email etc.

So this is my "onApprove" function:

onApprove: function(data, actions) {

  var EXECUTE_URL = 'https://www.mywebsite.com/actions/paymentsuccess.php';

  return fetch(EXECUTE_URL, {
    method: 'post',
    headers: {
      'content-type': 'application/json'
    },
    body: JSON.stringify({
      paymentID: data.paymentID,
      payerID: data.payerID,
      payerEmail: data.payerEmail,
      payerName: data.payerName,
      payerPhone: data.payerPhone
    })
  });
},

How to call a PHP page (maybe with a POST ) and pass all payment data, and elaborate that page (i don't need to stay to the payment page)?

Thanks

If you need to do something , you should do it inside the 'EXECUTE_URL' on your server (or with more current integrations, a capture URL) This is where any important business task should be done.

But if you want to then redirect the user some resulting point (not to "do something"), this should take place after the fetch, and only if the fetch is successful. You will need to add a JS redirect yourself.


So basically, add .then() code that deals with the fetch's response.

For current integrations (which use a capture, not an execute), here is an example implementation that parses a fetch response: https://developer.paypal.com/demo/checkout/#/pattern/server

if by the way you are using paypal sdk then you should really follow the documentation about confirmation page and present the user info that you want on the same page that already has the paypal's sdk objects loaded

onApprove: function (data, actions) {

    // Get the order details
    return actions.order.get().then(function (orderDetails) {

      // Show a confirmation using the details from orderDetails
      // Then listen for a click on your confirm button

      document.querySelector('#confirm-button')
        .addEventListener('click', function () {

          // Capture the transaction funds
          return actions.order.capture().then(function () {
            // Show a confirmation to the buyer
          });
        });
      });
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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