Class: ActiveMerchant::Billing::TnsGateway

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

Constant Summary

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, 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, #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 = {}) ⇒ TnsGateway

Returns a new instance of TnsGateway.



20
21
22
23
24
25
26
# File 'lib/active_merchant/billing/gateways/tns.rb', line 20

def initialize(options={})
  requires!(options, :userid, :password)

  options[:region] = 'north_america' unless options[:region]

  super
end

Instance Method Details

#authorize(amount, payment_method, options = {}) ⇒ Object



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

def authorize(amount, payment_method, options={})
  post = new_post
  add_invoice(post, amount, options)
  add_reference(post, *new_authorization)
  add_payment_method(post, payment_method)
  add_customer_data(post, options)

  commit('authorize', post)
end

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



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

def capture(amount, authorization, options={})
  post = new_post
  add_invoice(post, amount, options, :transaction)
  add_reference(post, *next_authorization(authorization))
  add_customer_data(post, options)

  commit('capture', post)
end

#purchase(amount, payment_method, options = {}) ⇒ Object



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

def purchase(amount, payment_method, options={})
  MultiResponse.run do |r|
    r.process { authorize(amount, payment_method, options) }
    r.process { capture(amount, r.authorization, options) }
  end
end

#refund(amount, authorization, options = {}) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/active_merchant/billing/gateways/tns.rb', line 54

def refund(amount, authorization, options={})
  post = new_post
  add_invoice(post, amount, options, :transaction)
  add_reference(post, *next_authorization(authorization))
  add_customer_data(post, options)

  commit('refund', post)
end

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



70
71
72
73
74
75
# File 'lib/active_merchant/billing/gateways/tns.rb', line 70

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



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

def void(authorization, options={})
  post = new_post
  add_reference(post, *next_authorization(authorization), :targetTransactionId)

  commit('void', post)
end