Class: ActiveMerchant::Billing::MercuryGateway

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

Overview

The Mercury gateway integration by default requires that the Mercury account being used has tokenization turned. This enables the use of capture/refund/void without having to pass the credit card back in each time. Only the “OneTime” tokenization is used; there is no use of “Recurring” tokenization.

If you don’t wish to enable Mercury tokenization, you can pass :tokenization => false as an option when creating the gateway. If you do so, then passing a :credit_card option to capture and refund will become mandatory.

Constant Summary collapse

URLS =
{
  :test => 'https://w1.mercurydev.net/ws/ws.asmx',
  :live => 'https://w1.mercurypay.com/ws/ws.asmx'
}

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, inherited, supports?, #test?

Methods included from CreditCardFormatting

#format

Constructor Details

#initialize(options = {}) ⇒ MercuryGateway

Returns a new instance of MercuryGateway.



25
26
27
28
29
# File 'lib/active_merchant/billing/gateways/mercury.rb', line 25

def initialize(options = {})
  requires!(options, :login, :password)
  @use_tokenization = (!options.has_key?(:tokenization) || options[:tokenization])
  super
end

Instance Method Details

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



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

def authorize(money, credit_card, options = {})
  requires!(options, :order_id)

  request = build_non_authorized_request('PreAuth', money, credit_card, options.merge(:authorized => money))
  commit('PreAuth', request)
end

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



52
53
54
55
56
57
# File 'lib/active_merchant/billing/gateways/mercury.rb', line 52

def capture(money, authorization, options = {})
  requires!(options, :credit_card) unless @use_tokenization

  request = build_authorized_request('PreAuthCapture', money, authorization, options[:credit_card], options.merge(:authorized => money))
  commit('PreAuthCapture', request)
end

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



38
39
40
41
42
43
# File 'lib/active_merchant/billing/gateways/mercury.rb', line 38

def credit(money, credit_card, options = {})
  requires!(options, :order_id)

  request = build_non_authorized_request('Return', money, credit_card, options)
  commit('Return', request)
end

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



31
32
33
34
35
36
# File 'lib/active_merchant/billing/gateways/mercury.rb', line 31

def purchase(money, credit_card, options = {})
  requires!(options, :order_id)

  request = build_non_authorized_request('Sale', money, credit_card, options)
  commit('Sale', request)
end

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



59
60
61
62
63
64
# File 'lib/active_merchant/billing/gateways/mercury.rb', line 59

def refund(money, authorization, options = {})
  requires!(options, :credit_card) unless @use_tokenization

  request = build_authorized_request('Return', money, authorization, options[:credit_card], options)
  commit('Return', request)
end

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



80
81
82
83
# File 'lib/active_merchant/billing/gateways/mercury.rb', line 80

def store(credit_card, options={})
  request = build_card_lookup_request(credit_card, options)
  commit('CardLookup', request)
end

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



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/active_merchant/billing/gateways/mercury.rb', line 66

def void(authorization, options={})
  requires!(options, :credit_card) unless @use_tokenization

  if options[:try_reversal]
    request = build_authorized_request('VoidSale', nil, authorization, options[:credit_card], options.merge(:reversal => true))
    response = commit('VoidSale', request)

    return response if response.success?
  end

  request = build_authorized_request('VoidSale', nil, authorization, options[:credit_card], options)
  commit('VoidSale', request)
end