class ActiveMerchant::Billing::PaywayDotComGateway
Constants
- AVS_MAPPING
Payway to standard
AVSResult
codes.- PAYWAY_WS_SUCCESS
- SCRUB_PATTERNS
- SCRUB_REPLACEMENT
- STANDARD_ERROR_CODE_MAPPING
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/payway_dot_com.rb, line 67 def initialize(options = {}) requires!(options, :login, :password, :company_id, :source_id) super end
Public Instance Methods
capture(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/payway_dot_com.rb, line 92 def capture(money, authorization, options = {}) post = {} add_common(post, options) add_card_transaction_name(post, authorization, options) commit('capture', post) end
credit(money, payment, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/payway_dot_com.rb, line 100 def credit(money, payment, options = {}) post = {} add_common(post, options) add_card_payment(post, payment, options) add_card_transaction_details(post, money, options) add_address(post, payment, options) commit('credit', post) end
purchase(money, payment, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/payway_dot_com.rb, line 72 def purchase(money, payment, options = {}) post = {} add_common(post, options) add_card_payment(post, payment, options) add_card_transaction_details(post, money, options) add_address(post, payment, options) commit('sale', post) end
scrub(transcript)
click to toggle source
# File lib/active_merchant/billing/gateways/payway_dot_com.rb, line 122 def scrub(transcript) SCRUB_PATTERNS.inject(transcript) do |text, pattern| text.gsub(pattern, SCRUB_REPLACEMENT) end end
supports_scrubbing?()
click to toggle source
# File lib/active_merchant/billing/gateways/payway_dot_com.rb, line 118 def supports_scrubbing? true end
void(authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/payway_dot_com.rb, line 110 def void(authorization, options = {}) post = {} add_common(post, options) add_card_transaction_name(post, authorization, options) commit('void', post) end
Private Instance Methods
add_address(post, payment, options)
click to toggle source
# File lib/active_merchant/billing/gateways/payway_dot_com.rb, line 138 def add_address(post, payment, options) post[:cardAccount] ||= {} address = options[:billing_address] || options[:address] || {} first_name, last_name = split_names(address[:name]) full_address = "#{address[:address1]} #{address[:address2]}".strip phone = address[:phone] || address[:phone_number] post[:cardAccount][:firstName] = first_name if first_name post[:cardAccount][:lastName] = last_name if last_name post[:cardAccount][:address] = full_address if full_address post[:cardAccount][:city] = address[:city] if address[:city] post[:cardAccount][:state] = address[:state] if address[:state] post[:cardAccount][:zip] = address[:zip] if address[:zip] post[:cardAccount][:phone] = phone if phone end
add_card_payment(post, payment, options)
click to toggle source
# File lib/active_merchant/billing/gateways/payway_dot_com.rb, line 166 def add_card_payment(post, payment, options) # credit_card post[:accountInputMode] = 'primaryAccountNumber' post[:cardAccount] ||= {} post[:cardAccount][:accountNumber] = payment.number post[:cardAccount][:fsv] = payment.verification_value post[:cardAccount][:expirationDate] = expdate(payment) post[:cardAccount][:email] = options[:email] if options[:email] end
add_card_transaction_details(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/payway_dot_com.rb, line 154 def add_card_transaction_details(post, money, options) post[:cardTransaction][:amount] = amount(money) eci_type = options[:eci_type].nil? ? '1' : options[:eci_type] post[:cardTransaction][:eciType] = eci_type post[:cardTransaction][:processorSoftDescriptor] = options[:processor_soft_descriptor] if options[:processor_soft_descriptor] post[:cardTransaction][:tax] = options[:tax] if options[:tax] end
add_card_transaction_name(post, identifier, options)
click to toggle source
# File lib/active_merchant/billing/gateways/payway_dot_com.rb, line 162 def add_card_transaction_name(post, identifier, options) post[:cardTransaction][:name] = identifier end
add_common(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/payway_dot_com.rb, line 130 def add_common(post, options) post[:userName] = @options[:login] post[:password] = @options[:password] post[:companyId] = @options[:company_id] post[:cardTransaction] = {} post[:cardTransaction][:sourceId] = @options[:source_id] end
commit(action, parameters)
click to toggle source
# File lib/active_merchant/billing/gateways/payway_dot_com.rb, line 188 def commit(action, parameters) parameters[:request] = action url = (test? ? test_url : live_url) payload = parameters.to_json unless parameters.nil? response = begin parse(ssl_request(:post, url, payload, headers)) rescue ResponseError => e return Response.new(false, 'Invalid Login') if e.response.code == '401' parse(e.response.body) end success = success_from(response) avs_result_code = response['cardTransaction'].nil? || response['cardTransaction']['addressVerificationResults'].nil? ? '' : response['cardTransaction']['addressVerificationResults'] avs_result = AVSResult.new(code: AVS_MAPPING[avs_result_code]) cvv_result = CVVResult.new(response['cardTransaction']['fraudSecurityResults']) if response['cardTransaction'] && response['cardTransaction']['fraudSecurityResults'] Response.new( success, message_from(success, response), response, test: test?, error_code: error_code_from(response), authorization: authorization_from(response), avs_result: avs_result, cvv_result: cvv_result ) end
error_code_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/payway_dot_com.rb, line 224 def error_code_from(response) return '' if success_from(response) error = STANDARD_ERROR_CODE_MAPPING[response['paywayCode']].nil? ? STANDARD_ERROR_CODE[:processing_error] : STANDARD_ERROR_CODE_MAPPING[response['paywayCode']] return error end
expdate(credit_card)
click to toggle source
# File lib/active_merchant/billing/gateways/payway_dot_com.rb, line 177 def expdate(credit_card) year = format(credit_card.year, :four_digits) month = format(credit_card.month, :two_digits) month + year end
headers()
click to toggle source
# File lib/active_merchant/billing/gateways/payway_dot_com.rb, line 245 def headers { 'Accept' => 'application/json', 'Content-type' => 'application/json' } end
message_from(success, response)
click to toggle source
# File lib/active_merchant/billing/gateways/payway_dot_com.rb, line 231 def message_from(success, response) return '' if response['paywayCode'].nil? return response['paywayCode'] + '-' + 'success' if success response['paywayCode'] end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/payway_dot_com.rb, line 184 def parse(body) body.blank? ? {} : JSON.parse(body) end
success_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/payway_dot_com.rb, line 220 def success_from(response) response['paywayCode'] == PAYWAY_WS_SUCCESS end