javascript - Add Paypal button redirect to a specific page after completing

admin2025-01-08  4

I have created a new page on my WordPress site to test the paypal payment flow. I have subscription based products. Attached code is for the paypal subscription button code.

 <div id="paypal-button-container-P-91F08612M1573283BMIUWMOA"></div>
<script src=";vault=true&intent=subscription" data-sdk-integration-source="button-factory"></script>
<script>
  paypal.Buttons({
      style: {
          shape: 'rect',
          color: 'gold',
          layout: 'vertical',
          label: 'subscribe'
      },
      createSubscription: function(data, actions) {
        return actions.subscription.create({
          /* Creates the subscription */
          plan_id: 'P-91xxxxxxxxxxxxxxx'
        });
      },
      onApprove: function(data, actions) {
        alert(data.subscriptionID); // You can add optional success message for the subscriber here
      }
  }).render('#paypal-button-container-P-91F08612M1573283BMIUWMOA'); // Renders the PayPal button
</script>

My outcome was success and it shows this message.

On completion, I just get an order number pop-up and then it stays on the same page. (check the image) What I want now is to redirect my user to a specific page after successful payment. I already set the URL auto return path from paypal but it won't working. See my paypal configuration from the below image.

How can I redirect user by adjusting the code? Will I be able to make that change?

I have created a new page on my WordPress site to test the paypal payment flow. I have subscription based products. Attached code is for the paypal subscription button code.

 <div id="paypal-button-container-P-91F08612M1573283BMIUWMOA"></div>
<script src="https://www.paypal.com/sdk/js?client-id=AfGWAPJxdGbCj7b51a2mpoZQYI5y63txxxxxxxxIe1UDh2Vxcr05AFJxxxxNSCNDf8y-xopaJ6&vault=true&intent=subscription" data-sdk-integration-source="button-factory"></script>
<script>
  paypal.Buttons({
      style: {
          shape: 'rect',
          color: 'gold',
          layout: 'vertical',
          label: 'subscribe'
      },
      createSubscription: function(data, actions) {
        return actions.subscription.create({
          /* Creates the subscription */
          plan_id: 'P-91xxxxxxxxxxxxxxx'
        });
      },
      onApprove: function(data, actions) {
        alert(data.subscriptionID); // You can add optional success message for the subscriber here
      }
  }).render('#paypal-button-container-P-91F08612M1573283BMIUWMOA'); // Renders the PayPal button
</script>

My outcome was success and it shows this message.

On completion, I just get an order number pop-up and then it stays on the same page. (check the image) What I want now is to redirect my user to a specific page after successful payment. I already set the URL auto return path from paypal but it won't working. See my paypal configuration from the below image.

How can I redirect user by adjusting the code? Will I be able to make that change?

Share Improve this question asked Mar 10, 2022 at 5:21 Havishka HalangodaHavishka Halangoda 32 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

https://www.paypal.com/us/smarthelp/article/how-do-i-use-paypal's-auto-return-feature-to-redirect-customers-back-to-my-website-faq3651

paypal provide this auto redirect to merchant please try again may be it should work.

This would redirect you to a specific page

 onApprove: function(data, actions) {
        actions.redirect('https://gutsycreatives.com/'); // You can add optional success message for the subscriber here
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736269973a1393.html

最新回复(0)