class ActiveMerchant::Billing::NetworkMerchantsGateway
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 15 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/network_merchants.rb, line 30 def capture(money, authorization, options = {}) post = build_capture_post(money, authorization, options) commit('capture', post) end
purchase(money, creditcard_or_vault_id, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 25 def purchase(money, creditcard_or_vault_id, options = {}) post = build_purchase_post(money, creditcard_or_vault_id, options) commit('sale', post) end
refund(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 40 def refund(money, authorization, options = {}) post = build_refund_post(money, authorization, options) commit('refund', post) end
store(creditcard, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 45 def store(creditcard, options = {}) post = build_store_post(creditcard, options) commit_vault('add_customer', post) end
unstore(customer_vault_id, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 50 def unstore(customer_vault_id, options = {}) post = build_unstore_post(customer_vault_id, options) commit_vault('delete_customer', post) end
void(authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 35 def void(authorization, options = {}) post = build_void_post(authorization, options) commit('void', post) end
Private Instance Methods
add_address(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 110 def add_address(post, options) post[:email] = options[:email] post[:ipaddress] = options[:ip] address = options[:billing_address] || options[:address] || {} post[:address1] = address[:address1] post[:address2] = address[:address2] post[:city] = address[:city] post[:state] = address[:state].blank? ? 'n/a' : address[:state] post[:zip] = address[:zip] post[:country] = address[:country] post[:phone] = address[:phone] end
add_amount(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 187 def add_amount(post, money, options) post[:currency] = options[:currency] || currency(money) post[:amount] = amount(money) end
add_login(post)
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 182 def add_login(post) post[:username] = @options[:login] post[:password] = @options[:password] end
add_order(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 105 def add_order(post, options) post[:orderid] = options[:order_id] post[:orderdescription] = options[:description] end
add_payment_method(post, payment_source, options)
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 153 def add_payment_method(post, payment_source, options) post[:processor_id] = options[:processor_id] post[:customer_vault] = 'add_customer' if options[:store] add_swipe_data(post, payment_source, options) if payment_source.is_a?(Check) check = payment_source post[:firstname] = check.first_name post[:lastname] = check.last_name post[:checkname] = check.name post[:checkaba] = check.routing_number post[:checkaccount] = check.account_number post[:account_type] = check.account_type post[:account_holder_type] = check.account_holder_type post[:payment] = 'check' elsif payment_source.respond_to?(:number) creditcard = payment_source post[:firstname] = creditcard.first_name post[:lastname] = creditcard.last_name post[:ccnumber] = creditcard.number post[:ccexp] = format(creditcard.month, :two_digits) + format(creditcard.year, :two_digits) post[:cvv] = creditcard.verification_value post[:payment] = 'creditcard' else post[:customer_vault_id] = payment_source end end
add_shipping_address(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 124 def add_shipping_address(post, options) shipping_address = options[:shipping_address] || {} post[:shipping_address1] = shipping_address[:address1] post[:shipping_address2] = shipping_address[:address2] post[:shipping_city] = shipping_address[:city] post[:shipping_state] = shipping_address[:state] post[:shipping_zip] = shipping_address[:zip] post[:shipping_country] = shipping_address[:country] end
add_swipe_data(post, creditcard, options)
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 134 def add_swipe_data(post, creditcard, options) # unencrypted tracks if creditcard.respond_to?(:track_data) && creditcard.track_data.present? post[:track_1] = creditcard.track_data else post[:track_1] = options[:track_1] post[:track_2] = options[:track_2] post[:track_3] = options[:track_3] end # encrypted tracks post[:magnesafe_track_1] = options[:magnesafe_track_1] post[:magnesafe_track_2] = options[:magnesafe_track_2] post[:magnesafe_track_3] = options[:magnesafe_track_3] post[:magnesafe_magneprint] = options[:magnesafe_magneprint] post[:magnesafe_ksn] = options[:magnesafe_ksn] post[:magnesafe_magneprint_status] = options[:magnesafe_magneprint_status] end
build_auth_post(money, creditcard_or_vault_id, options)
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 57 def build_auth_post(money, creditcard_or_vault_id, options) post = {} add_order(post, options) add_address(post, options) add_shipping_address(post, options) add_payment_method(post, creditcard_or_vault_id, options) add_amount(post, money, options) post end
build_capture_post(money, authorization, options)
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 71 def build_capture_post(money, authorization, options) post = {} post[:transactionid] = authorization add_amount(post, money, options) post end
build_purchase_post(money, creditcard, options)
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 67 def build_purchase_post(money, creditcard, options) build_auth_post(money, creditcard, options) end
build_refund_post(money, authorization, options)
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 84 def build_refund_post(money, authorization, options) post = {} post[:transactionid] = authorization add_amount(post, money, options) post end
build_request(action, parameters)
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 214 def build_request(action, parameters) parameters[:type] = action if action add_login(parameters) parameters.to_query end
build_store_post(creditcard_or_check, options)
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 91 def build_store_post(creditcard_or_check, options) post = {} add_address(post, options) add_shipping_address(post, options) add_payment_method(post, creditcard_or_check, options) post end
build_unstore_post(customer_vault_id, options)
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 99 def build_unstore_post(customer_vault_id, options) post = {} post['customer_vault_id'] = customer_vault_id post end
build_void_post(authorization, options)
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 78 def build_void_post(authorization, options) post = {} post[:transactionid] = authorization post end
commit(action, parameters)
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 196 def commit(action, parameters) raw = parse(ssl_post(self.live_url, build_request(action, parameters))) success = (raw['response'] == ResponseCodes::APPROVED) authorization = authorization_from(success, parameters, raw) Response.new( success, raw['responsetext'], raw, test: test?, authorization: authorization, avs_result: { code: raw['avsresponse'] }, cvv_result: raw['cvvresponse'] ) end
commit_vault(action, parameters)
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 192 def commit_vault(action, parameters) commit(nil, parameters.merge(customer_vault: action)) end
parse(raw_response)
click to toggle source
# File lib/active_merchant/billing/gateways/network_merchants.rb, line 235 def parse(raw_response) rsp = CGI.parse(raw_response) rsp.keys.each { |k| rsp[k] = rsp[k].first } # flatten out the values rsp end