Class: ActiveMerchant::Billing::BraintreeBlueGateway
Constant Summary
Constants inherited
from Gateway
Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS
Instance Attribute Summary
Attributes inherited from Gateway
#options
Instance Method Summary
collapse
-
#authorize(money, credit_card_or_vault_id, options = {}) ⇒ Object
-
#capture(money, authorization, options = {}) ⇒ Object
-
#credit(money, credit_card_or_vault_id, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ BraintreeBlueGateway
constructor
A new instance of BraintreeBlueGateway.
-
#purchase(money, credit_card_or_vault_id, options = {}) ⇒ Object
-
#refund(*args) ⇒ Object
-
#store(creditcard, options = {}) ⇒ Object
-
#unstore(customer_vault_id) ⇒ Object
(also: #delete)
-
#update(vault_id, creditcard, options = {}) ⇒ Object
-
#void(authorization, options = {}) ⇒ Object
included
Methods inherited from Gateway
#card_brand, card_brand, inherited, supports?, #test?
#format
Constructor Details
Returns a new instance of BraintreeBlueGateway.
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 18
def initialize(options = {})
requires!(options, :merchant_id, :public_key, :private_key)
@options = options
@merchant_account_id = options[:merchant_account_id]
Braintree::Configuration.merchant_id = options[:merchant_id]
Braintree::Configuration.public_key = options[:public_key]
Braintree::Configuration.private_key = options[:private_key]
Braintree::Configuration.environment = (options[:environment] || (test? ? :sandbox : :production)).to_sym
Braintree::Configuration.logger.level = Logger::ERROR if Braintree::Configuration.logger
Braintree::Configuration.custom_user_agent = "ActiveMerchant #{ActiveMerchant::VERSION}"
super
end
|
Instance Method Details
#authorize(money, credit_card_or_vault_id, options = {}) ⇒ Object
31
32
33
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 31
def authorize(money, credit_card_or_vault_id, options = {})
create_transaction(:sale, money, credit_card_or_vault_id, options)
end
|
#capture(money, authorization, options = {}) ⇒ Object
35
36
37
38
39
40
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 35
def capture(money, authorization, options = {})
commit do
result = Braintree::Transaction.submit_for_settlement(authorization, amount(money).to_s)
Response.new(result.success?, message_from_result(result))
end
end
|
#credit(money, credit_card_or_vault_id, options = {}) ⇒ Object
46
47
48
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 46
def credit(money, credit_card_or_vault_id, options = {})
create_transaction(:credit, money, credit_card_or_vault_id, options)
end
|
#purchase(money, credit_card_or_vault_id, options = {}) ⇒ Object
42
43
44
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 42
def purchase(money, credit_card_or_vault_id, options = {})
authorize(money, credit_card_or_vault_id, options.merge(:submit_for_settlement => true))
end
|
#refund(*args) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 50
def refund(*args)
money, transaction_id, options = (args)
money = amount(money).to_s if money
commit do
result = Braintree::Transaction.refund(transaction_id, money)
Response.new(result.success?, message_from_result(result),
{:braintree_transaction => (transaction_hash(result.transaction) if result.success?)},
{:authorization => (result.transaction.id if result.success?)}
)
end
end
|
#store(creditcard, options = {}) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 75
def store(creditcard, options = {})
commit do
parameters = {
:first_name => creditcard.first_name,
:last_name => creditcard.last_name,
:email => options[:email],
:credit_card => {
:number => creditcard.number,
:cvv => creditcard.verification_value,
:expiration_month => creditcard.month.to_s.rjust(2, "0"),
:expiration_year => creditcard.year.to_s
}
}
result = Braintree::Customer.create(merge_credit_card_options(parameters, options))
Response.new(result.success?, message_from_result(result),
{
:braintree_customer => (customer_hash(result.customer) if result.success?),
:customer_vault_id => (result.customer.id if result.success?)
}
)
end
end
|
#unstore(customer_vault_id) ⇒ Object
Also known as:
delete
126
127
128
129
130
131
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 126
def unstore(customer_vault_id)
commit do
Braintree::Customer.delete(customer_vault_id)
Response.new(true, "OK")
end
end
|
#update(vault_id, creditcard, options = {}) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 98
def update(vault_id, creditcard, options = {})
braintree_credit_card = nil
customer_update_result = commit do
braintree_credit_card = Braintree::Customer.find(vault_id).credit_cards.detect { |cc| cc.default? }
return Response.new(false, 'Braintree::NotFoundError') if braintree_credit_card.nil?
options.merge!(:update_existing_token => braintree_credit_card.token)
credit_card_params = merge_credit_card_options({
:credit_card => {
:number => creditcard.number,
:expiration_month => creditcard.month.to_s.rjust(2, "0"),
:expiration_year => creditcard.year.to_s
}
}, options)[:credit_card]
result = Braintree::Customer.update(vault_id,
:first_name => creditcard.first_name,
:last_name => creditcard.last_name,
:email => options[:email],
:credit_card => credit_card_params
)
Response.new(result.success?, message_from_result(result),
:braintree_customer => (customer_hash(Braintree::Customer.find(vault_id)) if result.success?),
:customer_vault_id => (result.customer.id if result.success?)
)
end
end
|
#void(authorization, options = {}) ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 65
def void(authorization, options = {})
commit do
result = Braintree::Transaction.void(authorization)
Response.new(result.success?, message_from_result(result),
{:braintree_transaction => (transaction_hash(result.transaction) if result.success?)},
{:authorization => (result.transaction.id if result.success?)}
)
end
end
|