# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.