google-apps-scriptstripe-paymentsstripes

create an invoice stripe using google app script


Hi I followed this documentation regarding on creating an invoice on stripe

it says here that The ID of the customer who will be billed. so I created a test customer manually on stripe and now I tried this code

function testDataInvoices()
{
  var url = "https://api.stripe.com/v1/invoices";
      var params = {
      method: "post",
      headers: {Authorization: "Basic " + Utilities.base64Encode("sk_testXXXXX:")},
      payload: 
      {
        customer: "cus_JLKM93Pc6j2mxB",
      }
    };
    var res = UrlFetchApp.fetch(url, params);
    Logger.log(res.getContentText())
}

but I am getting this error

Exception: Request failed for https://api.stripe.com returned code 400. Truncated server response: { "error": { "code": "invoice_no_customer_line_items",

Can someone please enlighten me about this stripe I really just new to this API and their API is just only for node.js

#TRIED

I tried following this link

and change my code to this

function testDataInvoices()
{
  var url = "https://api.stripe.com/v1/invoices";
      var params = {
      method: "post",
      headers: {Authorization: "Basic " + Utilities.base64Encode("sk_test_XXXXXX:")},
      payload: 
      {
        "email": "paul.kevin@senren.page",
        "payment_settings": 'pm_1FWS6ZClCIKljWvsVCvkdyWg',
        "invoice_settings[default_payment_method]":'pm_1FWS6ZClCIKljWvsVCvkdyWg'
      }
    };
    var res = UrlFetchApp.fetch(url, params);
    Logger.log(res.getContentText())
}

and got this error

enter image description here


Solution

  • A few things:

    I'd suggest following https://stripe.com/docs/invoicing/integration .