doushe2513 2019-07-01 00:05
浏览 41
已采纳

如何使用Go API获取确切的金额而不是条纹发票的整数金额? [重复]

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)
  }
</div>
  • 写回答

1条回答 默认 最新

  • dsfgds4215 2019-07-01 00:10
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥15 电脑锁屏时vba运行SAP,excel数据不能复制到SAP
    • ¥50 74LS系列 74LS00 74LS04设计一个RS485电路(关键词-差分)
    • ¥30 各位help写一下代码
    • ¥15 在运行SDEdit模型下载不了
    • ¥15 求51控制l298n驱动的小车中超声波避障怎么写
    • ¥15 电脑连上WIFI却用不了
    • ¥30 MATLAB在RLC电路的固有响应和阶跃响应GUI仿真报告
    • ¥15 hyper-v出现的问题
    • ¥15 有能用的可加酬金,求可以批量下载懒人听书的软件,能登录自己帐号的。
    • ¥100 高博一起做RGB-D SLAM(5)VO无法出visualisation问题