# Stripe for Google Sheets: script and web-hook

**URL:** <https://community.glideapps.com/t/stripe-for-google-sheets-script-and-web-hook/36395>\
**Category:** Community Resources\
**Created:** [December 27, 2021, 7:12pm UTC](https://community.glideapps.com/t/stripe-for-google-sheets-script-and-web-hook/36395 "2021-12-27T19:12:01Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [December 27, 2021, 7:12pm UTC](https://community.glideapps.com/t/stripe-for-google-sheets-script-and-web-hook/36395/1 "2021-12-27T19:12:01Z")

</div>

You can deal with Stripe directly now…  
just get an API key from Stripe, and you can generate payment links… it works! no more 10% fees for Glide… I hope they gonna rethink these fees!

 ![Screen Shot 2021-12-27 at 2.07.00 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/3/f/3f2cbf840ba96f44fe60c660fc6f345cf3214bb5.jpeg)  
 ![Screen Shot 2021-12-27 at 2.07.31 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/e/9/e915ced293501b982c66ff83a750a63ab09c6c23.png)

---

<div class="post-metadata">

**Author:** ![mzsadiek](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mzsadiek/32/36021_2.png) [@mzsadiek](https://community.glideapps.com/u/mzsadiek)\
**Post date:** [December 27, 2021, 7:30pm UTC](https://community.glideapps.com/t/stripe-for-google-sheets-script-and-web-hook/36395/2 "2021-12-27T19:30:04Z")

</div>

Excellent will be usable in lots of use cases 🙂

---

<div class="post-metadata">

**Author:** ![mzsadiek](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mzsadiek/32/36021_2.png) [@mzsadiek](https://community.glideapps.com/u/mzsadiek)\
**Post date:** [December 27, 2021, 7:31pm UTC](https://community.glideapps.com/t/stripe-for-google-sheets-script-and-web-hook/36395/3 "2021-12-27T19:31:52Z")

</div>

Is there any option for a URL to redirect to after payment via the payment link?

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [December 27, 2021, 7:34pm UTC](https://community.glideapps.com/t/stripe-for-google-sheets-script-and-web-hook/36395/4 "2021-12-27T19:34:40Z")

</div>

```auto
const STRIPE_API_KEY = "YOUR API";
const STRIPE_SUCCESS_URL = "succes URL";
const STRIPE_CANCEL_URL = "fail URL";

/**
 * Generate Stripe payment links in Google Sheets
 *
 * @param {number} amount The amount to be paid using Stripe
 * @param {string} currency The 3-letter currency code (optional)
 * @param {string} description A short description of the item name (optional)
 * @return Stripe checkout session link
 * @customfunction
 */

const STRIPE = (amount, currency, description) => {

  const input = {
    "line_items[0][price_data][currency]": currency || "USD",
    "line_items[0][price_data][product_data][name]": description || "Name",
    "line_items[0][price_data][unit_amount]": Math.ceil(amount * 100),
    "line_items[0][quantity]": 1,
  };

  const cacheKey = JSON.stringify(input);

  const cachedLink = CacheService.getScriptCache().get(cacheKey);

  if (cachedLink) return cachedLink;

  const params = {
    cancel_url: STRIPE_CANCEL_URL,
    success_url: STRIPE_SUCCESS_URL,
    mode: "payment",
    billing_address_collection: "required",
    "payment_method_types[]": "card",
    ...input,
  };

  const payload = Object.entries(params)
    .map(([key, value]) =>
      [encodeURIComponent(key), encodeURIComponent(value)].join("=")
    )
    .join("&");

  const response = UrlFetchApp.fetch(
    "https://api.stripe.com/v1/checkout/sessions",
    {
      method: "POST",
      headers: {
        Authorization: `Bearer ${STRIPE_API_KEY}`,
        "Content-Type": "application/x-www-form-urlencoded",
      },
      payload,
      muteHttpExceptions: true,
    }
  );

  const { url, error } = JSON.parse(response);

  if (url) {
    CacheService.getScriptCache().put(cacheKey, url, 21600);
  }

  return error ? error.message : url;
};

```

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [December 27, 2021, 11:35pm UTC](https://community.glideapps.com/t/stripe-for-google-sheets-script-and-web-hook/36395/5 "2021-12-27T23:35:51Z")

</div>

so… i’m playing with it… now i set up a webhook in Stripe and I got the feedback to my GS!!!  
LOL,  
this is great!! 🙂

 ![Screen Shot 2021-12-27 at 6.32.28 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/6/a/6a4b00c5ed1edbac60bb760f3c23f3a0c9580bae.png)  
 ![Screen Shot 2021-12-27 at 6.32.57 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/4/e/4e763713a0a53160d97600b39d785cc35253156e.png)

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [December 27, 2021, 11:38pm UTC](https://community.glideapps.com/t/stripe-for-google-sheets-script-and-web-hook/36395/6 "2021-12-27T23:38:12Z")

</div>

code for the web app to use in the webhook URL:

```auto
function doPost(e) {

    var jsonString = e.postData.getDataAsString();
    var event = JSON.parse(jsonString)
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheetByName("data");
    var timeStamp = new Date();
    var time = Utilities.formatDate(timeStamp, "GMT+08:00", "MM/dd/yy, h:mm a");
    var lastRow = sheet.getLastRow();
    var getHookType = event["type"];
    
switch (getHookType) {
  case "customer.created":
    var hookType = "New Customer"
    var customerId = event["data"].object.id;
    var customerEmail = event["data"].object.email;
    break;
  case "customer.subscription.created":       
    var hookType = "New Paid Subscriber";
    var customerId = event["data"].object.customer;
    break;
  case "charge.succeeded":
    var hookType = "Payment";
    var customerId = event["data"].object.customer;
    break;
  case "subscription_schedule.canceled":
    var hookType = "Cancelled";
    var customerId = event["data"].object.customer;
    }
    //Insert the data into the sheet  
    sheet.getRange(lastRow + 1, 1).setValue(time); 
    sheet.getRange(lastRow + 1, 2).setValue(hookType); 
    sheet.getRange(lastRow + 1, 3).setValue(event["data"]);   
    sheet.getRange(lastRow + 1, 4).setValue(customerEmail);
    sheet.getRange(lastRow + 1, 5).setValue(customerId);

  return HtmlService.createHtmlOutput(200);
}

```

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [December 27, 2021, 11:53pm UTC](https://community.glideapps.com/t/stripe-for-google-sheets-script-and-web-hook/36395/7 "2021-12-27T23:53:46Z")

</div>

Holy Cow!!! bye, bye Glide transaction fees! LOL  
So now… I can create free Apps that have a better desktop view than PRO, unlimited rows, and no transactions fees…

---

<div class="post-metadata">

**Author:** ![Roldy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/roldy/32/36068_2.png) [@Roldy](https://community.glideapps.com/u/Roldy)\
**Post date:** [December 28, 2021, 12:38am UTC](https://community.glideapps.com/t/stripe-for-google-sheets-script-and-web-hook/36395/8 "2021-12-28T00:38:52Z")

</div>

> [@Uzo](#):
>
> I can create free Apps that have a better desktop view than PRO, unlimited rows, and no transactions fees

So you pay nothing? I don’t know how much Glide will like this business model of yours, I don’t think they can work for us for free.  
I’m worried and disagree.

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [December 28, 2021, 12:42am UTC](https://community.glideapps.com/t/stripe-for-google-sheets-script-and-web-hook/36395/9 "2021-12-28T00:42:29Z")

</div>

i don’t think 10% is a fair rate, Stripe is charging only 2.9%… hitting you with an extra 10% on top…??? I don’t mind paying, but when is fair… most of the profits are set to 20% markup… so they wanna take half of your work

---

<div class="post-metadata">

**Author:** ![Roldy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/roldy/32/36068_2.png) [@Roldy](https://community.glideapps.com/u/Roldy)\
**Post date:** [December 28, 2021, 12:49am UTC](https://community.glideapps.com/t/stripe-for-google-sheets-script-and-web-hook/36395/10 "2021-12-28T00:49:30Z")

</div>

I think too that 10% is too much, but sorry you have brought up something else.  
Pay the fair and pay everyone, as in a civil society, to ensure development, continuity and reliability. That’s my opinion

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [December 28, 2021, 12:52am UTC](https://community.glideapps.com/t/stripe-for-google-sheets-script-and-web-hook/36395/11 "2021-12-28T00:52:54Z")

</div>

i agree… i have many PRO apps and many transactions going through them… i would not look for a solution if I don’t feel like a bit too much extra… especially since this is not a custom platform… it is a global system, which has millions of users… they should act more commercial… anyway, there are so many solutions like that out there, so it is just another one… that will keep users from not going to a different platform… I can bet, many of us simply give customers cash app, zele, western union, PayPal… when they have some serious sale going on… Glide could capitalize on that by simply reducing fees below 3% for free apps and 0% to 0.5% on paid apps

---

<div class="post-metadata">

**Author:** ![Roldy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/roldy/32/36068_2.png) [@Roldy](https://community.glideapps.com/u/Roldy)\
**Post date:** [December 28, 2021, 1:01am UTC](https://community.glideapps.com/t/stripe-for-google-sheets-script-and-web-hook/36395/12 "2021-12-28T01:01:34Z")

</div>

We agree on this. I must say that you have focused on a particularly important issue.

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [December 30, 2021, 5:59am UTC](https://community.glideapps.com/t/stripe-for-google-sheets-script-and-web-hook/36395/13 "2021-12-30T05:59:31Z")

</div>

all set and ready for production! Yea…

 ![Screen Shot 2021-12-30 at 12.56.39 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/4/7/477fb94a4f41bd545a8f3f2a2e67fdfd7b88913f.png)

AND THEY CLOSE THIS TOPIC ;-(

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)\
**Post date:** [December 31, 2021, 5:59am UTC](https://community.glideapps.com/t/stripe-for-google-sheets-script-and-web-hook/36395/14 "2021-12-31T05:59:32Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
