Class: ActiveMerchant::Billing::BraintreeBlueGateway
Constant Summary
Constants inherited
from Gateway
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(transaction_id, options = {}) ⇒ 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?
Methods included from Utils
generate_unique_id
#format
#requires!
Methods included from PostsData
included, #ssl_get, #ssl_post
Constructor Details
Returns a new instance of BraintreeBlueGateway.
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 18
def initialize(options = {})
requires!(options, :merchant_id, :public_key, :private_key)
@options = options
Braintree::Configuration.merchant_id = options[:merchant_id]
Braintree::Configuration.public_key = options[:public_key]
Braintree::Configuration.private_key = options[:private_key]
Braintree::Configuration.environment = test? ? :sandbox : :production
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
30
31
32
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 30
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
34
35
36
37
38
39
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 34
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
45
46
47
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 45
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
41
42
43
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 41
def purchase(money, credit_card_or_vault_id, options = {})
authorize(money, credit_card_or_vault_id, options.merge(:submit_for_settlement => true))
end
|
#refund(transaction_id, options = {}) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 49
def refund(transaction_id, options = {})
commit do
result = Braintree::Transaction.find(transaction_id).refund
Response.new(result.success?, message_from_result(result))
end
end
|
#store(creditcard, options = {}) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 65
def store(creditcard, options = {})
commit do
result = Braintree::Customer.create(
: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
}
)
Response.new(result.success?, message_from_result(result),
{
:braintree_customer => (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
114
115
116
117
118
119
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 114
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 87
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?
result = Braintree::Customer.update(vault_id,
:first_name => creditcard.first_name,
:last_name => creditcard.last_name,
:email => options[:email]
)
Response.new(result.success?, message_from_result(result),
:braintree_customer => (Braintree::Customer.find(vault_id) if result.success?)
)
end
return customer_update_result unless customer_update_result.success?
credit_card_update_result = commit do
result = Braintree::CreditCard.update(braintree_credit_card.token,
:number => creditcard.number,
:expiration_month => creditcard.month.to_s.rjust(2, "0"),
:expiration_year => creditcard.year.to_s
)
Response.new(result.success?, message_from_result(result),
:braintree_customer => (Braintree::Customer.find(vault_id) if result.success?)
)
end
end
|
#void(authorization, options = {}) ⇒ Object
56
57
58
59
60
61
62
63
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 56
def void(authorization, options = {})
commit do
result = Braintree::Transaction.void(authorization)
Response.new(result.success?, message_from_result(result),
:braintree_transaction => (result.transaction if result.success?)
)
end
end
|