class ActiveMerchant::Billing::WorldNetGateway
See helpdesk.worldnettps.com/support/solutions/articles/1000167298-integrator-guide
Constants
- CARD_TYPES
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/world_net.rb, line 28 def initialize(options = {}) requires!(options, :terminal_id, :secret) options[:terminal_type] ||= 2 # eCommerce super end
Public Instance Methods
capture(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 58 def capture(money, authorization, options = {}) post = {} add_invoice(post, money, options) post[:uniqueref] = authorization commit('PREAUTHCOMPLETION', post) end
purchase(money, payment, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 34 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
refund(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 66 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
scrub(transcript)
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 115 def scrub(transcript) transcript. gsub(%r{(<CARDNUMBER>\d{6})\d+(\d{4}</CARDNUMBER>)}, '\1...\2'). gsub(%r{(<CVV>)\d+(</CVV)}, '\1...\2') end
store(payment, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 91 def store(payment, options = {}) requires!(options, :order_id) post = {} post[:merchantref] = options[:order_id] add_payment(post, payment) commit('SECURECARDREGISTRATION', post) end
supports_scrubbing?()
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 111 def supports_scrubbing? true end
unstore(payment, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 101 def unstore(payment, options = {}) requires!(options, :order_id) post = {} post[:merchantref] = options[:order_id] add_card_reference(post, payment) commit('SECURECARDREMOVAL', post) end
verify(credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 84 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
void(authorization, _options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 78 def void(authorization, _options = {}) post = {} post[:uniqueref] = authorization commit('VOID', post) end
Private Instance Methods
add_address(post, _creditcard, options)
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 128 def add_address(post, _creditcard, options) address = options[:billing_address] || options[:address] return unless address post[:address1] = address[:address1] post[:address2] = address[:address2] post[:city] = address[:city] post[:country] = address[:country] # ISO 3166-1-alpha-2 code. post[:postcode] = address[:zip] end
add_card_reference(post, payment)
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 160 def add_card_reference(post, payment) post[:cardreference] = payment end
add_customer_data(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 123 def add_customer_data(post, options) post[:email] = options[:email] post[:ipaddress] = options[:ip] end
add_invoice(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 138 def add_invoice(post, money, options) post[:orderid] = options[:order_id] post[:amount] = amount(money) post[:currency] = (options[:currency] || currency(money)) post[:description] = options[:description] end
add_payment(post, payment)
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 145 def add_payment(post, payment) # a payment triggered with a secure_card (tokenised card) will not # respond to `:number` if payment.respond_to?(:number) post[:cardholdername] = cardholdername(payment) post[:cardtype] = CARD_TYPES[payment.brand.to_sym] post[:cardnumber] = payment.number post[:cvv] = payment.verification_value if payment.verification_value post[:cardexpiry] = expdate(payment) else post[:cardtype] = CARD_TYPES[:secure_card] post[:cardnumber] = payment end end
build_signature(parameters)
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 251 def build_signature(parameters) str = parameters[:terminalid] str += (parameters[:uniqueref] || parameters[:orderid]) str += (parameters[:amount].to_s + parameters[:datetime]) Digest::MD5.hexdigest(str + @options[:secret]) end
build_store_signature(parameters)
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 258 def build_store_signature(parameters) str = parameters[:terminalid] str += parameters[:merchantref] str += parameters[:datetime] str += parameters[:cardnumber] str += parameters[:cardexpiry] str += parameters[:cardtype] str += parameters[:cardholdername] Digest::MD5.hexdigest(str + @options[:secret]) end
build_unstore_signature(parameters)
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 269 def build_unstore_signature(parameters) str = parameters[:terminalid] str += parameters[:merchantref] str += parameters[:datetime] str += parameters[:cardreference] Digest::MD5.hexdigest(str + @options[:secret]) end
build_xml_request(action, fields, data)
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 328 def build_xml_request(action, fields, data) xml = Builder::XmlMarkup.new indent: 2 xml.instruct!(:xml, version: '1.0', encoding: 'utf-8') xml.tag!(action) do fields.each do |field| xml.tag!(field.to_s.upcase, data[field]) if data[field] end end xml.target! end
cardholdername(payment)
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 164 def cardholdername(payment) [payment.first_name, payment.last_name].join(' ').slice(0, 60) end
commit(action, parameters)
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 178 def commit(action, parameters) url = (test? ? test_url : live_url) response = parse(action, ssl_post(url, post_data(action, parameters))) Response.new( success_from(action, response), message_from(response), response, authorization: authorization_from(action, response), avs_result: AVSResult.new(code: response[:avs_response]), cvv_result: CVVResult.new(response[:cvv_response]), test: test?, error_code: success_from(action, response) ? nil : message_to_standard_error_code_from(response) ) end
create_time_stamp()
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 247 def create_time_stamp Time.now.gmtime.strftime('%d-%m-%Y:%H:%M:%S:%L') end
expdate(credit_card)
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 339 def expdate(credit_card) sprintf('%02d%02d', credit_card.month, credit_card.year % 100) end
fields(action)
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 277 def fields(action) # Gateway expects fields in fixed order below. case action when 'PAYMENT', 'PREAUTH' [ :orderid, :terminalid, :amount, :datetime, :cardnumber, :cardtype, :cardexpiry, :cardholdername, :hash, :currency, :terminaltype, :transactiontype, :email, :cvv, :address1, :address2, :postcode, :description, :city, :country, :ipaddress ] when 'PREAUTHCOMPLETION' [:uniqueref, :terminalid, :amount, :datetime, :hash] when 'REFUND' [:uniqueref, :terminalid, :amount, :datetime, :hash, :operator, :reason] when 'VOID' [:uniqueref] when 'SECURECARDREGISTRATION' [ :merchantref, :terminalid, :datetime, :cardnumber, :cardexpiry, :cardtype, :cardholdername, :hash, :dontchecksecurity, :cvv, :issueno ] when 'SECURECARDREMOVAL' [ :merchantref, :cardreference, :terminalid, :datetime, :hash ] end end
message_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 218 def message_from(response) response[:responsetext] || response[:errorstring] end
message_to_standard_error_code_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 205 def message_to_standard_error_code_from(response) case message_from(response) when /DECLINED/ STANDARD_ERROR_CODE[:card_declined] when /CVV FAILURE/ STANDARD_ERROR_CODE[:incorrect_cvc] when /Invalid CARDEXPIRY field/ STANDARD_ERROR_CODE[:invalid_expiry_date] else STANDARD_ERROR_CODE[:processing_error] end end
parse(action, body)
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 168 def parse(action, body) results = {} xml = Nokogiri::XML(body) resp = xml.xpath("//#{action}RESPONSE | //ERROR") resp.children.each do |element| results[element.name.downcase.to_sym] = element.text end results end
post_data(action, parameters = {})
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 231 def post_data(action, parameters = {}) parameters[:terminalid] = @options[:terminal_id] parameters[:terminaltype] = @options[:terminal_type] parameters[:transactiontype] = 7 # eCommerce parameters[:datetime] = create_time_stamp parameters[:hash] = case action when 'SECURECARDREGISTRATION' build_store_signature(parameters) when 'SECURECARDREMOVAL' build_unstore_signature(parameters) else build_signature(parameters) end build_xml_request(action, fields(action), parameters) end
success_from(action, response)
click to toggle source
# File lib/active_merchant/billing/gateways/world_net.rb, line 194 def success_from(action, response) case action when 'SECURECARDREGISTRATION' response[:cardreference].present? when 'SECURECARDREMOVAL' response[:datetime].present? && response[:hash].present? else response[:responsecode] == 'A' end end