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.mercurycert.net/ws/ws.asmx',
  live: 'https://w1.mercurypay.com/ws/ws.asmx'
}
STANDARD_ERROR_CODE_MAPPING =
{
  '100204' => STANDARD_ERROR_CODE[:invalid_number],
  '100205' => STANDARD_ERROR_CODE[:invalid_expiry_date],
  '000000' => STANDARD_ERROR_CODE[:card_declined]
}

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#add_field_to_post_if_present, #add_fields_to_post_if_present, card_brand, #card_brand, #generate_unique_id, inherited, supported_countries, #supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #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 = {}) ⇒ MercuryGateway

Returns a new instance of MercuryGateway.



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

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



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

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



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

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



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

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



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

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



65
66
67
68
69
70
# File 'lib/active_merchant/billing/gateways/mercury.rb', line 65

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

#scrub(transcript) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/active_merchant/billing/gateways/mercury.rb', line 88

def scrub(transcript)
  transcript.
    gsub(%r(&lt;), '<').
    gsub(%r(&gt;), '>').
    gsub(%r((<pw>).*(</pw>))i, '\1[FILTERED]\2').
    gsub(%r((<AcctNo>)(\d|x)*(</AcctNo>))i, '\1[FILTERED]\3').
    gsub(%r((<CVVData>)\d*(</CVVData>))i, '\1[FILTERED]\2')
end

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



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

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

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/active_merchant/billing/gateways/mercury.rb', line 84

def supports_scrubbing?
  true
end

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



72
73
74
75
76
77
# File 'lib/active_merchant/billing/gateways/mercury.rb', line 72

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

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