PayPal button custom text and after pay script

Hi,

I have been looking around and cant seem to find what I am looking for.

I have a video I want to let users rent and pay via paypal. After they pay I want to run a script that adds their info to a DB and displays the link and some custom data. I have a backend function that deals with the DB and returns the custom data.

I am having difficulties with two things:

  1. How to have the text “Rent Now” on a PayPal button (not even sure if this is the best option)
  2. How can I run custom scripts after payment

TIA,

What “custom scripts” do you want to run? What kind of Paypal button are you using? Explain what you are trying to do, what works, and what doesn’t. Also, add any code in a code block as stated in the Forum Guidelines.

so the script i want to run checks if user data, his email and the previously given number, matches what is in a database:

//A function that adds the user info to the DB
export function AddUserToDB (_firstName, _lastName, _email, _tel)
{
 let pass, time, date;
 let currTime = Date();
    pass = Math.floor((Math.random() * 1000000)).toString();//generate a random 6 digit number
    time = Date.now();//get current time
    date = GetMonthName(time.getMonth()) + " " + time.getDate + ", " + time.getFullYear();
    wixData.insert("watchingListMembers", {"firstName": _firstName, "lastName": _lastName, "email": _email, "telephone": _tel, "date": date, "password": pass, "time": time});
}

and regarding the PayPal button, I am currently using the ‘PayPal Button’ (has only 2 text options: Buy now and Donate :/). If that choice is not good, I dont mind using another solution.

As far as running your code after using pays, you might be able to use the onOrderPaid() event.

Regarding the Paypal button, reach out to Wix Customer Care and see if they can help. Who knows, maybe someone here in the forum will chip in with a suggestion. You might just have to do a regular button, and then do the rest with code.

My function needs to add the email I got from the user to a DB. It looks like onOrderPaid() event is not connected to a specific page, and therefore I wont have the email address from the user.
Am I correct? or is there a way to pass to this event data from a specific page?

@bezalelkoplon The function onOrderPaid() is an event and isn’t “connected” to a page. It is triggered when a user pays for their order. The event receives all of the information needed as the parameter event , which includes buyerInfo . See the events documentation for details on how to use events.

So I was able to get a PayPal button to work and invoke a piece of my code.
I was only able to do this in sandbox mode, while using the generated sandbox accounts PayPal generates, and not other real personal accounts.

I follows the guide found here: https://developer.paypal.com/docs/checkout/integrate/#

When it came to run live, I switched the client ID to the live one but couldnt find where to c hange any API calls from https://api.sandbox.paypal.com to https://api.paypal.com.

After I put in the live client-ID the sandbox pay window still gets invoked.

How can I get the live version to work and be able to accept payment from non sandbox accounts?

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Ensures optimal rendering on mobile devices. -->
  <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <!-- Optimal Internet Explorer compatibility -->
</head>

<body>
  <script
    //sandbox
	src="https://www.paypal.com/sdk/js?client-id=AQpXvDkj1yqBNBC-SGiF3IdEvuQwN4AzEsusy1vr1rxIVfD-UpsHNcXC2gOzqoEnnSN3Q-5q80zpVtLg"> // Required. Replace SB_CLIENT_ID with your sandbox client ID.
	//live
	//src="https://www.paypal.com/sdk/js?client-id=<LiveID from PayPal>">
  </script>
  
  <div id="paypal-button-container"></div>

  <script>
  paypal.Buttons({
    createOrder: function(data, actions) {
      // This function sets up the details of the transaction, including the amount and line item details.
      return actions.order.create({
        purchase_units: [{
          amount: {
            value: '1'
          }
        }]
      });
    },
	onApprove: function(data, actions) {
      // This function captures the funds from the transaction.
      return actions.order.capture().then(function(details) {
        // This function shows a transaction success message to your buyer.
        alert('Transaction completed by ' + details.payer.name.given_name);
		window.parent.postMessage(" ", "https://wpcjerusalem.wixsite.com/wpcjerusalem/register-for-rental");
      });
    }
  }).render('#paypal-button-container');
  </script>
</body>

You’ll need to check Paypal’s documentation for the “Live” URLs.