class ActiveMerchant::Billing::InspireGateway
Public Class Methods
new(options = {})
click to toggle source
Creates a new InspireGateway
The gateway requires that a valid login and password be passed in the options
hash.
Options¶ ↑
-
:login
– The Inspire Username. -
:password
– The Inspire Passowrd.
See the Inspire Integration Guide for details. (default: false
)
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/inspire.rb, line 22 def initialize(options = {}) requires!(options, :login, :password) super end
Public Instance Methods
capture(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/inspire.rb, line 53 def capture(money, authorization, options = {}) post ={} post[:transactionid] = authorization commit('capture', money, post) end
delete(vault_id)
click to toggle source
# File lib/active_merchant/billing/gateways/inspire.rb, line 85 def delete(vault_id) post = {} post[:customer_vault] = "delete_customer" add_customer_vault_id(post, vault_id) commit(nil, nil, post) end
Also aliased as: unstore
purchase(money, payment_source, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/inspire.rb, line 43 def purchase(money, payment_source, options = {}) post = {} add_invoice(post, options) add_payment_source(post, payment_source, options) add_address(post, payment_source, options) add_customer_data(post, options) commit('sale', money, post) end
refund(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/inspire.rb, line 65 def refund(money, authorization, options = {}) post = {} post[:transactionid] = authorization commit('refund', money, post) end
store(creditcard, options = {})
click to toggle source
To match the other stored-value gateways, like TrustCommerce, store and unstore need to be defined
# File lib/active_merchant/billing/gateways/inspire.rb, line 94 def store(creditcard, options = {}) billing_id = options.delete(:billing_id).to_s || true authorize(100, creditcard, options.merge(:store => billing_id)) end
update(vault_id, creditcard, options = {})
click to toggle source
Update the values (such as CC expiration) stored at InspireGateway
. The CC number must be supplied in the CreditCard
object.
# File lib/active_merchant/billing/gateways/inspire.rb, line 74 def update(vault_id, creditcard, options = {}) post = {} post[:customer_vault] = "update_customer" add_customer_vault_id(post, vault_id) add_creditcard(post, creditcard, options) add_address(post, creditcard, options) add_customer_data(post, options) commit(nil, nil, post) end
void(authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/inspire.rb, line 59 def void(authorization, options = {}) post ={} post[:transactionid] = authorization commit('void', nil, post) end
Private Instance Methods
add_address(post, creditcard, options)
click to toggle source
# File lib/active_merchant/billing/gateways/inspire.rb, line 112 def add_address(post, creditcard, options) if address = options[:billing_address] || options[:address] post[:address1] = address[:address1].to_s post[:address2] = address[:address2].to_s unless address[:address2].blank? post[:company] = address[:company].to_s post[:phone] = address[:phone].to_s post[:zip] = address[:zip].to_s post[:city] = address[:city].to_s post[:country] = address[:country].to_s post[:state] = address[:state].blank? ? 'n/a' : address[:state] end end
add_check(post, check)
click to toggle source
# File lib/active_merchant/billing/gateways/inspire.rb, line 154 def add_check(post, check) post[:payment] = 'check' # Set transaction to ACH post[:checkname] = check.name # The name on the customer's Checking Account post[:checkaba] = check.routing_number # The customer's bank routing number post[:checkaccount] = check.account_number # The customer's account number post[:account_holder_type] = check.account_holder_type # The customer's type of ACH account post[:account_type] = check.account_type # The customer's type of ACH account end
add_creditcard(post, creditcard,options)
click to toggle source
# File lib/active_merchant/billing/gateways/inspire.rb, line 142 def add_creditcard(post, creditcard,options) if options[:store] post[:customer_vault] = "add_customer" post[:customer_vault_id] = options[:store] unless options[:store] == true end post[:ccnumber] = creditcard.number post[:cvv] = creditcard.verification_value if creditcard.verification_value? post[:ccexp] = expdate(creditcard) post[:firstname] = creditcard.first_name post[:lastname] = creditcard.last_name end
add_customer_data(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/inspire.rb, line 102 def add_customer_data(post, options) if options.has_key? :email post[:email] = options[:email] end if options.has_key? :ip post[:ipaddress] = options[:ip] end end
add_customer_vault_id(params,vault_id)
click to toggle source
# File lib/active_merchant/billing/gateways/inspire.rb, line 138 def add_customer_vault_id(params,vault_id) params[:customer_vault_id] = vault_id end
add_invoice(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/inspire.rb, line 125 def add_invoice(post, options) post[:orderid] = options[:order_id].to_s.gsub(/[^\w.]/, '') post[:orderdescription] = options[:description] end
add_payment_source(params, source, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/inspire.rb, line 130 def add_payment_source(params, source, options={}) case determine_funding_source(source) when :vault then add_customer_vault_id(params, source) when :credit_card then add_creditcard(params, source, options) when :check then add_check(params, source) end end
commit(action, money, parameters)
click to toggle source
# File lib/active_merchant/billing/gateways/inspire.rb, line 173 def commit(action, money, parameters) parameters[:amount] = amount(money) if money response = parse( ssl_post(self.live_url, post_data(action,parameters)) ) Response.new(response["response"] == "1", message_from(response), response, :authorization => response["transactionid"], :test => test?, :cvv_result => response["cvvresponse"], :avs_result => { :code => response["avsresponse"] } ) end
determine_funding_source(source)
click to toggle source
# File lib/active_merchant/billing/gateways/inspire.rb, line 208 def determine_funding_source(source) case when source.is_a?(String) then :vault when CreditCard.card_companies.keys.include?(card_brand(source)) then :credit_card when card_brand(source) == 'check' then :check else raise ArgumentError, "Unsupported funding source provided" end end
message_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/inspire.rb, line 187 def message_from(response) case response["responsetext"] when "SUCCESS","Approved" "This transaction has been approved" when "DECLINE" "This transaction has been declined" else response["responsetext"] end end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/inspire.rb, line 163 def parse(body) results = {} body.split(/&/).each do |pair| key,val = pair.split(%r{=}) results[key] = val end results end
post_data(action, parameters = {})
click to toggle source
# File lib/active_merchant/billing/gateways/inspire.rb, line 198 def post_data(action, parameters = {}) post = {} post[:username] = @options[:login] post[:password] = @options[:password] post[:type] = action if action request = post.merge(parameters).map {|key,value| "#{key}=#{CGI.escape(value.to_s)}"}.join("&") request end