Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
488 views
in Technique[技术] by (71.8m points)

javascript - 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

question from:https://stackoverflow.com/questions/65831161/paypal-smart-button-how-to-redirect-to-a-php-page-after-successfull-payment

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...