Class Index [+]

Quicksearch

ActiveMerchant::Billing::SamuraiGateway

Public Class Methods

new(options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/samurai.rb, line 12
12:       def initialize(options = {})
13:         begin
14:           require 'samurai'
15:         rescue LoadError
16:           raise "Could not load the samurai gem (>= 0.2.25).  Use `gem install samurai` to install it."
17:         end
18: 
19:         requires!(options, :login, :password, :processor_token)
20:         @options = options
21:         Samurai.options = {
22:           :merchant_key       => options[:login],
23:           :merchant_password  => options[:password],
24:           :processor_token    => options[:processor_token]
25:         }
26:       end

Public Instance Methods

authorize(money, credit_card_or_vault_id, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/samurai.rb, line 32
32:       def authorize(money, credit_card_or_vault_id, options = {})
33:         token = payment_method_token(credit_card_or_vault_id, options)
34:         return token if token.is_a?(Response)
35: 
36:         authorize = Samurai::Processor.authorize(token, amount(money), processor_options(options))
37:         handle_result(authorize)
38:       end
capture(money, authorization_id, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/samurai.rb, line 48
48:       def capture(money, authorization_id, options = {})
49:         transaction = Samurai::Transaction.find(authorization_id)
50:         handle_result(transaction.capture(amount(money)))
51:       end
purchase(money, credit_card_or_vault_id, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/samurai.rb, line 40
40:       def purchase(money, credit_card_or_vault_id, options = {})
41:         token = payment_method_token(credit_card_or_vault_id, options)
42:         return token if token.is_a?(Response)
43: 
44:         purchase = Samurai::Processor.purchase(token, amount(money), processor_options(options))
45:         handle_result(purchase)
46:       end
refund(money, transaction_id, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/samurai.rb, line 53
53:       def refund(money, transaction_id, options = {})
54:         transaction = Samurai::Transaction.find(transaction_id)
55:         handle_result(transaction.credit(amount(money)))
56:       end
store(creditcard, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/samurai.rb, line 63
63:       def store(creditcard, options = {})
64:         address = options[:billing_address] || options[:address] || {}
65: 
66:         result = Samurai::PaymentMethod.create({
67:           :card_number  => creditcard.number,
68:           :expiry_month => creditcard.month.to_s.rjust(2, "0"),
69:           :expiry_year  => creditcard.year.to_s,
70:           :cvv          => creditcard.verification_value,
71:           :first_name   => creditcard.first_name,
72:           :last_name    => creditcard.last_name,
73:           :address_1    => address[:address1],
74:           :address_2    => address[:address2],
75:           :city         => address[:city],
76:           :zip          => address[:zip],
77:           :sandbox      => test?
78:         })
79: 
80:         Response.new(result.is_sensitive_data_valid,
81:                      message_from_result(result),
82:                      { :payment_method_token => result.is_sensitive_data_valid && result.payment_method_token })
83:       end
test?() click to toggle source
    # File lib/active_merchant/billing/gateways/samurai.rb, line 28
28:       def test?
29:         @options[:test] || super
30:       end
void(transaction_id, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/samurai.rb, line 58
58:       def void(transaction_id, options = {})
59:         transaction = Samurai::Transaction.find(transaction_id)
60:         handle_result(transaction.void)
61:       end

Private Instance Methods

handle_result(result) click to toggle source
     # File lib/active_merchant/billing/gateways/samurai.rb, line 93
 93:       def handle_result(result)
 94:         response_params, response_options = {}, {}
 95:         if result.success?
 96:           response_options[:test] = test?
 97:           response_options[:authorization] = result.reference_id
 98:           response_params[:reference_id] = result.reference_id
 99:           response_params[:transaction_token] = result.transaction_token
100:           response_params[:payment_method_token] = result.payment_method.payment_method_token
101:         end
102: 
103:         response_options[:avs_result] = { :code => result.processor_response && result.processor_response.avs_result_code }
104:         response_options[:cvv_result] = result.processor_response && result.processor_response.cvv_result_code
105: 
106:         message = message_from_result(result)
107:         Response.new(result.success?, message, response_params, response_options)
108:       end
message_from_result(result) click to toggle source
     # File lib/active_merchant/billing/gateways/samurai.rb, line 110
110:       def message_from_result(result)
111:         return "OK" if result.success?
112:         result.errors.map {|_, messages| messages }.join(" ")
113:       end
payment_method_token(credit_card_or_vault_id, options) click to toggle source
    # File lib/active_merchant/billing/gateways/samurai.rb, line 87
87:       def payment_method_token(credit_card_or_vault_id, options)
88:         return credit_card_or_vault_id if credit_card_or_vault_id.is_a?(String)
89:         store_result = store(credit_card_or_vault_id, options)
90:         store_result.success? ? store_result.params["payment_method_token"] : store_result
91:       end
processor_options(options) click to toggle source
     # File lib/active_merchant/billing/gateways/samurai.rb, line 115
115:       def processor_options(options)
116:         options.slice(:billing_reference, :customer_reference, :custom, :descriptor)
117:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.