Class Index [+]

Quicksearch

ActiveMerchant::Billing::RealexGateway

Realex is the leading CC gateway in Ireland see www.realexpayments.com Contributed by John Ward (john@ward.name) see thinedgeofthewedge.blogspot.com

Realex works using the following login - The unique id of the merchant password - The secret is used to digitally sign the request account - This is an optional third part of the authentication process and is used if the merchant wishes do distuinguish cc traffic from the different sources by using a different account. This must be created in advance

the Realex team decided to make the orderid unique per request, so if validation fails you can not correct and resend using the same order id

Constants

URL
CARD_MAPPING
DECLINED
BANK_ERROR
ERROR

Public Class Methods

new(options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/realex.rb, line 45
45:       def initialize(options = {})
46:         requires!(options, :login, :password)
47:         options[:refund_hash] = Digest::SHA1.hexdigest(options[:rebate_secret]) if options.has_key?(:rebate_secret)
48:         @options = options
49:         super
50:       end

Public Instance Methods

authorize(money, creditcard, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/realex.rb, line 59
59:       def authorize(money, creditcard, options = {})
60:         requires!(options, :order_id)
61: 
62:         request = build_purchase_or_authorization_request(:authorization, money, creditcard, options)
63:         commit(request)
64:       end
capture(money, authorization, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/realex.rb, line 66
66:       def capture(money, authorization, options = {})
67:         request = build_capture_request(authorization, options)
68:         commit(request)
69:       end
credit(money, authorization, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/realex.rb, line 76
76:       def credit(money, authorization, options = {})
77:         deprecated CREDIT_DEPRECATION_MESSAGE
78:         refund(money, authorization, options)
79:       end
purchase(money, credit_card, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/realex.rb, line 52
52:       def purchase(money, credit_card, options = {})
53:         requires!(options, :order_id)
54: 
55:         request = build_purchase_or_authorization_request(:purchase, money, credit_card, options)
56:         commit(request)
57:       end
refund(money, authorization, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/realex.rb, line 71
71:       def refund(money, authorization, options = {})
72:         request = build_refund_request(money, authorization, options)
73:         commit(request)
74:       end
void(authorization, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/realex.rb, line 81
81:       def void(authorization, options = {})
82:         request = build_void_request(authorization, options)
83:         commit(request)
84:       end

Private Instance Methods

add_address_and_customer_info(xml, options) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 180
180:       def add_address_and_customer_info(xml, options)
181:         billing_address = options[:billing_address] || options[:address]
182:         shipping_address = options[:shipping_address]
183: 
184:         return unless billing_address || shipping_address || options[:customer] || options[:invoice] || options[:ip]
185: 
186:         xml.tag! 'tssinfo' do
187:           xml.tag! 'custnum', options[:customer] if options[:customer]
188:           xml.tag! 'prodid', options[:invoice] if options[:invoice]
189:           xml.tag! 'custipaddress', options[:ip] if options[:ip]
190: 
191:           if billing_address
192:             xml.tag! 'address', 'type' => 'billing' do
193:               xml.tag! 'code', avs_input_code( billing_address )
194:               xml.tag! 'country', billing_address[:country]
195:             end
196:           end
197: 
198:           if shipping_address
199:             xml.tag! 'address', 'type' => 'shipping' do
200:               xml.tag! 'code', format_shipping_zip_code(shipping_address[:zip])
201:               xml.tag! 'country', shipping_address[:country]
202:             end
203:           end
204:         end
205:       end
add_amount(xml, money, options) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 228
228:       def add_amount(xml, money, options)
229:         xml.tag! 'amount', amount(money), 'currency' => options[:currency] || currency(money)
230:       end
add_card(xml, credit_card) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 232
232:       def add_card(xml, credit_card)
233:         xml.tag! 'card' do
234:           xml.tag! 'number', credit_card.number
235:           xml.tag! 'expdate', expiry_date(credit_card)
236:           xml.tag! 'chname', credit_card.name
237:           xml.tag! 'type', CARD_MAPPING[card_brand(credit_card).to_s]
238:           xml.tag! 'issueno', credit_card.issue_number
239:           xml.tag! 'cvn' do
240:             xml.tag! 'number', credit_card.verification_value
241:             xml.tag! 'presind', (options['presind'] || (credit_card.verification_value? ? 1 : nil))
242:           end
243:         end
244:       end
add_comments(xml, options) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 221
221:       def add_comments(xml, options)
222:         return unless options[:description]
223:         xml.tag! 'comments' do
224:           xml.tag! 'comment', options[:description], 'id' => 1
225:         end
226:       end
add_merchant_details(xml, options) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 207
207:       def add_merchant_details(xml, options)
208:         xml.tag! 'merchantid', @options[:login]
209:         if options[:account] || @options[:account]
210:           xml.tag! 'account', (options[:account] || @options[:account])
211:         end
212:       end
add_signed_digest(xml, *values) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 263
263:       def add_signed_digest(xml, *values)
264:         string = Digest::SHA1.hexdigest(values.join("."))
265:         xml.tag! 'sha1hash', Digest::SHA1.hexdigest([string, @options[:password]].join("."))
266:       end
add_transaction_identifiers(xml, authorization, options) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 214
214:       def add_transaction_identifiers(xml, authorization, options)
215:         options[:order_id], pasref, authcode = authorization.split(';')
216:         xml.tag! 'orderid', sanitize_order_id(options[:order_id])
217:         xml.tag! 'pasref', pasref
218:         xml.tag! 'authcode', authcode
219:       end
authorization_from(parsed) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 121
121:       def authorization_from(parsed)
122:         [parsed[:orderid], parsed[:pasref], parsed[:authcode]].join(';')
123:       end
auto_settle_flag(action) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 268
268:       def auto_settle_flag(action)
269:         action == :authorization ? '0' : '1'
270:       end
avs_input_code(address) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 246
246:       def avs_input_code(address)
247:         address.values_at(:zip, :address1).map{ |v| extract_digits(v) }.join('|')
248:       end
build_capture_request(authorization, options) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 141
141:       def build_capture_request(authorization, options)
142:         timestamp = new_timestamp
143:         xml = Builder::XmlMarkup.new :indent => 2
144:         xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'settle' do
145:           add_merchant_details(xml, options)
146:           add_transaction_identifiers(xml, authorization, options)
147:           add_comments(xml, options)
148:           add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), nil, nil, nil)
149:         end
150:         xml.target!
151:       end
build_purchase_or_authorization_request(action, money, credit_card, options) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 125
125:       def build_purchase_or_authorization_request(action, money, credit_card, options)
126:         timestamp = new_timestamp
127:         xml = Builder::XmlMarkup.new :indent => 2
128:         xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'auth' do
129:           add_merchant_details(xml, options)
130:           xml.tag! 'orderid', sanitize_order_id(options[:order_id])
131:           add_amount(xml, money, options)
132:           add_card(xml, credit_card)
133:           xml.tag! 'autosettle', 'flag' => auto_settle_flag(action)
134:           add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), amount(money), (options[:currency] || currency(money)), credit_card.number)
135:           add_comments(xml, options)
136:           add_address_and_customer_info(xml, options)
137:         end
138:         xml.target!
139:       end
build_refund_request(money, authorization, options) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 153
153:       def build_refund_request(money, authorization, options)
154:         timestamp = new_timestamp
155:         xml = Builder::XmlMarkup.new :indent => 2
156:         xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'rebate' do
157:           add_merchant_details(xml, options)
158:           add_transaction_identifiers(xml, authorization, options)
159:           xml.tag! 'amount', amount(money), 'currency' => options[:currency] || currency(money)
160:           xml.tag! 'refundhash', @options[:refund_hash] if @options[:refund_hash]
161:           xml.tag! 'autosettle', 'flag' => 1
162:           add_comments(xml, options)
163:           add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), amount(money), (options[:currency] || currency(money)), nil)
164:         end
165:         xml.target!
166:       end
build_void_request(authorization, options) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 168
168:       def build_void_request(authorization, options)
169:         timestamp = new_timestamp
170:         xml = Builder::XmlMarkup.new :indent => 2
171:         xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'void' do
172:           add_merchant_details(xml, options)
173:           add_transaction_identifiers(xml, authorization, options)
174:           add_comments(xml, options)
175:           add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), nil, nil, nil)
176:         end
177:         xml.target!
178:       end
commit(request) click to toggle source
    # File lib/active_merchant/billing/gateways/realex.rb, line 87
87:       def commit(request)
88:         response = parse(ssl_post(URL, request))
89: 
90:         Response.new(response[:result] == "00", message_from(response), response,
91:           :test => response[:message] =~ /\[ test system \]/,
92:           :authorization => authorization_from(response),
93:           :cvv_result => response[:cvnresult],
94:           :avs_result => {
95:             :street_match => response[:avspostcoderesponse],
96:             :postal_match => response[:avspostcoderesponse]
97:           }
98:         )
99:       end
expiry_date(credit_card) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 272
272:       def expiry_date(credit_card)
273:         "#{format(credit_card.month, :two_digits)}#{format(credit_card.year, :two_digits)}"
274:       end
extract_digits(string) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 254
254:       def extract_digits(string)
255:         return "" if string.nil?
256:         string.gsub(/[\D]/,'')
257:       end
format_shipping_zip_code(zip) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 250
250:       def format_shipping_zip_code(zip)
251:         zip.to_s.gsub(/\W/, '')
252:       end
message_from(response) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 286
286:       def message_from(response)
287:         message = nil
288:         case response[:result]
289:         when "00"
290:           message = SUCCESS
291:         when "101"
292:           message = response[:message]
293:         when "102", "103"
294:           message = DECLINED
295:         when /^2[0-9][0-9]/
296:           message = BANK_ERROR
297:         when /^3[0-9][0-9]/
298:           message = REALEX_ERROR
299:         when /^5[0-9][0-9]/
300:           message = response[:message]
301:         when "600", "601", "603"
302:           message = ERROR
303:         when "666"
304:           message = CLIENT_DEACTIVATED
305:         else
306:           message = DECLINED
307:         end
308:       end
new_timestamp() click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 259
259:       def new_timestamp
260:         Time.now.strftime('%Y%m%d%H%M%S')
261:       end
normalize(field) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 276
276:       def normalize(field)
277:         case field
278:         when "true"   then true
279:         when "false"  then false
280:         when ""       then nil
281:         when "null"   then nil
282:         else field
283:         end
284:       end
parse(xml) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 101
101:       def parse(xml)
102:         response = {}
103: 
104:         xml = REXML::Document.new(xml)
105:         xml.elements.each('//response/*') do |node|
106: 
107:           if (node.elements.size == 0)
108:             response[node.name.downcase.to_sym] = normalize(node.text)
109:           else
110:             node.elements.each do |childnode|
111:               name = "#{node.name.downcase}_#{childnode.name.downcase}"
112:               response[name.to_sym] = normalize(childnode.text)
113:             end
114:           end
115: 
116:         end unless xml.root.nil?
117: 
118:         response
119:       end
sanitize_order_id(order_id) click to toggle source
     # File lib/active_merchant/billing/gateways/realex.rb, line 310
310:       def sanitize_order_id(order_id)
311:         order_id.to_s.gsub(/[^a-zA-Z0-9\-_]/, '')
312:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.