In a recent Totally unscripted broadcast, Steve Webster provided a great introduction to monetizing add-ons, along with some sample code on how to use Stripe to manage payments.
Using stripe means that you have to deal with things happening both server and client side, as well as with the Stripe API. This means that there's a fair bit of async activities going on, and if you read the content on this site at all you'll notice that I prefer to use Promises to orchestrate all that. In this post I'll show a way of implementing Stripe from Apps Script using promises.
Stripe have a simplified entry point to their API - StripeCheckout. You can include it in your project with
The steps involved in using StripeCheckout are as follows
I have a dedicated namespace for doing all my Stripe related stuff, but the method that configures and gets the payment is here.
Let's walk through that a little.
getPayment returns a promise which is resolved when
The closed handler is fired after the token handler, so that way you can know if the resolved promise delivers null, then the payment form has been abandoned.
This is what the payment form looks like
If the user successfully completes a payment, then this is fired.
I have a couple of different payment forms in the app from which this code is extracted, so I use this general function
Let's walk through
This is running from the client side, but it obviously has to update properties using server side functions to store the result of the payment.
In other words , a successful payment replaces this
Services > Desktop Liberation - the definitive resource for Google Apps Script and Microsoft Office automation > Add-ons >