Class: ActiveMerchant::Billing::MonerisUsGateway

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

Overview

To learn more about the Moneris (US) gateway, please contact [email protected] for a copy of their integration guide. For information on remote testing, please see “Test Environment Penny Value Response Table”, and “Test Environment eFraud (AVS and CVD) Penny Response Values”, available at Moneris’ eSelect Plus Documentation Centre.

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, supported_countries, #supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #test?

Methods included from CreditCardFormatting

#format

Methods included from PostsData

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

Constructor Details

#initialize(options = {}) ⇒ MonerisUsGateway

Initialize the Gateway

The gateway requires that a valid login and password be passed in the options hash.

Options

  • :login – Your Store ID

  • :password – Your API Token

  • :cvv_enabled – Specify that you would like the CVV passed to the gateway.

    Only particular  types at Moneris will allow this.
    Defaults to false.  (optional)
    


33
34
35
36
37
38
39
# File 'lib/active_merchant/billing/gateways/moneris_us.rb', line 33

def initialize(options = {})
  requires!(options, :login, :password)
  @cvv_enabled = options[:cvv_enabled]
  @avs_enabled = options[:avs_enabled]
  options = { :crypt_type => 7 }.merge(options)
  super
end

Instance Method Details

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

Referred to as “PreAuth” in the Moneris integration guide, this action verifies and locks funds on a customer’s card, which then must be captured at a later date.

Pass in order_id and optionally a customer parameter.



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

def authorize(money, creditcard_or_datakey, options = {})
  requires!(options, :order_id)
  post = {}
  add_payment_source(post, creditcard_or_datakey, options)
  post[:amount]     = amount(money)
  post[:order_id]   = options[:order_id]
  post[:address]    = options[:billing_address] || options[:address]
  post[:crypt_type] = options[:crypt_type] || @options[:crypt_type]
  action = (post[:data_key].blank?) ? 'us_preauth' : 'us_res_preauth_cc'
  commit(action, post)
end

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

This method retrieves locked funds from a customer’s account (from a PreAuth) and prepares them for deposit in a merchant’s account.

Note: Moneris requires both the order_id and the transaction number of the original authorization. To maintain the same interface as the other gateways the two numbers are concatenated together with a ; separator as the authorization number returned by authorization



94
95
96
# File 'lib/active_merchant/billing/gateways/moneris_us.rb', line 94

def capture(money, authorization, options = {})
  commit 'us_completion', crediting_params(authorization, :comp_amount => amount(money))
end

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

Performs a refund. This method requires that the original transaction number and order number be included. Concatenate your transaction number and order_id by using a semicolon (‘;’). This is to keep the Moneris interface consistent with other gateways. (See capture for details.)



114
115
116
117
# File 'lib/active_merchant/billing/gateways/moneris_us.rb', line 114

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

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

This action verifies funding on a customer’s card and readies them for deposit in a merchant’s account.

Pass in order_id and optionally a customer parameter



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

def purchase(money, creditcard_or_datakey, options = {})
  requires!(options, :order_id)
  post = {}
  add_payment_source(post, creditcard_or_datakey, options)
  post[:amount]     = amount(money)
  post[:order_id]   = options[:order_id]
  add_address(post, creditcard_or_datakey, options)
  post[:crypt_type] = options[:crypt_type] || @options[:crypt_type]
  action = if creditcard_or_datakey.is_a?(String)
    'us_res_purchase_cc'
  elsif card_brand(creditcard_or_datakey) == 'check'
    'us_ach_debit'
  elsif post[:data_key].blank?
    'us_purchase'
  end
  commit(action, post)
end

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



119
120
121
# File 'lib/active_merchant/billing/gateways/moneris_us.rb', line 119

def refund(money, authorization, options = {})
  commit 'us_refund', crediting_params(authorization, :amount => amount(money))
end

#scrub(transcript) ⇒ Object



147
148
149
150
151
152
# File 'lib/active_merchant/billing/gateways/moneris_us.rb', line 147

def scrub(transcript)
  transcript.
    gsub(%r((<pan>)[^<]*(</pan>))i, '\1[FILTERED]\2').
    gsub(%r((<api_token>)[^<]*(</api_token>))i, '\1[FILTERED]\2').
    gsub(%r((<cvd_value>)[^<]*(</cvd_value>))i, '\1[FILTERED]\2')
end

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



123
124
125
126
127
128
# File 'lib/active_merchant/billing/gateways/moneris_us.rb', line 123

def store(payment_source, options = {})
  post = {}
  add_payment_source(post, payment_source, options)
  post[:crypt_type] = options[:crypt_type] || @options[:crypt_type]
  card_brand(payment_source) == 'check' ? commit('us_res_add_ach', post) : commit('us_res_add_cc', post)
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/active_merchant/billing/gateways/moneris_us.rb', line 143

def supports_scrubbing?
  true
end

#unstore(data_key, options = {}) ⇒ Object



130
131
132
133
134
# File 'lib/active_merchant/billing/gateways/moneris_us.rb', line 130

def unstore(data_key, options = {})
  post = {}
  post[:data_key] = data_key
  commit('us_res_delete', post)
end

#update(data_key, payment_source, options = {}) ⇒ Object



136
137
138
139
140
141
# File 'lib/active_merchant/billing/gateways/moneris_us.rb', line 136

def update(data_key, payment_source, options = {})
  post = {}
  add_payment_source(post, payment_source, options)
  post[:data_key] = data_key
  card_brand(payment_source) == 'check' ? commit('us_res_update_ach', post) : commit('us_res_update_cc', post)
end

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



41
42
43
44
45
46
# File 'lib/active_merchant/billing/gateways/moneris_us.rb', line 41

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

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

Voiding requires the original transaction ID and order ID of some open transaction. Closed transactions must be refunded. Note that the only methods which may be voided are capture and purchase.

Concatenate your transaction number and order_id by using a semicolon (‘;’). This is to keep the Moneris interface consistent with other gateways. (See capture for details.)



105
106
107
# File 'lib/active_merchant/billing/gateways/moneris_us.rb', line 105

def void(authorization, options = {})
  commit 'us_purchasecorrection', crediting_params(authorization)
end