Creates a new InspireGateway
The gateway requires that a valid login and password be passed in the options hash.
:login — The Inspire Username.
:password — The Inspire Passowrd.
See the Inspire Integration Guide for details. (default: false)
# File lib/active_merchant/billing/gateways/inspire.rb, line 21 21: def initialize(options = {}) 22: requires!(options, :login, :password) 23: @options = options 24: super 25: end
# File lib/active_merchant/billing/gateways/inspire.rb, line 53 53: def capture(money, authorization, options = {}) 54: post ={} 55: post[:transactionid] = authorization 56: commit('capture', money, post) 57: end
# File lib/active_merchant/billing/gateways/inspire.rb, line 79 79: def delete(vault_id) 80: post = {} 81: post[:customer_vault] = "delete_customer" 82: add_customer_vault_id(post, vault_id) 83: commit(nil, nil, post) 84: end
# File lib/active_merchant/billing/gateways/inspire.rb, line 43 43: def purchase(money, payment_source, options = {}) 44: post = {} 45: add_invoice(post, options) 46: add_payment_source(post, payment_source, options) 47: add_address(post, payment_source, options) 48: add_customer_data(post, options) 49: 50: commit('sale', money, post) 51: end
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 88 88: def store(creditcard, options = {}) 89: billing_id = options.delete(:billing_id).to_s || true 90: authorize(100, creditcard, options.merge(:store => billing_id)) 91: end
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 68 68: def update(vault_id, creditcard, options = {}) 69: post = {} 70: post[:customer_vault] = "update_customer" 71: add_customer_vault_id(post, vault_id) 72: add_creditcard(post, creditcard, options) 73: add_address(post, creditcard, options) 74: add_customer_data(post, options) 75: 76: commit(nil, nil, post) 77: end
# File lib/active_merchant/billing/gateways/inspire.rb, line 106 106: def add_address(post, creditcard, options) 107: if address = options[:billing_address] || options[:address] 108: post[:address1] = address[:address1].to_s 109: post[:address2] = address[:address2].to_s unless address[:address2].blank? 110: post[:company] = address[:company].to_s 111: post[:phone] = address[:phone].to_s 112: post[:zip] = address[:zip].to_s 113: post[:city] = address[:city].to_s 114: post[:country] = address[:country].to_s 115: post[:state] = address[:state].blank? ? 'n/a' : address[:state] 116: end 117: end
# File lib/active_merchant/billing/gateways/inspire.rb, line 148 148: def add_check(post, check) 149: post[:payment] = 'check' # Set transaction to ACH 150: post[:checkname] = check.name # The name on the customer's Checking Account 151: post[:checkaba] = check.routing_number # The customer's bank routing number 152: post[:checkaccount] = check.account_number # The customer's account number 153: post[:account_holder_type] = check.account_holder_type # The customer's type of ACH account 154: post[:account_type] = check.account_type # The customer's type of ACH account 155: end
# File lib/active_merchant/billing/gateways/inspire.rb, line 136 136: def add_creditcard(post, creditcard,options) 137: if options[:store] 138: post[:customer_vault] = "add_customer" 139: post[:customer_vault_id] = options[:store] unless options[:store] == true 140: end 141: post[:ccnumber] = creditcard.number 142: post[:cvv] = creditcard.verification_value if creditcard.verification_value? 143: post[:ccexp] = expdate(creditcard) 144: post[:firstname] = creditcard.first_name 145: post[:lastname] = creditcard.last_name 146: end
# File lib/active_merchant/billing/gateways/inspire.rb, line 96 96: def add_customer_data(post, options) 97: if options.has_key? :email 98: post[:email] = options[:email] 99: end 100: 101: if options.has_key? :ip 102: post[:ipaddress] = options[:ip] 103: end 104: end
# File lib/active_merchant/billing/gateways/inspire.rb, line 132 132: def add_customer_vault_id(params,vault_id) 133: params[:customer_vault_id] = vault_id 134: end
# File lib/active_merchant/billing/gateways/inspire.rb, line 119 119: def add_invoice(post, options) 120: post[:orderid] = options[:order_id].to_s.gsub(/[^\w.]/, '') 121: post[:orderdescription] = options[:description] 122: end
# File lib/active_merchant/billing/gateways/inspire.rb, line 124 124: def add_payment_source(params, source, options={}) 125: case determine_funding_source(source) 126: when :vault then add_customer_vault_id(params, source) 127: when :credit_card then add_creditcard(params, source, options) 128: when :check then add_check(params, source) 129: end 130: end
# File lib/active_merchant/billing/gateways/inspire.rb, line 167 167: def commit(action, money, parameters) 168: parameters[:amount] = amount(money) if money 169: 170: response = parse( ssl_post(URL, post_data(action,parameters)) ) 171: 172: Response.new(response["response"] == "1", message_from(response), response, 173: :authorization => response["transactionid"], 174: :test => test?, 175: :cvv_result => response["cvvresponse"], 176: :avs_result => { :code => response["avsresponse"] } 177: ) 178: 179: end
# File lib/active_merchant/billing/gateways/inspire.rb, line 210 210: def determine_funding_source(source) 211: case 212: when source.is_a?(String) then :vault 213: when CreditCard.card_companies.keys.include?(card_brand(source)) then :credit_card 214: when card_brand(source) == 'check' then :check 215: else raise ArgumentError, "Unsupported funding source provided" 216: end 217: end
# File lib/active_merchant/billing/gateways/inspire.rb, line 181 181: def expdate(creditcard) 182: year = sprintf("%.4i", creditcard.year) 183: month = sprintf("%.2i", creditcard.month) 184: 185: "#{month}#{year[-2..-1]}" 186: end
# File lib/active_merchant/billing/gateways/inspire.rb, line 189 189: def message_from(response) 190: case response["responsetext"] 191: when "SUCCESS","Approved" 192: "This transaction has been approved" 193: when "DECLINE" 194: "This transaction has been declined" 195: else 196: response["responsetext"] 197: end 198: end
# File lib/active_merchant/billing/gateways/inspire.rb, line 157 157: def parse(body) 158: results = {} 159: body.split(/&/).each do |pair| 160: key,val = pair.split(/=/) 161: results[key] = val 162: end 163: 164: results 165: end
# File lib/active_merchant/billing/gateways/inspire.rb, line 200 200: def post_data(action, parameters = {}) 201: post = {} 202: post[:username] = @options[:login] 203: post[:password] = @options[:password] 204: post[:type] = action if action 205: 206: request = post.merge(parameters).map {|key,value| "#{key}=#{CGI.escape(value.to_s)}"}.join("&") 207: request 208: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.