| Class | ActiveMerchant::Billing::BraintreeGateway |
| In: |
lib/active_merchant/billing/gateways/braintree.rb
|
| Parent: | Gateway |
| URL | = | 'https://secure.braintreepaymentgateway.com/api/transact.php' |
# File lib/active_merchant/billing/gateways/braintree.rb, line 13
13: def initialize(options = {})
14: requires!(options, :login, :password)
15: @options = options
16: super
17: 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).
# File lib/active_merchant/billing/gateways/braintree.rb, line 25
25: def authorize(money, creditcard, options = {})
26: post = {}
27: add_invoice(post, options)
28: add_payment_source(post, creditcard,options)
29: add_address(post, creditcard, options)
30: add_customer_data(post, options)
31:
32: commit('auth', money, post)
33: end
# File lib/active_merchant/billing/gateways/braintree.rb, line 45
45: def capture(money, authorization, options = {})
46: post ={}
47: post[:transactionid] = authorization
48: commit('capture', money, post)
49: end
# File lib/active_merchant/billing/gateways/braintree.rb, line 71
71: def delete(vault_id)
72: post = {}
73: post[:customer_vault] = "delete_customer"
74: add_customer_vault_id(post, vault_id)
75: commit(nil, nil, post)
76: end
# File lib/active_merchant/billing/gateways/braintree.rb, line 35
35: def purchase(money, payment_source, options = {})
36: post = {}
37: add_invoice(post, options)
38: add_payment_source(post, payment_source, options)
39: add_address(post, payment_source, options)
40: add_customer_data(post, options)
41:
42: commit('sale', money, post)
43: end
To match the other stored-value gateways, like TrustCommerce, store and unstore need to be defined
# File lib/active_merchant/billing/gateways/braintree.rb, line 80
80: def store(creditcard, options = {})
81: billing_id = options.delete(:billing_id).to_s || true
82: authorize(100, creditcard, options.merge(:store => billing_id))
83: end
Update the values (such as CC expiration) stored at BrainTree. The CC number must be supplied in the CreditCard object.
# File lib/active_merchant/billing/gateways/braintree.rb, line 60
60: def update(vault_id, creditcard, options = {})
61: post = {}
62: post[:customer_vault] = "update_customer"
63: add_customer_vault_id(post, vault_id)
64: add_creditcard(post, creditcard, options)
65: add_address(post, creditcard, options)
66: add_customer_data(post, options)
67:
68: commit(nil, nil, post)
69: end