Class Index [+]

Quicksearch

ActiveMerchant::Billing::MonerisGateway

To learn more about the Moneris gateway, please contact eselectplus@moneris.com 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.

Constants

TEST_URL
LIVE_URL

Public Class Methods

new(options = {}) click to toggle source

login is your Store ID password is your API Token

    # File lib/active_merchant/billing/gateways/moneris.rb, line 23
23:       def initialize(options = {})
24:         requires!(options, :login, :password)
25:         @options = { :crypt_type => 7 }.update(options)
26:         super      
27:       end

Public Instance Methods

authorize(money, creditcard, options = {}) click to toggle source

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.

    # File lib/active_merchant/billing/gateways/moneris.rb, line 34
34:       def authorize(money, creditcard, options = {})
35:         debit_commit 'preauth', money, creditcard, options        
36:       end
capture(money, authorization, options = {}) click to toggle source

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

    # File lib/active_merchant/billing/gateways/moneris.rb, line 53
53:       def capture(money, authorization, options = {})
54:         commit 'completion', crediting_params(authorization, :comp_amount => amount(money))
55:       end
credit(money, authorization, options = {}) click to toggle source

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.)

    # File lib/active_merchant/billing/gateways/moneris.rb, line 73
73:       def credit(money, authorization, options = {})
74:         deprecated CREDIT_DEPRECATION_MESSAGE
75:         refund(money, authorization, options)
76:       end
purchase(money, creditcard, options = {}) click to toggle source

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

    # File lib/active_merchant/billing/gateways/moneris.rb, line 42
42:       def purchase(money, creditcard, options = {})
43:         debit_commit 'purchase', money, creditcard, options
44:       end
refund(money, authorization, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/moneris.rb, line 78
78:       def refund(money, authorization, options = {})
79:         commit 'refund', crediting_params(authorization, :amount => amount(money))
80:       end
test?() click to toggle source
    # File lib/active_merchant/billing/gateways/moneris.rb, line 82
82:       def test?
83:         @options[:test] || super
84:       end
void(authorization, options = {}) click to toggle source

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.)

    # File lib/active_merchant/billing/gateways/moneris.rb, line 64
64:       def void(authorization, options = {})
65:         commit 'purchasecorrection', crediting_params(authorization)
66:       end

Private Instance Methods

actions() click to toggle source
     # File lib/active_merchant/billing/gateways/moneris.rb, line 194
194:       def actions
195:         {
196:           "purchase"           => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
197:           "preauth"            => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
198:           "command"            => [:order_id],
199:           "refund"             => [:order_id, :amount, :txn_number, :crypt_type],
200:           "indrefund"          => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
201:           "completion"         => [:order_id, :comp_amount, :txn_number, :crypt_type],
202:           "purchasecorrection" => [:order_id, :txn_number, :crypt_type],
203:           "cavvpurcha"         => [:order_id, :cust_id, :amount, :pan, :expdate, :cav],
204:           "cavvpreaut"         => [:order_id, :cust_id, :amount, :pan, :expdate, :cavv],
205:           "transact"           => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
206:           "Batchcloseall"      => [],
207:           "opentotals"         => [:ecr_number],
208:           "batchclose"         => [:ecr_number]
209:         }
210:       end
authorization_from(response = {}) click to toggle source

Generates a Moneris authorization string of the form ‘trans_id;receipt_id’.

     # File lib/active_merchant/billing/gateways/moneris.rb, line 137
137:       def authorization_from(response = {})
138:         if response[:trans_id] && response[:receipt_id]
139:           "#{response[:trans_id]};#{response[:receipt_id]}"
140:         end
141:       end
commit(action, parameters = {}) click to toggle source
     # File lib/active_merchant/billing/gateways/moneris.rb, line 127
127:       def commit(action, parameters = {})
128:         response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, post_data(action, parameters)))
129: 
130:         Response.new(successful?(response), message_from(response[:message]), response,
131:           :test          => test?,
132:           :authorization => authorization_from(response)
133:         )
134:       end
crediting_params(authorization, options = {}) click to toggle source

Common params used amongst the credit, void and capture methods

     # File lib/active_merchant/billing/gateways/moneris.rb, line 109
109:       def crediting_params(authorization, options = {})
110:         {
111:           :txn_number => split_authorization(authorization).first, 
112:           :order_id   => split_authorization(authorization).last, 
113:           :crypt_type => options[:crypt_type] || @options[:crypt_type]
114:         }.merge(options)
115:       end
debit_commit(commit_type, money, creditcard, options) click to toggle source
    # File lib/active_merchant/billing/gateways/moneris.rb, line 91
91:       def debit_commit(commit_type, money, creditcard, options)
92:         requires!(options, :order_id)
93:         commit(commit_type, debit_params(money, creditcard, options))
94:       end
debit_params(money, creditcard, options = {}) click to toggle source

Common params used amongst the purchase and authorization methods

     # File lib/active_merchant/billing/gateways/moneris.rb, line 97
 97:       def debit_params(money, creditcard, options = {})
 98:         {
 99:           :order_id   => options[:order_id],
100:           :cust_id    => options[:customer],
101:           :amount     => amount(money),
102:           :pan        => creditcard.number,
103:           :expdate    => expdate(creditcard),
104:           :crypt_type => options[:crypt_type] || @options[:crypt_type]
105:         }
106:       end
expdate(creditcard) click to toggle source
    # File lib/active_merchant/billing/gateways/moneris.rb, line 87
87:       def expdate(creditcard)
88:         sprintf("%.4i", creditcard.year)[2..1] + sprintf("%.2i", creditcard.month)
89:       end
hashify_xml!(xml, response) click to toggle source
     # File lib/active_merchant/billing/gateways/moneris.rb, line 156
156:       def hashify_xml!(xml, response)
157:         xml = REXML::Document.new(xml)
158:         return if xml.root.nil?
159:         xml.elements.each('//receipt/*') do |node|
160:           response[node.name.underscore.to_sym] = normalize(node.text)
161:         end
162:       end
message_from(message) click to toggle source
     # File lib/active_merchant/billing/gateways/moneris.rb, line 179
179:       def message_from(message)
180:         return 'Unspecified error' if message.blank?
181:         message.gsub(/[^\w]/, ' ').split.join(" ").capitalize
182:       end
normalize(field) click to toggle source

Make a Ruby type out of the response string

     # File lib/active_merchant/billing/gateways/moneris.rb, line 185
185:       def normalize(field)
186:         case field
187:           when "true"     then true
188:           when "false"    then false
189:           when '', "null" then nil
190:           else field
191:         end        
192:       end
parse(xml) click to toggle source
     # File lib/active_merchant/billing/gateways/moneris.rb, line 150
150:       def parse(xml)
151:         response = { :message => "Global Error Receipt", :complete => false }
152:         hashify_xml!(xml, response)
153:         response
154:       end
post_data(action, parameters = {}) click to toggle source
     # File lib/active_merchant/billing/gateways/moneris.rb, line 164
164:       def post_data(action, parameters = {})
165:         xml   = REXML::Document.new
166:         root  = xml.add_element("request")
167:         root.add_element("store_id").text  = options[:login]
168:         root.add_element("api_token").text = options[:password]
169:         transaction = root.add_element(action)
170: 
171:         # Must add the elements in the correct order
172:         actions[action].each do |key|
173:           transaction.add_element(key.to_s).text = parameters[key] unless parameters[key].blank?
174:         end
175:         
176:         xml.to_s
177:       end
split_authorization(authorization) click to toggle source

Splits an authorization param and retrives the order id and transaction number in that order.

     # File lib/active_merchant/billing/gateways/moneris.rb, line 119
119:       def split_authorization(authorization)
120:         if authorization.nil? || authorization.empty? || authorization !~ /;/
121:           raise ArgumentError, 'You must include a valid authorization code (e.g. "1234;567")' 
122:         else
123:           authorization.split(';')
124:         end
125:       end
successful?(response) click to toggle source

Tests for a successful response from Moneris’ servers

     # File lib/active_merchant/billing/gateways/moneris.rb, line 144
144:       def successful?(response)
145:         response[:response_code] && 
146:         response[:complete] && 
147:         (0..49).include?(response[:response_code].to_i)
148:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.