class ActiveMerchant::Billing::CashnetGateway
Constants
- CASHNET_CODES
Public Class Methods
new(options = {})
click to toggle source
Creates a new CashnetGateway
Options¶ ↑
-
:merchant
–Gateway
Merchant (REQUIRED) -
:operator
– Operator (REQUIRED) -
:password
– Password (REQUIRED) -
:merchant_gateway_name
– Site name (REQUIRED) -
:station
– Station (defaults to “WEB”) -
:custcode
– Customer code (defaults to “ActiveMerchant/#{ActiveMerchant::VERSION}”) -
:default_item_code
– Default item code (defaults to “FEE”, can be overridden on a per-transaction basis with options)
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/cashnet.rb, line 29 def initialize(options = {}) requires!( options, :merchant, :operator, :password, :merchant_gateway_name ) options[:default_item_code] ||= 'FEE' super end
Public Instance Methods
purchase(money, payment_object, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/cashnet.rb, line 41 def purchase(money, payment_object, options = {}) post = {} add_creditcard(post, payment_object) add_invoice(post, money, options) add_address(post, options) add_customer_data(post, options) commit('SALE', money, post) end
refund(money, identification, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/cashnet.rb, line 50 def refund(money, identification, options = {}) post = {} post[:origtx] = identification add_invoice(post, money, options) add_customer_data(post, options) commit('REFUND', money, post) end
scrub(transcript)
click to toggle source
# File lib/active_merchant/billing/gateways/cashnet.rb, line 62 def scrub(transcript) transcript. gsub(%r{(password=)[^&]+}, '\1[FILTERED]'). gsub(%r{(cardno=)[^&]+}, '\1[FILTERED]'). gsub(%r{(cid=)[^&]+}, '\1[FILTERED]') end
supports_scrubbing?()
click to toggle source
# File lib/active_merchant/billing/gateways/cashnet.rb, line 58 def supports_scrubbing? true end
Private Instance Methods
add_address(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/cashnet.rb, line 128 def add_address(post, options) if address = (options[:shipping_address] || options[:billing_address] || options[:address]) post[:addr_g] = String(address[:address1]) + ',' + String(address[:address2]) post[:city_g] = address[:city] post[:state_g] = address[:state] post[:zip_g] = address[:zip] end end
add_creditcard(post, creditcard)
click to toggle source
# File lib/active_merchant/billing/gateways/cashnet.rb, line 104 def add_creditcard(post, creditcard) post[:cardno] = creditcard.number post[:cid] = creditcard.verification_value post[:expdate] = expdate(creditcard) post[:card_name_g] = creditcard.name post[:fname] = creditcard.first_name post[:lname] = creditcard.last_name end
add_customer_data(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/cashnet.rb, line 137 def add_customer_data(post, options) post[:email_g] = options[:email] post[:custcode] = options[:custcode] unless empty?(options[:custcode]) end
add_invoice(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/cashnet.rb, line 113 def add_invoice(post, money, options) post[:order_number] = options[:order_id] if options[:order_id].present? if options[:item_codes].present? codes_and_amounts = options[:item_codes].transform_keys { |key| key.to_s.delete('_') } codes_and_amounts.each do |key, value| post[key] = value if key.start_with?('itemcode') post[key] = amount(value.to_i) if key.start_with?('amount') end else post[:itemcode] = (options[:item_code] || @options[:default_item_code]) post[:amount] = amount(money.to_i) end end
commit(action, money, fields)
click to toggle source
# File lib/active_merchant/billing/gateways/cashnet.rb, line 71 def commit(action, money, fields) url = (test? ? test_url : live_url) + CGI.escape(@options[:merchant_gateway_name]) raw_response = ssl_post(url, post_data(action, fields)) parsed_response = parse(raw_response) return unparsable_response(raw_response) unless parsed_response success = success?(parsed_response) Response.new( success, CASHNET_CODES[parsed_response[:result]], parsed_response, test: test?, authorization: (success ? parsed_response[:tx] : '') ) end
expdate(creditcard)
click to toggle source
# File lib/active_merchant/billing/gateways/cashnet.rb, line 142 def expdate(creditcard) year = format(creditcard.year, :two_digits) month = format(creditcard.month, :two_digits) "#{month}#{year}" end
handle_response(response)
click to toggle source
# File lib/active_merchant/billing/gateways/cashnet.rb, line 156 def handle_response(response) if (200...300).cover?(response.code.to_i) return response.body elsif response.code.to_i == 302 return ssl_get(URI.parse(response['location'])) end raise ResponseError.new(response) end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/cashnet.rb, line 149 def parse(body) match = body.match(/<cngateway>(.*)<\/cngateway>/) return nil unless match CGI::parse(match[1]).map { |k, v| [k.to_sym, v.first] }.to_h end
post_data(action, parameters = {})
click to toggle source
# File lib/active_merchant/billing/gateways/cashnet.rb, line 92 def post_data(action, parameters = {}) post = {} post[:command] = action post[:merchant] = @options[:merchant] post[:operator] = @options[:operator] post[:password] = @options[:password] post[:station] = (@options[:station] || 'WEB') post[:custcode] = (@options[:custcode] || "ActiveMerchant/#{ActiveMerchant::VERSION}") post.merge(parameters).collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join('&') end
success?(response)
click to toggle source
# File lib/active_merchant/billing/gateways/cashnet.rb, line 88 def success?(response) response[:result] == '0' end
unparsable_response(raw_response)
click to toggle source
# File lib/active_merchant/billing/gateways/cashnet.rb, line 166 def unparsable_response(raw_response) message = 'Unparsable response received from Cashnet. Please contact Cashnet if you continue to receive this message.' message += " (The raw response returned by the API was #{raw_response.inspect})" return Response.new(false, message) end