balanced / balanced-ruby

Balanced API library in ruby.
MIT License
111 stars 47 forks source link

Balanced::Debit.source sometimes returns a Hash #158

Open taylorbrooks opened 10 years ago

taylorbrooks commented 10 years ago

I'm trying to find failed debits originating from a Bank Account. Like so:

failed_debits = Balanced::Debit.where(status: 'failed')
failed_debits.each do |d| 
  if d.source._type == 'bank_account'
    p "#{d.created_at} #{d.amount} #{d.customer.name} #{d.appears_on_statement_as}"
  end
end

The problem here is that the debit source class is sometimes:

Balanced::Card
Balanced::BankAccount
Hash

Why would it return a hash? Shouldn't it always return either a Card or BankAccount object? I'm using 0.7.4 version of the gem.

mjallday commented 10 years ago

@taylorbrooks that is odd. Can I see the output of the funding instrument that's represented by the hash?

i suspect there's something odd about the bank account/card e.g. it has been deleted and the client library is having trouble figuring out the type.

taylorbrooks commented 10 years ago
{
    "routing_number"=>"063115194", 
    "bank_name"=>"REGIONS BANK", 
    "_type"=>"bank_account", 
    "name"=>"E***a V**a", 
    "_uris"=>{}, 
    "type"=>"checking", 
    "meta"=>{}, 
    "account_number"=>"xxxxxxxxx0132",
    "fingerprint"=>"a629871d5a4b3788e8f687d4eae10589c4a1bca8826082b3c12b2ca7cef1e3a7",
    "can_debit"=>true
}
mjallday commented 10 years ago

Thanks. It is indeed a deleted funding instrument.

It looks like the code requires a URI in order to determine the object type.

Balanced needs to return URIs for all resources even if they have been deleted. This needs to be implemented in the API before we can fix it in the client libraries. I suspect the 1.1 revision will not be susceptible to this since it returns resources in a collection so this is only going to effect 1.0 clients.

taylorbrooks commented 10 years ago

Ok, got it.

1) Will 1.0 have breaking changes? 2) When will 1.0 be pushed to RubyGems?

mjallday commented 10 years ago
  1. 1.0 is the current version you're using. There are no breaking changes in that. 1.1 is the new revision and it is largely backwards compatible but not a drop-in replacement. If you're using the deprecated Accounts still you need to switch to customers.
  2. There is a pre-release version. Nothing's going to change as far as I know beyond the removal of the beta tag which is blocking on some last minute documentation changes.