Class: ActiveMerchant::Billing::NmiGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/nmi.rb

Constant Summary collapse

API_VERSION =
'3.1'
CARD_CODE_ERRORS =
%w( N S )
AVS_ERRORS =
%w( A E N R W Z )
AVS_REASON_CODES =
%w(27 45)
TRANSACTION_ALREADY_ACTIONED =
%w(310 311)

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, #generate_unique_id, inherited, non_fractional_currency?, #scrub, supported_countries, #supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #supports_scrubbing?, #test?

Methods included from CreditCardFormatting

#expdate, #format

Methods included from PostsData

included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request

Constructor Details

#initialize(options = {}) ⇒ NmiGateway

Returns a new instance of NmiGateway.



28
29
30
31
# File 'lib/active_merchant/billing/gateways/nmi.rb', line 28

def initialize(options = {})
  requires!(options, :login, :password)
  super
end

Instance Method Details

#authorize(money, paysource, options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/active_merchant/billing/gateways/nmi.rb', line 33

def authorize(money, paysource, options = {})
  post = {}
  add_currency_code(post, money, options)
  add_invoice(post, options)
  add_payment_source(post, paysource, options)
  add_address(post, options)
  add_customer_data(post, options)
  add_duplicate_window(post)

  commit('AUTH_ONLY', money, post)
end

#capture(money, authorization, options = {}) ⇒ Object



57
58
59
60
61
62
# File 'lib/active_merchant/billing/gateways/nmi.rb', line 57

def capture(money, authorization, options = {})
  post = {:trans_id => authorization}
  add_customer_data(post, options)
  add_invoice(post, options)
  commit('PRIOR_AUTH_CAPTURE', money, post)
end

#credit(money, identification, options = {}) ⇒ Object



87
88
89
90
# File 'lib/active_merchant/billing/gateways/nmi.rb', line 87

def credit(money, identification, options = {})
  ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
  refund(money, identification, options)
end

#purchase(money, paysource, options = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/active_merchant/billing/gateways/nmi.rb', line 45

def purchase(money, paysource, options = {})
  post = {}
  add_currency_code(post, money, options)
  add_invoice(post, options)
  add_payment_source(post, paysource, options)
  add_address(post, options)
  add_customer_data(post, options)
  add_duplicate_window(post)

  commit('AUTH_CAPTURE', money, post)
end

#refund(money, identification, options = {}) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/active_merchant/billing/gateways/nmi.rb', line 70

def refund(money, identification, options = {})
  requires!(options, :card_number)

  post = { :trans_id => identification,
           :card_num => options[:card_number]
         }

  post[:first_name] = options[:first_name] if options[:first_name]
  post[:last_name] = options[:last_name] if options[:last_name]
  post[:zip] = options[:zip] if options[:zip]

  add_invoice(post, options)
  add_duplicate_window(post)

  commit('CREDIT', money, post)
end

#verify(credit_card, options = {}) ⇒ Object



92
93
94
95
96
97
# File 'lib/active_merchant/billing/gateways/nmi.rb', line 92

def verify(credit_card, options = {})
  MultiResponse.run(:use_first_response) do |r|
    r.process { authorize(100, credit_card, options) }
    r.process(:ignore_result) { void(r.authorization, options) }
  end
end

#void(authorization, options = {}) ⇒ Object



64
65
66
67
68
# File 'lib/active_merchant/billing/gateways/nmi.rb', line 64

def void(authorization, options = {})
  post = {:trans_id => authorization}
  add_duplicate_window(post)
  commit('VOID', nil, post)
end