简体   繁体   中英

PayPal Smart Button - How To Edit Redirect Url

I am trying to input a redirect url link in my PayPal smart button generated code and don't know how to do that. I am hoping that I will get help here please.

I want to be able to redirect customers to eg ( https://www.example.com/request/ ) after a successful payment.

Below is the smart button code from Paypal:

function initPayPalButton() { paypal.Buttons({ style: { shape: 'rect', color: 'gold', layout: 'vertical', label: 'paypal',
},

createOrder: function(data, actions) {
  return actions.order.create({
    purchase_units: [{"description":"Digital Service","amount":{"currency_code":"USD","value":1}}]
  });
},

onApprove: function(data, actions) {
  return actions.order.capture().then(function(orderData) {

    // Full available details
    console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));

    // Show a success message within this page, e.g.
    const element = document.getElementById('paypal-button-container');
    element.innerHTML = '';
    element.innerHTML = '<h3>Thank you for your payment!</h3>';

    // Or go to another URL:  actions.redirect('thank_you.html');

  });
},

onError: function(err) {
  console.log(err);
}
}).render('#paypal-button-container');
}
initPayPalButton();

You need to comment out the first part, and uncomment the second part, like so:

// Show a success message within this page, e.g.
// const element = document.getElementById('paypal-button-container');
// element.innerHTML = '';
// element.innerHTML = '<h3>Thank you for your payment!</h3>';

// Or go to another URL:
actions.redirect('https://www.example.com/thankyou/');

// Or go to another URL: actions.redirect('thank_you.html');

您的问题的答案在代码示例中,就在这里。

function redirect(url){
  window.setTimeout(function(){
      window.location.href = url;
  }, 300);
}
<button onclick="redirect("https://www.google.com")">Redirect</button>

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