Add Paypal button redirect to a specific page after completing

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-xopaJ6vault=trueintent=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?

Topic scripts paypal html Wordpress javascript

Category Web


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

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.