Stripe Invoices throws error undefined method date for <Stripe::Invoice

After integrating Stripe with our dashboard I’m getting the described error when fetching the stripe Invoices

Expected behavior

The invoices are displayed as intended

Actual behavior

There’s an error when fetching the stripe invoices it seems that it’s related to

Failure Logs

NoMethodError (undefined method `date' for #<Stripe::Invoice:0x00007fbea5759ca0>):

stripe (5.15.0) lib/stripe/stripe_object.rb:376:in `method_missing'
forest_liana (5.4.0) app/services/forest_liana/stripe_invoices_getter.rb:35:in `block in perform'
forest_liana (5.4.0) app/services/forest_liana/stripe_invoices_getter.rb:34:in `map'
forest_liana (5.4.0) app/services/forest_liana/stripe_invoices_getter.rb:34:in `perform'
...

Context

  • Ruby Version: 2.6.5
  • Forest Liana Version: 5.4.0
  • Rails Version: 5.2.4.4
  • Stripe Gem Version: 5.15.0

Edit:

I’ve updated the link to the file stripe_invoices_getter.rb

Hi @felipe.cabezudo !
I am not sure if it’s the source of the error, but can you check the type of @record ? You might need to use @record['date'], @record['period_start'], etc.

Hey, Actually the issue was on this file forest-rails/stripe_invoices_getter.rb at master · ForestAdmin/forest-rails · GitHub.

I’ve monkey patched the method and placed a byebug to check whether or not the invoice object had a date on it.
It results that the object provided by stripe doesn’t have a date on it and the method throws an error

I’ve also checked stripe documentation and there isn’t any specification of a date parameter at the Invoice
object https://stripe.com/docs/api/invoices/object

Hello @felipe.cabezudo, thanks for having reported the issue with such details.

Just to be sure, can you try to monkey patch again, and replace

d.date = Time.at(d.date).to_datetime

By

d.date = Time.at(d.created).to_datetime

And check if it fixes your issue?

Hey,

That fixes that issue but the serializer forest-rails/stripe_invoice_serializer.rb at a36791da9aa0321a20614a851cbf8c0f676402ba · ForestAdmin/forest-rails · GitHub still has undefined attributes, for example closed, once the objects get serialized this new error shows up NoMethodError (undefined method `closed' for #<Stripe::Invoice:.

I’ve tried deleting the attributes set on the serializer that aren’t specified in the stripe documentation, and it works! But the frontend still has those columns (the ones just deleted) at the stripe invoice tables

Thanks for the update @felipe.cabezudo

I created an issue on our side:

In the meantime, it would help a lot if you could work on a fix on your side and submit a Pull Request on Github. Even if the fix is not complete, it’ll create a starting point for our team.

Thanks! I’ve opened the PR Fix: stripe_invoices_getter.rb, stripe_invoice_serializer.rb by felipekb · Pull Request #409 · ForestAdmin/forest-rails · GitHub

2 Likes