Class: ActiveMerchant::Billing::BraintreeGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/braintree.rb

Constant Summary collapse

URL =
'https://secure.braintreepaymentgateway.com/api/transact.php'

Constants inherited from Gateway

Gateway::DEBIT_CARDS

Constants included from PostsData

PostsData::MAX_RETRIES, PostsData::OPEN_TIMEOUT, PostsData::READ_TIMEOUT

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, inherited, supports?, #test?

Methods included from Utils

generate_unique_id

Methods included from CreditCardFormatting

#format

Methods included from RequiresParameters

#requires!

Methods included from PostsData

included, #retry_exceptions, #ssl_post

Constructor Details

#initialize(options = {}) ⇒ BraintreeGateway

Returns a new instance of BraintreeGateway.



13
14
15
16
17
# File 'lib/active_merchant/billing/gateways/braintree.rb', line 13

def initialize(options = {})
  requires!(options, :login, :password)
  @options = options
  super
end

Instance Method Details

#authorize(money, creditcard, options = {}) ⇒ Object

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).



25
26
27
28
29
30
31
32
33
# File 'lib/active_merchant/billing/gateways/braintree.rb', line 25

def authorize(money, creditcard, options = {})
  post = {}
  add_invoice(post, options)
  add_payment_source(post, creditcard,options)        
  add_address(post, creditcard, options)        
  add_customer_data(post, options)
  
  commit('auth', money, post)
end

#capture(money, authorization, options = {}) ⇒ Object



45
46
47
48
49
# File 'lib/active_merchant/billing/gateways/braintree.rb', line 45

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

#delete(vault_id) ⇒ Object Also known as: unstore



71
72
73
74
75
76
# File 'lib/active_merchant/billing/gateways/braintree.rb', line 71

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

#purchase(money, payment_source, options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/active_merchant/billing/gateways/braintree.rb', line 35

def purchase(money, payment_source, options = {})
  post = {}
  add_invoice(post, options)
  add_payment_source(post, payment_source, options)        
  add_address(post, payment_source, options)   
  add_customer_data(post, options)
       
  commit('sale', money, post)
end

#store(payment_source, options = {}) ⇒ Object

To match the other stored-value gateways, like TrustCommerce, store and unstore need to be defined



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/active_merchant/billing/gateways/braintree.rb', line 80

def store(payment_source, options = {})
  billing_id = options.delete(:billing_id).to_s || true
  post = {}
  post[:customer_vault] = 'add_customer'
  if billing_id
    post[:customer_vault_id] = billing_id
  end
  add_payment_source(post, payment_source, options)
  add_address(post, payment_source, options)
  add_customer_data(post, options)
  commit(nil,nil, post)
end

#update(vault_id, creditcard, options = {}) ⇒ Object

Update the values (such as CC expiration) stored at BrainTree. The CC number must be supplied in the CreditCard object.



60
61
62
63
64
65
66
67
68
69
# File 'lib/active_merchant/billing/gateways/braintree.rb', line 60

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

#void(authorization, options = {}) ⇒ Object



51
52
53
54
55
# File 'lib/active_merchant/billing/gateways/braintree.rb', line 51

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