lib/active_merchant/billing/gateways/realex.rb in activemerchant-1.86.0 vs lib/active_merchant/billing/gateways/realex.rb in activemerchant-1.87.0
- old
+ new
@@ -78,10 +78,17 @@
def void(authorization, options = {})
request = build_void_request(authorization, options)
commit(request)
end
+ def verify(credit_card, options = {})
+ requires!(options, :order_id)
+
+ request = build_verify_request(credit_card, options)
+ commit(request)
+ end
+
def supports_scrubbing
true
end
def scrub(transcript)
@@ -109,11 +116,11 @@
def parse(xml)
response = {}
doc = Nokogiri::XML(xml)
doc.xpath('//response/*').each do |node|
- if (node.elements.size == 0)
+ if node.elements.size == 0
response[node.name.downcase.to_sym] = normalize(node.text)
else
node.elements.each do |childnode|
name = "#{node.name.downcase}_#{childnode.name.downcase}"
response[name.to_sym] = normalize(childnode.text)
@@ -183,10 +190,24 @@
add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), nil, nil, nil)
end
xml.target!
end
+ # Verify initiates an OTB (Open To Buy) request
+ def build_verify_request(credit_card, options)
+ timestamp = new_timestamp
+ xml = Builder::XmlMarkup.new :indent => 2
+ xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'otb' do
+ add_merchant_details(xml, options)
+ xml.tag! 'orderid', sanitize_order_id(options[:order_id])
+ add_card(xml, credit_card)
+ add_comments(xml, options)
+ add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), credit_card.number)
+ end
+ xml.target!
+ end
+
def add_address_and_customer_info(xml, options)
billing_address = options[:billing_address] || options[:address]
shipping_address = options[:shipping_address]
return unless billing_address || shipping_address || options[:customer] || options[:invoice] || options[:ip]
@@ -256,18 +277,18 @@
xml.tag! 'cavv', payment.payment_cryptogram
xml.tag! 'eci', payment.eci
end
xml.tag! 'supplementarydata' do
xml.tag! 'item', 'type' => 'mobile' do
- xml.tag! 'field01', payment.source.to_s.gsub('_','-')
+ xml.tag! 'field01', payment.source.to_s.gsub('_', '-')
end
end
end
def format_address_code(address)
code = [address[:zip].to_s, address[:address1].to_s + address[:address2].to_s]
- code.collect{|e| e.gsub(/\D/, '')}.reject(&:empty?).join('|')
+ code.collect { |e| e.gsub(/\D/, '') }.reject(&:empty?).join('|')
end
def new_timestamp
Time.now.strftime('%Y%m%d%H%M%S')
end
@@ -284,29 +305,28 @@
def expiry_date(credit_card)
"#{format(credit_card.month, :two_digits)}#{format(credit_card.year, :two_digits)}"
end
def message_from(response)
- message = nil
case response[:result]
when '00'
- message = SUCCESS
+ SUCCESS
when '101'
- message = response[:message]
+ response[:message]
when '102', '103'
- message = DECLINED
+ DECLINED
when /^2[0-9][0-9]/
- message = BANK_ERROR
+ BANK_ERROR
when /^3[0-9][0-9]/
- message = REALEX_ERROR
+ REALEX_ERROR
when /^5[0-9][0-9]/
- message = response[:message]
+ response[:message]
when '600', '601', '603'
- message = ERROR
+ ERROR
when '666'
- message = CLIENT_DEACTIVATED
+ CLIENT_DEACTIVATED
else
- message = DECLINED
+ DECLINED
end
end
def sanitize_order_id(order_id)
order_id.to_s.gsub(/[^a-zA-Z0-9\-_]/, '')