Skip to content

Commit

Permalink
Add support for creating a credit card with an existing billing address.
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-beacher authored and Gabe Berke-Williams committed Apr 12, 2013
1 parent 52bbb10 commit 2b0314c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/fake_braintree/credit_card.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/fake_braintree/credit_card_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 2b0314c

Please sign in to comment.