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
|
# 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(*args) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 49
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 74
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 => (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
123
124
125
126
127
128
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 123
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 96
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 => (customer_hash(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 => (customer_hash(Braintree::Customer.find(vault_id)) if result.success?)
)
end
end
|
#void(authorization, options = {}) ⇒ Object
64
65
66
67
68
69
70
71
72
|
# File 'lib/active_merchant/billing/gateways/braintree_blue.rb', line 64
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
|