lyang / braintree-rails

MIT License
65 stars 22 forks source link

CreditCard update inconsistent when updating expiration_date #5

Closed n0nick closed 11 years ago

n0nick commented 11 years ago

It seems that when trying to update a CreditCard instance using the expiration_date field, leaving out expiration_month and expiration_year, i.e.

card.update_attributes(:number => '4111111111111111', :cvv => '666', :expiration_date => '12/2027')

the behaviour is inconsistent: The first time it is done on a CreditCard instance, the change is not registered. After that, it seems to work fine. See testcase gist: https://gist.github.com/n0nick/5299333

In my debugging efforts, I've concluded that this is related to lib/braintree_rails/credit_card.rb:57:

attributes.delete(:expiration_date) if expiration_month.present?

The trouble is, expiration_month is always present for CreditCards that were fetched from Braintree! And so, expiration_date gets deleted.

I've included a unit test that expects expiration_date to be pending an update, and thus failing for now. I wasn't sure how to go about actually fixing the bug, since this seems like more of a design decision.

lyang commented 11 years ago

Hi, @n0nick This is now fixed in master, thanks!

n0nick commented 11 years ago

Awesome, thanks! :)