class ActiveMerchant::Billing::WorldpayUsGateway
Constants
- ACCOUNT_TYPES
- ACTIONS
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/worldpay_us.rb, line 20 def initialize(options = {}) requires!(options, :acctid, :subid, :merchantpin) super end
Public Instance Methods
capture(amount, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/worldpay_us.rb, line 43 def capture(amount, authorization, options = {}) post = {} add_invoice(post, amount, options) add_reference(post, authorization) add_customer_data(post, options) commit('capture', options, post) end
purchase(money, payment_method, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/worldpay_us.rb, line 25 def purchase(money, payment_method, options = {}) post = {} add_invoice(post, money, options) add_payment_method(post, payment_method) add_customer_data(post, options) commit('purchase', options, post) end
refund(amount, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/worldpay_us.rb, line 52 def refund(amount, authorization, options = {}) post = {} add_invoice(post, amount, options) add_reference(post, authorization) add_customer_data(post, options) commit('refund', options, post) end
scrub(transcript)
click to toggle source
# File lib/active_merchant/billing/gateways/worldpay_us.rb, line 79 def scrub(transcript) transcript. gsub(%r((&?merchantpin=)[^&]*)i, '\1[FILTERED]'). gsub(%r((&?ccnum=)[^&]*)i, '\1[FILTERED]'). gsub(%r((&?ckacct=)[^&]*)i, '\1[FILTERED]'). gsub(%r((&?cvv2=)[^&]*)i, '\1[FILTERED]') end
supports_scrubbing?()
click to toggle source
# File lib/active_merchant/billing/gateways/worldpay_us.rb, line 75 def supports_scrubbing? true end
verify(credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/worldpay_us.rb, line 68 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/worldpay_us.rb, line 61 def void(authorization, options = {}) post = {} add_reference(post, authorization) commit('void', options, post) end
Private Instance Methods
add_check(post, payment_method)
click to toggle source
# File lib/active_merchant/billing/gateways/worldpay_us.rb, line 145 def add_check(post, payment_method) post[:action] = 'ns_quicksale_check' post[:ckacct] = payment_method.account_number post[:ckaba] = payment_method.routing_number post[:ckno] = payment_method.number post[:ckaccttype] = ACCOUNT_TYPES[payment_method.account_type] if ACCOUNT_TYPES[payment_method.account_type] end
add_credit_card(post, payment_method)
click to toggle source
# File lib/active_merchant/billing/gateways/worldpay_us.rb, line 132 def add_credit_card(post, payment_method) post[:ccname] = payment_method.name post[:ccnum] = payment_method.number post[:cvv2] = payment_method.verification_value post[:expyear] = format(payment_method.year, :four_digits) post[:expmon] = format(payment_method.month, :two_digits) end
add_customer_data(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/worldpay_us.rb, line 93 def add_customer_data(post, options) if (billing_address = (options[:billing_address] || options[:address])) post[:ci_companyname] = billing_address[:company] post[:ci_billaddr1] = billing_address[:address1] post[:ci_billaddr2] = billing_address[:address2] post[:ci_billcity] = billing_address[:city] post[:ci_billstate] = billing_address[:state] post[:ci_billzip] = billing_address[:zip] post[:ci_billcountry] = billing_address[:country] post[:ci_phone] = billing_address[:phone] post[:ci_email] = billing_address[:email] post[:ci_ipaddress] = billing_address[:ip] end if (shipping_address = options[:shipping_address]) post[:ci_shipaddr1] = shipping_address[:address1] post[:ci_shipaddr2] = shipping_address[:address2] post[:ci_shipcity] = shipping_address[:city] post[:ci_shipstate] = shipping_address[:state] post[:ci_shipzip] = shipping_address[:zip] post[:ci_shipcountry] = shipping_address[:country] end end
add_invoice(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/worldpay_us.rb, line 118 def add_invoice(post, money, options) post[:amount] = amount(money) post[:currencycode] = (options[:currency] || currency(money)) post[:merchantordernumber] = options[:order_id] if options[:order_id] end
add_payment_method(post, payment_method)
click to toggle source
# File lib/active_merchant/billing/gateways/worldpay_us.rb, line 124 def add_payment_method(post, payment_method) if card_brand(payment_method) == 'check' add_check(post, payment_method) else add_credit_card(post, payment_method) end end
add_reference(post, authorization)
click to toggle source
# File lib/active_merchant/billing/gateways/worldpay_us.rb, line 158 def add_reference(post, authorization) historyid, orderid = split_authorization(authorization) post[:postonly] = historyid post[:historykeyid] = historyid post[:orderkeyid] = orderid end
commit(action, options, post)
click to toggle source
# File lib/active_merchant/billing/gateways/worldpay_us.rb, line 184 def commit(action, options, post) post[:action] = ACTIONS[action] unless post[:action] post[:acctid] = @options[:acctid] post[:subid] = @options[:subid] post[:merchantpin] = @options[:merchantpin] post[:authonly] = '1' if action == 'authorize' raw = parse(ssl_post(url(options), post.to_query)) succeeded = success_from(raw['result']) Response.new( succeeded, message_from(succeeded, raw), raw, authorization: authorization_from(raw), test: test? ) end
message_from(succeeded, response)
click to toggle source
# File lib/active_merchant/billing/gateways/worldpay_us.rb, line 208 def message_from(succeeded, response) if succeeded 'Succeeded' else (response['transresult'] || response['Reason'] || 'Unable to read error message') end end
parse(xml)
click to toggle source
# File lib/active_merchant/billing/gateways/worldpay_us.rb, line 165 def parse(xml) response = {} doc = Nokogiri::XML(xml) message = doc.xpath('//plaintext') message.text.split(/\r?\n/).each do |line| key, value = line.split(%r{=}) response[key] = value if key end response end
success_from(result)
click to toggle source
# File lib/active_merchant/billing/gateways/worldpay_us.rb, line 204 def success_from(result) result == '1' end
url(options)
click to toggle source
# File lib/active_merchant/billing/gateways/worldpay_us.rb, line 89 def url(options) options[:use_backup_url].to_s == 'true' ? self.backup_url : self.live_url end