Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Commit

Permalink
Braintree Blue: Allow unstoring just a credit card
Browse files Browse the repository at this point in the history
Unfortunately the Braintree implementation of store/unstore/update was
originally made very customer-centric where ActiveMerchant is credit
card centric. This means that #unstore expects a customer id rather than
a credit card token. To at least allow unstoring a card only, this
allows passing a credit card token for removal; the customer id must be
passed as nil for it to work, though.
  • Loading branch information
ntalbott committed Nov 29, 2013
1 parent ae0002f commit a781f34
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Braintree Blue: Allow specifying the customer id [ntalbott]
* Braintree Blue: Scrub invalid emails and zips [ntalbott]
* Braintree Blue: Return :credit_card_token as a top level param [ntalbott]
* Braintree Blue: Allow unstoring just a credit card [ntalbott]

== Version 1.42.2 (November 13th, 2013)

Expand Down
6 changes: 5 additions & 1 deletion lib/active_merchant/billing/gateways/braintree_blue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ def update(vault_id, creditcard, options = {})

def unstore(customer_vault_id, options = {})
commit do
@braintree_gateway.customer.delete(customer_vault_id)
if(!customer_vault_id && options[:credit_card_token])
@braintree_gateway.credit_card.delete(options[:credit_card_token])
else
@braintree_gateway.customer.delete(customer_vault_id)
end
Response.new(true, "OK")
end
end
Expand Down
11 changes: 10 additions & 1 deletion test/remote/gateways/remote_braintree_blue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def test_failed_add_to_vault
assert_equal nil, response.params["customer_vault_id"]
end

def test_unstore
def test_unstore_customer
assert response = @gateway.store(@credit_card)
assert_success response
assert_equal 'OK', response.message
Expand All @@ -375,6 +375,15 @@ def test_unstore
assert_success delete_response
end

def test_unstore_credit_card
assert response = @gateway.store(@credit_card)
assert_success response
assert_equal 'OK', response.message
assert credit_card_token = response.params["credit_card_token"]
assert delete_response = @gateway.unstore(nil, credit_card_token: credit_card_token)
assert_success delete_response
end

def test_unstore_with_delete_method
assert response = @gateway.store(@credit_card)
assert_success response
Expand Down

0 comments on commit a781f34

Please sign in to comment.