Permalink
Browse files

Add support for creating a credit card with an existing billing address.

  • Loading branch information...
1 parent 52bbb10 commit 2b0314c4f17e7b18f305e65b06e1b66889a5130d @brandon-beacher brandon-beacher committed with gabebw Feb 20, 2013
Showing with 8 additions and 0 deletions.
  1. +7 −0 lib/fake_braintree/credit_card.rb
  2. +1 −0 spec/fake_braintree/credit_card_spec.rb
@@ -4,6 +4,7 @@ class CreditCard
def initialize(credit_card_hash_from_params, options)
set_up_credit_card(credit_card_hash_from_params, options)
+ set_billing_address
set_expiration_month_and_year
end
@@ -104,6 +105,12 @@ def set_up_credit_card(credit_card_hash_from_params, options)
}.merge(credit_card_hash_from_params)
end
+ def set_billing_address
+ if @hash["billing_address_id"]
+ @hash["billing_address"] = FakeBraintree.registry.addresses[@hash['billing_address_id']]
+ end
+ end
+
def set_expiration_month_and_year
if expiration_month
@hash['expiration_month'] = expiration_month
@@ -72,6 +72,7 @@ def build_credit_card_hash
result.should be_success
Braintree::Customer.find(@customer.id).credit_cards.last.token.should == 'token'
Braintree::Customer.find(@customer.id).credit_cards.last.default?.should be_true
+ Braintree::Customer.find(@customer.id).credit_cards.last.billing_address.postal_code.should == "94110"
end
it 'only allows one credit card to be default' do

0 comments on commit 2b0314c

Please sign in to comment.