1

Hi guys I am having trouble sending an invoice due to

parameter_invalid_integer

this error.

Here's my code of sending

var url3 = "https://api.stripe.com/v1/invoices";
      var params3 = {
      method: "post",
      headers: {Authorization: "Basic " + Utilities.base64Encode("sk_test_XXXXX:")},
      payload: 
      {
        customer: responseValue.id,
        collection_method : "send_invoice",
        due_date:responseValue2.date
      }
    };
    var res3 = UrlFetchApp.fetch(url3, params3);
    Logger.log(res3.getContentText());

the due_date is the problem because I can't give its format . The documentation didn't provide any of that or I am just dumb that I can't understand it.

I tried

due_date:Date.now()
due_date:"01/01/2022" // tried different formats

What I am trying to do is that I am trying to send the invoice base on the email address provided on the invoice.

Please enlighten me . Thank you.

#TRIED 1

var timeStamp = (new Date('2022-01-01').getTime())/1000;
due_date = timeStamp

still the same error

Ginxxx
  • 1,602
  • 2
  • 25
  • 54

3 Answers3

2

All dates/timestamps in the Stripe API use unix seconds (not milliseconds). So you set the due date to Jan 1 2022 (at 0h UTC, say), you'd use due_date=1641013200

Nolan H
  • 6,205
  • 1
  • 5
  • 19
  • tried that already sir but still got the same error – Ginxxx Apr 22 '21 at 16:16
  • Did you notice that TheMaster suggested that you stringify the payload? – Cooper Apr 22 '21 at 16:38
  • @MetaMan can you explain a bit more sir . – Ginxxx Apr 22 '21 at 16:48
  • 1
    The timestamp needs to be sent as an integer, not a string. It's possible that your request library is inadvertently converting the parameter to a string. Ensure that your request is encoded using as `Content-Type: application/x-www-form-urlencoded` noted at the start of the API ref here: https://stripe.com/docs/api – Nolan H Apr 22 '21 at 17:44
0
payload:JSON.stringify({customer:responseValue.id,collection_method:"send_invoice",due_date:responseValue2.date});

I don't know for a fact that this will work but I'd try it if TheMaster said to try it.

Cooper
  • 59,616
  • 6
  • 23
  • 54
  • actually the only problem is that the `due_date` part is not working because of some kind of format – Ginxxx Apr 22 '21 at 17:32
-1

Solved it . What I did was

var timeStamp = (new Date('2021-08-10').getTime())/1000;
due_date: ""+timeStamp+""

Thanks everyone.

Ginxxx
  • 1,602
  • 2
  • 25
  • 54