Class: ActiveMerchant::Billing::SamuraiGateway
- 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
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
- #void(transaction_id, options = {}) ⇒ Object
Methods inherited from Gateway
#card_brand, card_brand, inherited, supports?, #test?
Methods included from CreditCardFormatting
Constructor Details
#initialize(options = {}) ⇒ SamuraiGateway
Returns a new instance of SamuraiGateway.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/active_merchant/billing/gateways/samurai.rb', line 12 def initialize( = {}) begin require 'samurai' rescue LoadError raise "Could not load the samurai gem (>= 0.2.25). Use `gem install samurai` to install it." end requires!(, :login, :password, :processor_token) Samurai. = { :merchant_key => [:login], :merchant_password => [:password], :processor_token => [:processor_token] } super end |
Instance Method Details
#authorize(money, credit_card_or_vault_id, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/active_merchant/billing/gateways/samurai.rb', line 29 def (money, credit_card_or_vault_id, = {}) token = payment_method_token(credit_card_or_vault_id, ) return token if token.is_a?(Response) = Samurai::Processor.(token, amount(money), ()) handle_result() rescue ActiveResource::ServerError => e Response.new(false, e., {}, test: test?) end |
#capture(money, authorization_id, options = {}) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/active_merchant/billing/gateways/samurai.rb', line 49 def capture(money, , = {}) transaction = Samurai::Transaction.find() handle_result(transaction.capture(amount(money))) rescue ActiveResource::ServerError => e Response.new(false, e., {}, test: test?) end |
#purchase(money, credit_card_or_vault_id, options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/active_merchant/billing/gateways/samurai.rb', line 39 def purchase(money, credit_card_or_vault_id, = {}) token = payment_method_token(credit_card_or_vault_id, ) return token if token.is_a?(Response) purchase = Samurai::Processor.purchase(token, amount(money), ()) handle_result(purchase) rescue ActiveResource::ServerError => e Response.new(false, e., {}, test: test?) end |
#refund(money, transaction_id, options = {}) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/active_merchant/billing/gateways/samurai.rb', line 56 def refund(money, transaction_id, = {}) transaction = Samurai::Transaction.find(transaction_id) handle_result(transaction.credit(amount(money))) rescue ActiveResource::ServerError => e Response.new(false, e., {}, test: test?) end |
#store(creditcard, options = {}) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/active_merchant/billing/gateways/samurai.rb', line 70 def store(creditcard, = {}) address = [:billing_address] || [: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 [:retain] && result.is_sensitive_data_valid && result.payment_method_token Response.new(result.is_sensitive_data_valid, (result), { :payment_method_token => result.is_sensitive_data_valid && result.payment_method_token }) rescue ActiveResource::ServerError => e Response.new(false, e., {}, test: test?) end |
#void(transaction_id, options = {}) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/active_merchant/billing/gateways/samurai.rb', line 63 def void(transaction_id, = {}) transaction = Samurai::Transaction.find(transaction_id) handle_result(transaction.void) rescue ActiveResource::ServerError => e Response.new(false, e., {}, test: test?) end |