Class: ActiveMerchant::Billing::SamuraiGateway
- Inherits:
-
Gateway
- Object
- Gateway
- ActiveMerchant::Billing::SamuraiGateway
show all
- Defined in:
- lib/active_merchant/billing/gateways/samurai.rb
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_id, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ SamuraiGateway
constructor
A new instance of SamuraiGateway.
-
#purchase(money, credit_card_or_vault_id, options = {}) ⇒ Object
-
#refund(money, transaction_id, options = {}) ⇒ Object
-
#store(creditcard, options = {}) ⇒ Object
-
#test? ⇒ Boolean
-
#void(transaction_id, options = {}) ⇒ Object
Methods inherited from Gateway
#card_brand, card_brand, inherited, supports?
#format
Constructor Details
Returns a new instance of SamuraiGateway.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/active_merchant/billing/gateways/samurai.rb', line 12
def initialize(options = {})
begin
require 'samurai'
rescue LoadError
raise "Could not load the samurai gem (>= 0.2.25). Use `gem install samurai` to install it."
end
requires!(options, :login, :password, :processor_token)
@options = options
Samurai.options = {
:merchant_key => options[:login],
:merchant_password => options[:password],
:processor_token => options[:processor_token]
}
end
|
Instance Method Details
#authorize(money, credit_card_or_vault_id, options = {}) ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/active_merchant/billing/gateways/samurai.rb', line 32
def authorize(money, credit_card_or_vault_id, options = {})
token = payment_method_token(credit_card_or_vault_id, options)
return token if token.is_a?(Response)
authorize = Samurai::Processor.authorize(token, amount(money), processor_options(options))
handle_result(authorize)
end
|
#capture(money, authorization_id, options = {}) ⇒ Object
48
49
50
51
|
# File 'lib/active_merchant/billing/gateways/samurai.rb', line 48
def capture(money, authorization_id, options = {})
transaction = Samurai::Transaction.find(authorization_id)
handle_result(transaction.capture(amount(money)))
end
|
#purchase(money, credit_card_or_vault_id, options = {}) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/active_merchant/billing/gateways/samurai.rb', line 40
def purchase(money, credit_card_or_vault_id, options = {})
token = payment_method_token(credit_card_or_vault_id, options)
return token if token.is_a?(Response)
purchase = Samurai::Processor.purchase(token, amount(money), processor_options(options))
handle_result(purchase)
end
|
#refund(money, transaction_id, options = {}) ⇒ Object
53
54
55
56
|
# File 'lib/active_merchant/billing/gateways/samurai.rb', line 53
def refund(money, transaction_id, options = {})
transaction = Samurai::Transaction.find(transaction_id)
handle_result(transaction.credit(amount(money)))
end
|
#store(creditcard, options = {}) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/active_merchant/billing/gateways/samurai.rb', line 63
def store(creditcard, options = {})
address = options[:billing_address] || options[:address] || {}
result = Samurai::PaymentMethod.create({
:card_number => creditcard.number,
:expiry_month => creditcard.month.to_s.rjust(2, "0"),
:expiry_year => creditcard.year.to_s,
:cvv => creditcard.verification_value,
:first_name => creditcard.first_name,
:last_name => creditcard.last_name,
:address_1 => address[:address1],
:address_2 => address[:address2],
:city => address[:city],
:zip => address[:zip],
:sandbox => test?
})
result.retain if options[:retain] && result.is_sensitive_data_valid && result.payment_method_token
Response.new(result.is_sensitive_data_valid,
message_from_result(result),
{ :payment_method_token => result.is_sensitive_data_valid && result.payment_method_token })
end
|
#test? ⇒ Boolean
28
29
30
|
# File 'lib/active_merchant/billing/gateways/samurai.rb', line 28
def test?
@options[:test] || super
end
|
#void(transaction_id, options = {}) ⇒ Object
58
59
60
61
|
# File 'lib/active_merchant/billing/gateways/samurai.rb', line 58
def void(transaction_id, options = {})
transaction = Samurai::Transaction.find(transaction_id)
handle_result(transaction.void)
end
|