balanced / balanced-ruby

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

postal_code method on Balanced::Card doesn't always exist #122

Closed blim8183 closed 11 years ago

blim8183 commented 11 years ago

If I load a a card with no postal code and call postal_code on it, I get the following error:

NoMethodError: undefined method `postal_code' for #    <Balanced::Card:0x00000006497a68>
from /app/vendor/bundle/ruby/1.9.1/gems/balanced-0.7.2/lib/balanced/resources/resource.rb:93:in `method_missing'
from (irb):2
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

However, after loading a card that does have a postal code, the original item will return "nil" instead of blowing up.

mjallday commented 11 years ago

@blim8183 it looks like this field is only returned on valid cards, on invalid (e.g. deleted) cards it is not returned.

Does this correspond with what you're seeing or is it not being returned on a valid card? If it's the latter please provide us with the URI of the card in question and we'll look at what's going on.

blim8183 commented 11 years ago

/marketplaces/MP3Qbrqi8eRZpdzVU3jtQewu/cards/CC1t74WFG31XgNbecvpDLuiW

That is a valid card that was tokenized and associated with a customer without ever including a postal code

mjallday commented 11 years ago

Thanks for that, we've found the issue and will release a fix to ensure the field is consistently returned on card objects. We'll update this github issue once it's been resolved and deployed.

For whoever fixes this - the view for the address fields defaults to pez.SKIP, adding default=None should resolve this issue.

curl https://api.balancedpayments.com/v1/marketplaces/TEST-MPxn4pzNrkXXrrA69phWFSg/cards      -u 118f07b8fdd611e2a0af026ba7cd33d0:      -d "expiration_month=12"      -d "security_code=123"      -d "card_number=5105105105105100"      -d "expiration_year=2020" | grep street
mjallday commented 11 years ago

@blim8183 this should now be fixed, please reopen if it's not working as you expected

curl https://api.balancedpayments.com/v1/marketplaces/TEST-MPxn4pzNrkXXrrA69phWFSg/cards      -u 118f07b8fdd611e2a0af026ba7cd33d0:      -d "expiration_month=12"      -d "security_code=123"      -d "card_number=5105105105105100"      -d "expiration_year=2020" 2>/dev/null | grep street 
  "street_address": null