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

Question

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. Click here for the image

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. Paypal config

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

0
Havishka Halangoda 5 months 2022-03-10T00:21:55-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse