Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Always pass CVV on card update for Braintree Blue

Always passing the CVV allows for "updating a credit card and explicitly
verifying the card" at the same time:
https://www.braintreepayments.com/docs/ruby/general/card_verification#credit_card_api
  • Loading branch information...
commit 0836d0c2c189d0b8ff7c4f641c9a6782c001530d 1 parent 7ea6cdf
Shay Frendt authored June 15, 2012
1  lib/active_merchant/billing/gateways/braintree_blue.rb
@@ -105,6 +105,7 @@ def update(vault_id, creditcard, options = {})
105 105
           credit_card_params = merge_credit_card_options({
106 106
             :credit_card => {
107 107
               :number => creditcard.number,
  108
+              :cvv => creditcard.verification_value,
108 109
               :expiration_month => creditcard.month.to_s.rjust(2, "0"),
109 110
               :expiration_year => creditcard.year.to_s
110 111
             }
30  test/unit/gateways/braintree_blue_test.rb
@@ -150,6 +150,36 @@ def test_store_with_billing_address_options
150 150
     @gateway.store(credit_card("41111111111111111111"), :billing_address => billing_address)
151 151
   end
152 152
 
  153
+  def test_update_with_cvv
  154
+    stored_credit_card = mock(:token => "token", :default? => true)
  155
+    customer = mock(:credit_cards => [stored_credit_card], :id => '123')
  156
+    Braintree::Customer.stubs(:find).with('vault_id').returns(customer)
  157
+    BraintreeBlueGateway.any_instance.stubs(:customer_hash)
  158
+
  159
+    result = Braintree::SuccessfulResult.new(:customer => customer)
  160
+    Braintree::Customer.expects(:update).with do |vault, params|
  161
+      assert_equal "567", params[:credit_card][:cvv]
  162
+      [vault, params]
  163
+    end.returns(result)
  164
+
  165
+    @gateway.update('vault_id', credit_card("41111111111111111111", :verification_value => "567"))
  166
+  end
  167
+
  168
+  def test_update_with_verify_card_true
  169
+    stored_credit_card = mock(:token => "token", :default? => true)
  170
+    customer = mock(:credit_cards => [stored_credit_card], :id => '123')
  171
+    Braintree::Customer.stubs(:find).with('vault_id').returns(customer)
  172
+    BraintreeBlueGateway.any_instance.stubs(:customer_hash)
  173
+
  174
+    result = Braintree::SuccessfulResult.new(:customer => customer)
  175
+    Braintree::Customer.expects(:update).with do |vault, params|
  176
+      assert_equal true, params[:credit_card][:options][:verify_card]
  177
+      [vault, params]
  178
+    end.returns(result)
  179
+
  180
+    @gateway.update('vault_id', credit_card("41111111111111111111"), :verify_card => true)
  181
+  end
  182
+
153 183
   def test_merge_credit_card_options_ignores_bad_option
154 184
     params = {:first_name => 'John', :credit_card => {:cvv => '123'}}
155 185
     options = {:verify_card => true, :bogus => 'ignore me'}

0 notes on commit 0836d0c

Please sign in to comment.
Something went wrong with that request. Please try again.