0

Using the Stripe Go library, when listing the invoices for a particular customer, the amount due for that invoice is $1000 when it should be $10.00 (which is seen in the Stripe dashboard).

I'm assuming it's because the AmountDue field in the Invoice struct is an int64 (https://github.com/stripe/stripe-go/blob/master/invoice.go#L204), and it's losing the decimal component during a cast, but is there a way to get the exact amount?

This is how I'm querying the invoices:

  params := &stripe.InvoiceListParams{}
  params.Filters.AddFilter("limit", "", "100")
  params.Filters.AddFilter("customer", "", stripeCustomerId)
  i := invoice.List(params)
  for i.Next() {
    i := i.Invoice()

    invoice := BillingModels.Transaction{
      Id:         i.ID,
      Amount:     i.AmountDue,
    }   

    invoices = append(invoices, invoice)
  }

1 Answers1

2

The AmountDue field is in cents, as are all the Stripe fields, so they should be stored as an integer. This is quite common when dealing with money. Never use floats for currency.

https://stripe.com/docs/api/invoices/object#invoice_object-amount_due

Kenny Grant
  • 9,360
  • 2
  • 33
  • 47