require 'nokogiri'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
# See https://helpdesk.worldnettps.com/support/solutions/articles/1000167298-integrator-guide
class WorldNetGateway < Gateway
self.test_url = 'https://testpayments.worldnettps.com/merchant/xmlpayment'
self.live_url = 'https://payments.worldnettps.com/merchant/xmlpayment'
self.homepage_url = 'http://worldnettps.com/'
self.display_name = 'WorldNet'
self.supported_countries = %w(IE GB US)
self.default_currency = 'EUR'
CARD_TYPES = {
visa: 'VISA',
master: 'MASTERCARD',
discover: 'DISCOVER',
american_express: 'AMEX',
maestro: 'MAESTRO',
diners_club: 'DINERS',
jcb: 'JCB',
secure_card: 'SECURECARD'
}.freeze
self.supported_cardtypes = CARD_TYPES.keys
def initialize(options = {})
requires!(options, :terminal_id, :secret)
options[:terminal_type] ||= 2 # eCommerce
super
end
def purchase(money, payment, options = {})
requires!(options, :order_id)
post = {}
add_invoice(post, money, options)
add_payment(post, payment)
add_address(post, payment, options)
add_customer_data(post, options)
commit('PAYMENT', post)
end
def authorize(money, payment, options = {})
requires!(options, :order_id)
post = {}
add_invoice(post, money, options)
add_payment(post, payment)
add_address(post, payment, options)
add_customer_data(post, options)
commit('PREAUTH', post)
end
def capture(money, authorization, options = {})
post = {}
add_invoice(post, money, options)
post[:uniqueref] = authorization
commit('PREAUTHCOMPLETION', post)
end
def refund(money, authorization, options = {})
requires!(options, :operator, :reason)
post = {}
post[:uniqueref] = authorization
add_invoice(post, money, options)
post[:operator] = options[:operator]
post[:reason] = options[:reason]
commit('REFUND', post)
end
def void(authorization, _options = {})
post = {}
post[:uniqueref] = authorization
commit('VOID', post)
end
def verify(credit_card, options = {})
MultiResponse.run(:use_first_response) do |r|
r.process { authorize(100, credit_card, options) }
r.process(:ignore_result) { void(r.authorization, options) }
end
end
def store(payment, options = {})
requires!(options, :order_id)
post = {}
post[:merchantref] = options[:order_id]
add_payment(post, payment)
commit('SECURECARDREGISTRATION', post)
end
def unstore(payment, options = {})
requires!(options, :order_id)
post = {}
post[:merchantref] = options[:order_id]
add_card_reference(post, payment)
commit('SECURECARDREMOVAL', post)
end
def supports_scrubbing?
true
end
def scrub(transcript)
transcript.
gsub(%r{(\d{6})\d+(\d{4})}, '\1...\2').
gsub(%r{()\d+(