class ActiveMerchant::Billing::CommercegateGateway
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/commercegate.rb, line 18 def initialize(options = {}) requires!(options, :login, :password, :site_id, :offer_id) super end
Public Instance Methods
capture(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/commercegate.rb, line 30 def capture(money, authorization, options = {}) post = {} post[:currencyCode] = (options[:currency] || currency(money)) post[:amount] = amount(money) post[:transID] = authorization commit('CAPTURE', post) end
purchase(money, creditcard, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/commercegate.rb, line 38 def purchase(money, creditcard, options = {}) post = {} add_creditcard(post, creditcard) add_auth_purchase_options(post, money, options) commit('SALE', post) end
refund(money, identification, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/commercegate.rb, line 45 def refund(money, identification, options = {}) post = {} post[:currencyCode] = options[:currency] || currency(money) post[:amount] = amount(money) post[:transID] = identification commit('REFUND', post) end
void(identification, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/commercegate.rb, line 53 def void(identification, options = {}) post = {} post[:transID] = identification commit('VOID_AUTH', post) end
Private Instance Methods
add_address(post, address)
click to toggle source
# File lib/active_merchant/billing/gateways/commercegate.rb, line 61 def add_address(post, address) if address post[:address] = address[:address1] post[:city] = address[:city] post[:state] = address[:state] post[:postalCode] = address[:zip] end post[:countryCode] = ((address && address[:country]) || 'US') end
add_auth_purchase_options(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/commercegate.rb, line 71 def add_auth_purchase_options(post, money, options) add_address(post, options[:address]) post[:customerIP] = options[:ip] || '127.0.0.1' post[:amount] = amount(money) post[:email] = options[:email] || 'unknown@example.com' post[:currencyCode] = options[:currency] || currency(money) post[:merchAcct] = options[:merchant] end
add_creditcard(params, creditcard)
click to toggle source
# File lib/active_merchant/billing/gateways/commercegate.rb, line 81 def add_creditcard(params, creditcard) params[:firstName] = creditcard.first_name params[:lastName] = creditcard.last_name params[:cardNumber] = creditcard.number params[:expiryMonth] = creditcard.month params[:expiryYear] = creditcard.year params[:cvv] = creditcard.verification_value if creditcard.verification_value? end
commit(action, parameters)
click to toggle source
# File lib/active_merchant/billing/gateways/commercegate.rb, line 90 def commit(action, parameters) parameters[:apiUsername] = @options[:login] parameters[:apiPassword] = @options[:password] parameters[:siteID] = @options[:site_id] parameters[:offerID] = @options[:offer_id] parameters[:action] = action response = parse(ssl_post(self.live_url, post_data(parameters))) Response.new( successful?(response), message_from(response), response, authorization: response['transID'], test: test?, avs_result: { code: response['avsCode'] }, cvv_result: response['cvvCode'] ) end
message_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/commercegate.rb, line 125 def message_from(response) if response['returnText'].present? response['returnText'] else 'Invalid response received from the CommerceGate API. ' \ 'Please contact CommerceGate support if you continue to receive this message. ' \ "(The raw response returned by the API was #{response.inspect})" end end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/commercegate.rb, line 110 def parse(body) results = {} body.split(/\&/).each do |pair| key, val = pair.split(%r{=}) results[key] = CGI.unescape(val) end results end
post_data(parameters)
click to toggle source
# File lib/active_merchant/billing/gateways/commercegate.rb, line 135 def post_data(parameters) parameters.collect do |key, value| "#{key}=#{CGI.escape(value.to_s)}" end.join('&') end
successful?(response)
click to toggle source
# File lib/active_merchant/billing/gateways/commercegate.rb, line 121 def successful?(response) response['returnCode'] == '0' end