class ActiveMerchant::Billing::InstapayGateway
Constants
- SUCCESS
- SUCCESS_MESSAGE
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/instapay.rb, line 22 def initialize(options = {}) requires!(options, :login) super end
Public Instance Methods
capture(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/instapay.rb, line 50 def capture(money, authorization, options = {}) post = {} add_amount(post, money) add_reference(post, authorization) commit('ns_quicksale_cc', post) end
purchase(money, creditcard, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/instapay.rb, line 39 def purchase(money, creditcard, options = {}) post = {} add_amount(post, money) add_invoice(post, options) add_creditcard(post, creditcard) add_address(post, options) add_customer_data(post, options) commit('ns_quicksale_cc', post) end
Private Instance Methods
add_address(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/instapay.rb, line 72 def add_address(post, options) if address = options[:billing_address] || options[:address] post[:ci_billaddr1] = address[:address1] post[:ci_billaddr2] = address[:address2] post[:ci_billcity] = address[:city] post[:ci_billstate] = address[:state] post[:ci_billzip] = address[:zip] post[:ci_billcountry] = address[:country] post[:ci_phone] = address[:phone] end if address = options[:shipping_address] post[:ci_shipaddr1] = address[:address1] post[:ci_shipaddr2] = address[:address2] post[:ci_shipcity] = address[:city] post[:ci_shipstate] = address[:state] post[:ci_shipzip] = address[:zip] post[:ci_shipcountry] = address[:country] end end
add_amount(post, money)
click to toggle source
# File lib/active_merchant/billing/gateways/instapay.rb, line 59 def add_amount(post, money) post[:amount] = amount(money) end
add_creditcard(post, creditcard)
click to toggle source
# File lib/active_merchant/billing/gateways/instapay.rb, line 99 def add_creditcard(post, creditcard) post[:ccnum] = creditcard.number post[:expmon] = format(creditcard.month, :two_digits) post[:cvv2] = creditcard.verification_value if creditcard.verification_value? post[:expyear] = creditcard.year post[:ccname] = creditcard.name end
add_customer_data(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/instapay.rb, line 67 def add_customer_data(post, options) post[:ci_email] = options[:email] post["ci_IP Address"] = options[:ip] end
add_invoice(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/instapay.rb, line 93 def add_invoice(post, options) post[:merchantordernumber] = options[:order_id] post[:ci_memo] = options[:description] post[:pocustomerrefid] = options[:invoice] end
add_reference(post, reference)
click to toggle source
# File lib/active_merchant/billing/gateways/instapay.rb, line 63 def add_reference(post, reference) post[:postonly] = reference end
commit(action, parameters)
click to toggle source
# File lib/active_merchant/billing/gateways/instapay.rb, line 139 def commit(action, parameters) data = ssl_post self.live_url, post_data(action, parameters) response = parse(data) Response.new(response[:success] , response[:message], response, :authorization => response[:transaction_id], :avs_result => { :code => response[:avs_result] }, :cvv_result => response[:cvv_result] ) end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/instapay.rb, line 107 def parse(body) results = {} fields = body.split("\r\n") response = fields[1].split('=') response_data = response[1].split(':') if response[0] == SUCCESS results[:success] = true results[:message] = SUCCESS_MESSAGE results[:transaction_type] = response_data[0] results[:authorization_code] = response_data[1] results[:reference_number] = response_data[2] results[:batch_number] = response_data[3] results[:transaction_id] = response_data[4] results[:avs_result] = response_data[5] results[:authorize_net] = response_data[6] results[:cvv_result] = response_data[7] else results[:success] = false results[:result] = response_data[0] results[:response_code] = response_data[1] results[:message] = response_data[2] end fields[1..-1].each do |pair| key, value = pair.split('=') results[key] = value end results end
post_data(action, parameters = {})
click to toggle source
# File lib/active_merchant/billing/gateways/instapay.rb, line 150 def post_data(action, parameters = {}) post = {} post[:acctid] = @options[:login] if(@options[:password]) post[:merchantpin] = @options[:password] end post[:action] = action request = post.merge(parameters).collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&") request end