PayPal payment acceptance system

522 views
Skip to first unread message

Alan Wells

unread,
Dec 11, 2020, 8:25:26 PM12/11/20
to Google Apps Script Community
I've created some code to accept payments from PayPal using Apps Script.
It uses the newer PayPal JavaScript SDK which became available February 2019.
That's almost two years ago, but I hadn't look at my PayPal code for quite a while.
The PayPal client code generates PayPal buttons that get inserted into your HTML,
so there is no need to insert image files for PayPal buttons.
The PayPal log in dialog opens in a small window that overlays your current content
instead of opening a new browser window.
Because it also uses server side code, you have more options available to you,
and maybe better security.
There is no need for an IPN listener because when the order is accepted,
your code can call a server side Apps Script function.

See StackOverflow answer:

Andrew Apell

unread,
Dec 13, 2020, 3:44:57 PM12/13/20
to Google Apps Script Community
Thanks for this. I setup my PayPal system at the end of 2019 so I think I'm already using the new API but mine still opens a new window.
I think I'll use this opportunity to revise my code to make it better.

Alan Wells

unread,
Dec 13, 2020, 4:31:40 PM12/13/20
to Google Apps Script Community
Thanks for the feedback.  I just added something new this morning, to capture the order.
Technically, you don't need server code if you don't have something like a cart.
And the server code will make it a little slower.
But it's a lot faster than using an IPN listener.
I also added the code on GitHub:

Andrew Apell

unread,
Dec 14, 2020, 7:37:30 AM12/14/20
to Google Apps Script Community
👍

Faustino Rodriguez

unread,
Dec 14, 2020, 12:35:38 PM12/14/20
to Google Apps Script Community
Thanks Alan
Maybe it's about time for us to review our PayPal subscription workflow
- We rely exclusively on an IPN server listener, connected through a Firebase realtime database, to the add-on client-side subscription dialog
- But this kind of "embedded" experience might be much better for the user
- We would keep the IPN server to react to subscription changes at PayPal

Alan Wells

unread,
Dec 14, 2020, 12:57:14 PM12/14/20
to Google Apps Script Community
If your payment system needs to make a server call, then this new server side integration will probably be a lot better.
You can have the "embedded" PayPal log in (technically a browser window that is small and overlays) without using the server side integration.
So, you can switch to the newer PayPal JavaScript SDK, and still keep everything client side if that's your preference or need.
Although there are some options that may only be available with the server side integration.
This is the first time that I've felt good about how the PayPal system is working.
This is at least the 3rd time I've changed my PayPal code I think.

Faustino Rodriguez

unread,
Dec 15, 2020, 8:24:03 PM12/15/20
to Google Apps Script Community
That's a good point indeed
Thanks again

Kim Nilsson

unread,
Dec 17, 2020, 3:43:20 AM12/17/20
to Google Apps Script Community
Interesting.
Alan, do you have any examples of where you use this, for your own things I mean.
So it can be observed "in the wild", so to speak. :-)

Do you use it to verify a "licensed user" or something similar, to get access to more features? Or just as a "buy me beer" opportunity?

Alan Wells

unread,
Dec 17, 2020, 9:31:40 AM12/17/20
to Google Apps Script Community
I just implemented this new PayPal code into my Google Forms add-on named Emails Director Gold.
You'd need to install the add-on.
The store listing is at:
That add-on doesn't have a free tier.  It has a free trial period.
The PayPal code that I've provided doesn't include the code that I use to determine the trial period or whether the user is paid.
I don't have many paid users, so I just save customer information to a Google Sheet.
The customer information saved to a Google Sheet is obviously done with server side code, so as soon as the payment has been
accepted, the client side code makes a call to the server.
The PayPal code provided is intended to be stripped down and generic, it's not the exact code that I use.
So, if you need code to filter out the paid and unpaid features, or the trial period,
this code doesn't provide that.
I don't have any sample code for that.
Do you have an app that you'd like to accept payments/donations for?
If you are accepting donations, then you don't really need the server side integration, and it would be much simpler.

Kim Nilsson

unread,
Dec 17, 2020, 10:25:54 AM12/17/20
to Google Apps Script Community
Thank you so much for explaining in such detail.

I'm hoping to, during next year, to publish at least one and maybe a few addons that can accept donations, but I don't have anything created or in mind for freemium or paid features. So I'll be happy to learn how to incorporate the donations code in my project.

Kim

Alan Wells

unread,
Dec 17, 2020, 10:38:25 AM12/17/20
to Google Apps Script Community
The easiest way to to create a PayPal button and just copy the code to your html.
But don't choose the "donation" option because that requires you to send the money somewhere else.
It's not a donation to you, it's a donation to someone else.
Or something like that.
In any case, make sure that you understand what it's actually doing.

Kim Nilsson

unread,
Dec 17, 2020, 10:51:58 AM12/17/20
to Google Apps Script Community
Oh, then perhaps something like the code I have on github would work?


Or should I use some special PayPal embed code instead?

Alan Wells

unread,
Dec 17, 2020, 11:14:16 AM12/17/20
to Google Apps Script Community
That's a PayPal Me button.
The amount is set to zero, and the user can enter any amount.
I don't know how much success you've had with that, but I haven't had much success with it.
I don't know why.
Maybe because it opens in another browser tab?
Maybe because if they need to think about how much to enter, then they decide to not give anything an close the page?
But now we're getting into marketing psychology.
Even if you are asking for a voluntary payment, (I'm not calling it a donation because that has legal implications)
it's probably better to have a set amount.
A donation implies that you should legally be set up as a non-profit org.
But if you're only getting a very small amount of money, it's probably not worth the time, effort and money to legally do that.
So, the "donation" is probably actually income going to you as far as tax liability goes.
But that depends on the tax laws in your area.

Kim Nilsson

unread,
Dec 17, 2020, 11:18:15 AM12/17/20
to Google Apps Script Community
Oh, yes, I'm in Sweden so anything coming in is income. :-)

Nah, I've not received a single thing from that. :-)
I'm thinking, when you give something away for free people grab it and run. :-)
So, the PayPal Me button was just added there to have as a test.
Never expected to get anything from it.

Kim
Reply all
Reply to author
Forward
0 new messages