lib/fake_braintree/customer.rb in fake_braintree-0.7.0 vs lib/fake_braintree/customer.rb in fake_braintree-0.8.0

- old
+ new

@@ -18,10 +18,14 @@ def create if invalid? response_for_invalid_card else + load_payment_method!( + @customer_hash.delete('payment_method_nonce'), + @customer_hash['credit_card'] ||= {} + ) credit_cards = customer_hash['credit_cards'] create_customer_with(customer_hash) credit_cards.each { |card| add_credit_card_to_registry(card) } set_default_credit_card credit_cards.first response_for_created_customer(customer_hash) @@ -116,10 +120,15 @@ end end def generate_credit_cards_from(new_credit_card_hash) if new_credit_card_hash.present? && new_credit_card_hash.is_a?(Hash) + load_payment_method!( + new_credit_card_hash.delete('payment_method_nonce'), + new_credit_card_hash + ) + new_credit_card_hash['bin'] = new_credit_card_hash['number'][0..5] new_credit_card_hash['last_4'] = new_credit_card_hash['number'][-4..-1] new_credit_card_hash['token'] = credit_card_token(new_credit_card_hash) if credit_card_expiration_month @@ -196,8 +205,14 @@ @customer_hash['id'] ||= create_id(@customer_hash['merchant_id']) end def credit_card_token(credit_card_hash_without_token) md5("#{credit_card_hash_without_token['number']}#{@customer_hash['merchant_id']}") + end + + def load_payment_method!(nonce, credit_card_hash) + return unless nonce + payment_method_hash = FakeBraintree.registry.payment_methods[nonce] + credit_card_hash.merge!(payment_method_hash) end end end