Class: ActiveMerchant::Billing::MonerisGateway

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

Overview

To learn more about the Moneris 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 collapse

TEST_URL =
'https://esqa.moneris.com/gateway2/servlet/MpgRequest'
LIVE_URL =
'https://www3.moneris.com/gateway2/servlet/MpgRequest'

Constants inherited from Gateway

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 Utils

generate_unique_id

Methods included from CreditCardFormatting

#format

Methods included from RequiresParameters

#requires!

Methods included from PostsData

included, #ssl_get, #ssl_post

Constructor Details

#initialize(options = {}) ⇒ MonerisGateway

login is your Store ID password is your API Token



23
24
25
26
27
# File 'lib/active_merchant/billing/gateways/moneris.rb', line 23

def initialize(options = {})
  requires!(options, :login, :password)
  @options = { :crypt_type => 7 }.update(options)
  super      
end

Instance Method Details

#authorize(money, creditcard, 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.



34
35
36
# File 'lib/active_merchant/billing/gateways/moneris.rb', line 34

def authorize(money, creditcard, options = {})
  debit_commit 'preauth', money, creditcard, options        
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



127
128
129
# File 'lib/active_merchant/billing/gateways/moneris.rb', line 127

def capture(money, authorization, options = {})
  commit '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.)



147
148
149
# File 'lib/active_merchant/billing/gateways/moneris.rb', line 147

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

#purchase(money, creditcard, 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



42
43
44
# File 'lib/active_merchant/billing/gateways/moneris.rb', line 42

def purchase(money, creditcard, options = {})
  debit_commit 'purchase', money, creditcard, options
end

#recurring_purchase(money, creditcard, interval, frequency, limit, starts_on, start_now, options = {}) ⇒ Object

This action create a recurring purchase on a customer’s card with the desired interval, frequency, limit, starting date. It can also peform an immediate verification of funding on a customer’s card and ready them for deposit in a merchant’s account. This immediate amount can differ from the recurring amount

Parameters

  • money – The amount to be purchased. Either an Integer value in cents or a Money object.

  • creditcard – The CreditCard details for the transaction.

  • :interval - :day, :week, or :month

  • :frequency - The number of intervals you wish to pass between billing cycles

  • :limit - The number of times to recur this transaction

  • :starts_on - This is the date on which the first charge will be billed. The value must be in the

future. It cannot be the day on which the transaction is being sent. If the transaction is to be billed immediately the start_now feature must be set to true and the start_date should be set at the desired interval after today.

  • :start_now - When a charge is to be made against the card immediately start_now should be

set to ‘true’. If the billing is to start in the future then this value is to be set to ‘false’. When start_now is set to ‘true’ the amount to be billed immediately may differ from the recur amount billed on a regular basis thereafter.

  • options – A hash of optional parameters. Set :recur_amount to either an Integer

value in cents or a Money object to have the recurring amount differ from the immediate amount. Note this only works if start_now is set to false. Otherwise it is ignored.



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

def recurring_purchase(money, creditcard, interval, frequency, limit, starts_on, start_now, options = {})
  requires!(options, :order_id)
  params = debit_params(money, creditcard, options)
  recur_params = {
    :recur_unit => interval,
    :start_now => start_now,
    :start_date => starts_on,
    :num_recurs => limit,
    :period => frequency,
    :recur_amount => amount(options[:recurring_money] || money)
  }
  commit('purchase', params, recur_params)
end

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

This action updates a recurring purchase on a customer’s card. It requires the authorization code and can change the following: customer id, add more recurring payments, the total number of recurring payments, terminate the recurring payments, put them on hold (suspend), the amount and change the credit card.

Parameters

  • authorization – The authorization code used to initially create the recurring payment

  • options – The possible options are:

:customer - the customer id to use :extend_limit - add additional recurring payments :limit - change the total number of recurring payments :recurring_money - change the recurring payment amount :terminate - set to true to stop recurring payments :hold - set to true to hold recurring payments (suspend them) :creditcard - a credit card object to associated with the recurring payments



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/active_merchant/billing/gateways/moneris.rb', line 101

def recurring_update(authorization, options = {})
  params = {
    :order_id   => split_authorization(authorization).last,
    :cust_id    => options[:customer],
    :add_num_recurs   => options[:extend_limit],
    :total_num_recurs   => options[:limit],
    :recur_amount => amount(options[:recurring_money]),
    :terminate    => options[:terminate].nil? ? false : options[:terminate],
    :hold    => options[:hold].nil? ? false : options[:hold]
  }
  if options[:creditcard]
    params.merge!(
      :pan        => options[:creditcard].number,
      :expdate    => expdate(options[:creditcard])
    )
  end
  commit 'recur_update', params
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.)



138
139
140
# File 'lib/active_merchant/billing/gateways/moneris.rb', line 138

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