简体   繁体   English

PayPal 智能按钮 - 如何编辑重定向 URL

[英]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.我正在尝试在我的 PayPal 智能按钮生成的代码中输入重定向 url 链接,但不知道该怎么做。 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.我希望能够在成功付款后将客户重定向到例如( https://www.example.com/request/ )。

Below is the smart button code from Paypal:以下是 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>

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

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