Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Add update and delete methods to update and delete records stored in …
Browse files Browse the repository at this point in the history
…the vault

git-svn-id: https://activemerchant.googlecode.com/svn/trunk/active_merchant@572 6513ea26-6c20-0410-8a68-89cd7235086d
  • Loading branch information
codyfauser committed Jan 23, 2008
1 parent b9726b0 commit 60f7024
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
= ActiveMerchant CHANGELOG

* Add update and delete methods to update and delete records stored in the vault. [benjamin.curtis]
* Add support for recurring_inquiry() to the PayflowGateway [dave.my...@contentfree.com]
* Add support for Authorize.net Automated Recurring Billing (ARB) [vkurnavenkov, forestcarlisle, ianlotin...@hotmail.com, patrick.t.joyce]
* Fix laser card regex [ladislav.martincik]
Expand Down
43 changes: 39 additions & 4 deletions lib/active_merchant/billing/gateways/brain_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ def initialize(options = {})
super
end

# Pass :store => true in the options to store the
# payment info at BrainTree and get a generated
# customer_vault_id in the response.
# Pass :store => some_number_or_string to specify the
# customer_vault_id BrainTree should use (make sure it's
# unique).
def authorize(money, creditcard, options = {})
post = {}
add_invoice(post, options)
Expand All @@ -41,6 +47,33 @@ def capture(money, authorization, options = {})
post[:transactionid] = authorization
commit('capture', money, post)
end

def void(authorization, options = {})
post ={}
post[:transactionid] = authorization
commit('void', nil, post)
end

# Update the values (such as CC expiration) stored at
# BrainTree. The CC number must be supplied in the
# CreditCard object.
def update(vault_id, creditcard, options = {})
post = {}
post[:customer_vault] = "update_customer"
add_customer_vault_id(post, vault_id)
add_creditcard(post, creditcard, options)
add_address(post, creditcard, options)
add_customer_data(post, options)

commit(nil, nil, post)
end

def delete(vault_id)
post = {}
post[:customer_vault] = "delete_customer"
add_customer_vault_id(post, vault_id)
commit(nil, nil, post)
end

private
def add_customer_data(post, options)
Expand Down Expand Up @@ -82,9 +115,11 @@ def add_customer_vault_id(params,vault_id)
params[:customer_vault_id] = vault_id
end

def add_creditcard(post, creditcard,options)
post[:customer_vault] = "add_customer" if options[:store]

def add_creditcard(post, creditcard,options)
if options[:store]
post[:customer_vault] = "add_customer"
post[:customer_vault_id] = options[:store] unless options[:store] == true
end
post[:ccnumber] = creditcard.number
post[:cvv] = creditcard.verification_value if creditcard.verification_value?
post[:ccexp] = expdate(creditcard)
Expand Down Expand Up @@ -149,7 +184,7 @@ def post_data(action, parameters = {})
post = {}
post[:username] = @options[:login]
post[:password] = @options[:password]
post[:type] = action
post[:type] = action if action

request = post.merge(parameters).map {|key,value| "#{key}=#{CGI.escape(value.to_s)}"}.join("&")
request
Expand Down
33 changes: 33 additions & 0 deletions test/remote/gateways/remote_brain_tree_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,29 @@ def test_successful_add_to_vault_and_use
assert_equal 'This transaction has been approved', second_response.message
assert second_response.success?
end

def test_add_to_vault_with_custom_vault_id
@options[:store] = rand(100000)+10001
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_equal 'This transaction has been approved', response.message
assert_success response
assert_equal @options[:store], response.params["customer_vault_id"].to_i
end

def test_update_vault
test_add_to_vault_with_custom_vault_id
@credit_card = credit_card('4111111111111111', :month => 10)
assert response = @gateway.update(@options[:store], @credit_card)
assert_success response
assert_equal 'Customer Update Successful', response.message
end

def test_delete_from_vault
test_add_to_vault_with_custom_vault_id
assert response = @gateway.delete(@options[:store])
assert_success response
assert_equal 'Customer Deleted', response.message
end

def test_declined_purchase
assert response = @gateway.purchase(@declined_amount, @credit_card, @options)
Expand All @@ -66,6 +89,16 @@ def test_authorize_and_capture
assert_equal 'This transaction has been approved', capture.message
assert_success capture
end

def test_authorize_and_void
assert auth = @gateway.authorize(@amount, @credit_card, @options)
assert_success auth
assert_equal 'This transaction has been approved', auth.message
assert auth.authorization
assert void = @gateway.void(auth.authorization)
assert_equal 'Transaction Void Successful', void.message
assert_success void
end

def test_failed_capture
assert response = @gateway.capture(@amount, '')
Expand Down

0 comments on commit 60f7024

Please sign in to comment.