class ActiveMerchant::Billing::NmiGateway
Constants
- DUP_WINDOW_DEPRECATION_MESSAGE
Public Class Methods
duplicate_window()
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 21 def self.duplicate_window instance_variable_defined?(:@dup_seconds) ? @dup_seconds : nil end
duplicate_window=(seconds)
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 16 def self.duplicate_window=(seconds) ActiveMerchant.deprecated(DUP_WINDOW_DEPRECATION_MESSAGE) @dup_seconds = seconds end
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/nmi.rb, line 25 def initialize(options = {}) requires!(options, :login, :password) super end
Public Instance Methods
capture(amount, authorization, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 56 def capture(amount, authorization, options={}) post = {} add_invoice(post, amount, options) add_reference(post, authorization) add_merchant_defined_fields(post, options) commit('capture', post) end
credit(amount, payment_method, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 82 def credit(amount, payment_method, options={}) post = {} add_invoice(post, amount, options) add_payment_method(post, payment_method, options) add_customer_data(post, options) add_vendor_data(post, options) add_level3_fields(post, options) commit('credit', post) end
purchase(amount, payment_method, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 30 def purchase(amount, payment_method, options={}) post = {} add_invoice(post, amount, options) add_payment_method(post, payment_method, options) add_stored_credential(post, options) add_customer_data(post, options) add_vendor_data(post, options) add_merchant_defined_fields(post, options) add_level3_fields(post, options) commit('sale', post) end
refund(amount, authorization, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 73 def refund(amount, authorization, options={}) post = {} add_invoice(post, amount, options) add_reference(post, authorization) add_payment_type(post, authorization) commit('refund', post) end
scrub(transcript)
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 124 def scrub(transcript) transcript. gsub(%r((password=)[^&\n]*), '\1[FILTERED]'). gsub(%r((ccnumber=)\d+), '\1[FILTERED]'). gsub(%r((cvv=)\d+), '\1[FILTERED]'). gsub(%r((checkaba=)\d+), '\1[FILTERED]'). gsub(%r((checkaccount=)\d+), '\1[FILTERED]'). gsub(%r((cryptogram=)[^&]+(&?)), '\1[FILTERED]\2') end
store(payment_method, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 104 def store(payment_method, options = {}) post = {} add_invoice(post, nil, options) add_payment_method(post, payment_method, options) add_customer_data(post, options) add_vendor_data(post, options) add_merchant_defined_fields(post, options) commit('add_customer', post) end
supports_network_tokenization?()
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 134 def supports_network_tokenization? true end
supports_scrubbing?()
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 120 def supports_scrubbing? true end
verify(payment_method, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 93 def verify(payment_method, options={}) post = {} add_payment_method(post, payment_method, options) add_customer_data(post, options) add_vendor_data(post, options) add_merchant_defined_fields(post, options) add_level3_fields(post, options) commit('validate', post) end
verify_credentials()
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 115 def verify_credentials response = void('0') response.message != 'Authentication Failed' end
void(authorization, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 65 def void(authorization, options={}) post = {} add_reference(post, authorization) add_payment_type(post, authorization) commit('void', post) end
Private Instance Methods
add_customer_data(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 211 def add_customer_data(post, options) post[:email] = options[:email] post[:ipaddress] = options[:ip] post[:customer_id] = options[:customer_id] || options[:customer] if(billing_address = options[:billing_address] || options[:address]) post[:company] = billing_address[:company] post[:address1] = billing_address[:address1] post[:address2] = billing_address[:address2] post[:city] = billing_address[:city] post[:state] = billing_address[:state] post[:country] = billing_address[:country] post[:zip] = billing_address[:zip] post[:phone] = billing_address[:phone] end if(shipping_address = options[:shipping_address]) post[:shipping_company] = shipping_address[:company] 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_country] = shipping_address[:country] post[:shipping_zip] = shipping_address[:zip] post[:shipping_phone] = shipping_address[:phone] end end
add_invoice(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 144 def add_invoice(post, money, options) post[:amount] = amount(money) post[:orderid] = options[:order_id] post[:orderdescription] = options[:description] post[:currency] = options[:currency] || currency(money) post[:billing_method] = 'recurring' if options[:recurring] if (dup_seconds = (options[:dup_seconds] || self.class.duplicate_window)) post[:dup_seconds] = dup_seconds end end
add_level3_fields(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 140 def add_level3_fields(post, options) add_fields_to_post_if_present(post, options, [:tax, :shipping, :ponumber]) end
add_merchant_defined_fields(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 244 def add_merchant_defined_fields(post, options) (1..20).each do |each| key = "merchant_defined_field_#{each}".to_sym post[key] = options[key] if options[key] end end
add_payment_method(post, payment_method, options)
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 155 def add_payment_method(post, payment_method, options) if(payment_method.is_a?(String)) customer_vault_id, _ = split_authorization(payment_method) post[:customer_vault_id] = customer_vault_id elsif payment_method.is_a?(NetworkTokenizationCreditCard) post[:ccnumber] = payment_method.number post[:ccexp] = exp_date(payment_method) post[:token_cryptogram] = payment_method.payment_cryptogram elsif(card_brand(payment_method) == 'check') post[:payment] = 'check' post[:firstname] = payment_method.first_name post[:lastname] = payment_method.last_name post[:checkname] = payment_method.name post[:checkaba] = payment_method.routing_number post[:checkaccount] = payment_method.account_number post[:account_holder_type] = payment_method.account_holder_type post[:account_type] = payment_method.account_type post[:sec_code] = options[:sec_code] || 'WEB' else post[:payment] = 'creditcard' post[:firstname] = payment_method.first_name post[:lastname] = payment_method.last_name post[:ccnumber] = payment_method.number post[:cvv] = payment_method.verification_value unless empty?(payment_method.verification_value) post[:ccexp] = exp_date(payment_method) end end
add_payment_type(post, authorization)
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 256 def add_payment_type(post, authorization) _, payment_type = split_authorization(authorization) post[:payment] = payment_type if payment_type end
add_reference(post, authorization)
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 251 def add_reference(post, authorization) transaction_id, _ = split_authorization(authorization) post[:transactionid] = transaction_id end
add_stored_credential(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 183 def add_stored_credential(post, options) return unless (stored_credential = options[:stored_credential]) if stored_credential[:initiator] == 'cardholder' post[:initiated_by] = 'customer' else post[:initiated_by] = 'merchant' end # :reason_type, when provided, overrides anything previously set in # post[:billing_method] (see `add_invoice` and the :recurring) option case stored_credential[:reason_type] when 'recurring' post[:billing_method] = 'recurring' when 'installment' post[:billing_method] = 'installment' when 'unscheduled' post.delete(:billing_method) end if stored_credential[:initial_transaction] post[:stored_credential_indicator] = 'stored' else post[:stored_credential_indicator] = 'used' post[:initial_transaction_id] = stored_credential[:network_transaction_id] end end
add_vendor_data(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 239 def add_vendor_data(post, options) post[:vendor_id] = options[:vendor_id] if options[:vendor_id] post[:processor_id] = options[:processor_id] if options[:processor_id] end
commit(action, params)
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 265 def commit(action, params) params[action == 'add_customer' ? :customer_vault : :type] = action params[:username] = @options[:login] params[:password] = @options[:password] raw_response = ssl_post(url, post_data(action, params), headers) response = parse(raw_response) succeeded = success_from(response) Response.new( succeeded, message_from(succeeded, response), response, authorization: authorization_from(response, params[:payment], action), avs_result: AVSResult.new(code: response[:avsresponse]), cvv_result: CVVResult.new(response[:cvvresponse]), test: test? ) end
exp_date(payment_method)
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 261 def exp_date(payment_method) "#{format(payment_method.month, :two_digits)}#{format(payment_method.year, :two_digits)}" end
headers()
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 294 def headers { 'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8' } end
message_from(succeeded, response)
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 314 def message_from(succeeded, response) if succeeded 'Succeeded' else response[:responsetext] end end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 306 def parse(body) Hash[CGI::parse(body).map { |k, v| [k.intern, v.first] }] end
post_data(action, params)
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 298 def post_data(action, params) params.map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&') end
success_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 310 def success_from(response) response[:response] == '1' end
url()
click to toggle source
# File lib/active_merchant/billing/gateways/nmi.rb, line 302 def url test? ? test_url : live_url end