class ActiveMerchant::Billing::Latitude19Gateway
Constants
- BRAND_MAP
- RESPONSE_CODE_MAPPING
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/latitude19.rb, line 54 def initialize(options = {}) requires!(options, :account_number, :configuration_id, :secret) super end
Public Instance Methods
capture(amount, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 83 def capture(amount, authorization, options = {}) post = {} post[:method] = 'deposit' add_request_id(post) params = {} _, params[:pgwTID] = split_authorization(authorization) add_invoice(params, amount, options) add_credentials(params, post[:method]) post[:params] = [params] commit('v1/', post) end
credit(amount, payment_method, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 112 def credit(amount, payment_method, options = {}) if payment_method.is_a?(String) refundWithCard(payment_method, amount, nil, options) else MultiResponse.run() do |r| r.process { get_session(options) } r.process { get_token(r.authorization, payment_method, options) } r.process { refundWithCard(r.authorization, amount, payment_method, options) } end end end
purchase(amount, payment_method, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 59 def purchase(amount, payment_method, options = {}) if payment_method.is_a?(String) auth_or_sale('sale', payment_method, amount, nil, options) else MultiResponse.run() do |r| r.process { get_session(options) } r.process { get_token(r.authorization, payment_method, options) } r.process { auth_or_sale('sale', r.authorization, amount, payment_method, options) } end end end
scrub(transcript)
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 144 def scrub(transcript) transcript. gsub(%r((\"cardNumber\\\":\\\")\d+), '\1[FILTERED]'). gsub(%r((\"cvv\\\":\\\")\d+), '\1[FILTERED]') end
store(payment_method, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 136 def store(payment_method, options = {}) verify(payment_method, options, 'store') end
supports_scrubbing?()
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 140 def supports_scrubbing? true end
verify(payment_method, options = {}, action = nil)
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 124 def verify(payment_method, options = {}, action = nil) if payment_method.is_a?(String) verifyOnly(action, payment_method, nil, options) else MultiResponse.run() do |r| r.process { get_session(options) } r.process { get_token(r.authorization, payment_method, options) } r.process { verifyOnly(action, r.authorization, payment_method, options) } end end end
void(authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 99 def void(authorization, options = {}) method, pgwTID = split_authorization(authorization) case method when 'auth' reverse_or_void('reversal', pgwTID, options) when 'deposit', 'sale' reverse_or_void('void', pgwTID, options) else message = 'Unsupported operation: successful Purchase, Authorize and unsettled Capture transactions can only be voided.' return Response.new(false, message) end end
Private Instance Methods
add_credentials(params, method)
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 170 def add_credentials(params, method) params[:pgwAccountNumber] = @options[:account_number] params[:pgwConfigurationId] = @options[:configuration_id] params[:requestTimeStamp] = add_timestamp() if method == 'getSession' params[:pgwHMAC] = add_hmac(params, method) end
add_customer_data(params, options)
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 193 def add_customer_data(params, options) if (billing_address = options[:billing_address] || options[:address]) params[:address1] = billing_address[:address1] params[:address2] = billing_address[:address2] params[:city] = billing_address[:city] params[:stateProvince] = billing_address[:state] params[:zipPostalCode] = billing_address[:zip] params[:countryCode] = billing_address[:country] end end
add_hmac(params, method)
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 160 def add_hmac(params, method) if method == 'getSession' hmac_message = params[:pgwAccountNumber] + '|' + params[:pgwConfigurationId] + '|' + params[:requestTimeStamp] + '|' + method else hmac_message = params[:pgwAccountNumber] + '|' + params[:pgwConfigurationId] + '|' + (params[:orderNumber] || '') + '|' + method + '|' + (params[:amount] || '') + '|' + (params[:sessionToken] || '') + '|' + (params[:accountToken] || '') end OpenSSL::HMAC.hexdigest('sha512', @options[:secret], hmac_message) end
add_invoice(params, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 179 def add_invoice(params, money, options) params[:amount] = amount(money) params[:orderNumber] = options[:order_id] params[:transactionClass] = options[:transaction_class] || 'eCommerce' end
add_payment_method(params, credit_card)
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 185 def add_payment_method(params, credit_card) params[:cardExp] = format(credit_card.month, :two_digits).to_s + '/' + format(credit_card.year, :two_digits).to_s params[:cardType] = BRAND_MAP[credit_card.brand.to_s] params[:cvv] = credit_card.verification_value params[:firstName] = credit_card.first_name params[:lastName] = credit_card.last_name end
add_request_id(post)
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 152 def add_request_id(post) post[:id] = SecureRandom.hex(16) end
add_timestamp()
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 156 def add_timestamp Time.now.getutc.strftime('%Y%m%d%H%M%S') end
auth_or_sale(method, authorization, amount, credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 229 def auth_or_sale(method, authorization, amount, credit_card, options = {}) post = {} post[:method] = method add_request_id(post) params = {} if credit_card _, params[:sessionToken] = split_authorization(authorization) add_payment_method(params, credit_card) add_customer_data(params, options) else _, params[:accountToken] = split_authorization(authorization) end add_invoice(params, amount, options) add_credentials(params, post[:method]) post[:params] = [params] commit('v1/', post) end
avs_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 384 def avs_from(response) response['result'].key?('avsResponse') ? AVSResult.new(code: response['result']['avsResponse']) : nil end
commit(endpoint, post)
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 303 def commit(endpoint, post) raw_response = ssl_post(url() + endpoint, post_data(post), headers) response = parse(raw_response) rescue ResponseError => e raw_response = e.response.body response_error(raw_response) rescue JSON::ParserError unparsable_response(raw_response) else success = success_from(response) Response.new( success, message_from(response), response, authorization: success ? authorization_from(response, post[:method]) : nil, avs_result: success ? avs_from(response) : nil, cvv_result: success ? cvv_from(response) : nil, error_code: success ? nil : error_from(response), test: test? ) end
cvv_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 388 def cvv_from(response) response['result'].key?('cvvResponse') ? CVVResult.new(response['result']['cvvResponse']) : nil end
error_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 364 def error_from(response) return response['error'] if response['error'] return 'Failed' unless response.key?('result') return response['result']['pgwResponseCode'] || response['result']['processor']['responseCode'] || 'Failed' end
get_session(options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 204 def get_session(options = {}) post = {} post[:method] = 'getSession' add_request_id(post) params = {} add_credentials(params, post[:method]) post[:params] = [params] commit('session', post) end
get_token(authorization, payment_method, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 216 def get_token(authorization, payment_method, options = {}) post = {} post[:method] = 'tokenize' add_request_id(post) params = {} _, params[:sessionId] = split_authorization(authorization) params[:cardNumber] = payment_method.number post[:params] = [params] commit('token', post) end
headers()
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 325 def headers { 'Content-Type' => 'application/json' } end
message_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 353 def message_from(response) return response['error'] if response['error'] return 'Failed' unless response.key?('result') if response['result'].key?('pgwResponseCode') RESPONSE_CODE_MAPPING[response['result']['pgwResponseCode']] || response['result']['responseText'] else response['result']['lastActionSucceeded'] == 1 ? 'Succeeded' : 'Failed' end end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 339 def parse(body) JSON.parse(body) end
post_data(params)
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 331 def post_data(params) params.to_json end
refundWithCard(authorization, amount, credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 270 def refundWithCard(authorization, amount, credit_card, options = {}) post = {} post[:method] = 'refundWithCard' add_request_id(post) params = {} if credit_card _, params[:sessionToken] = split_authorization(authorization) add_payment_method(params, credit_card) else _, params[:accountToken] = split_authorization(authorization) end add_invoice(params, amount, options) add_credentials(params, post[:method]) post[:params] = [params] commit('v1/', post) end
response_error(raw_response)
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 392 def response_error(raw_response) response = parse(raw_response) rescue JSON::ParserError unparsable_response(raw_response) else return Response.new( false, message_from(response), response, test: test? ) end
reverse_or_void(method, pgwTID, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 289 def reverse_or_void(method, pgwTID, options = {}) post = {} post[:method] = method add_request_id(post) params = {} params[:orderNumber] = options[:order_id] params[:pgwTID] = pgwTID add_credentials(params, post[:method]) post[:params] = [params] commit('v1/', post) end
success_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 343 def success_from(response) return false if response['result'].nil? || response['error'] if response['result'].key?('pgwResponseCode') response['error'].nil? && response['result']['lastActionSucceeded'] == 1 && response['result']['pgwResponseCode'] == '100' else response['error'].nil? && response['result']['lastActionSucceeded'] == 1 end end
unparsable_response(raw_response)
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 405 def unparsable_response(raw_response) message = 'Invalid JSON response received from Latitude19Gateway. Please contact Latitude19Gateway if you continue to receive this message.' message += " (The raw response returned by the API was #{raw_response.inspect})" return Response.new(false, message) end
url()
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 335 def url test? ? test_url : live_url end
verifyOnly(action, authorization, credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/latitude19.rb, line 249 def verifyOnly(action, authorization, credit_card, options = {}) post = {} post[:method] = 'verifyOnly' add_request_id(post) params = {} if credit_card _, params[:sessionToken] = split_authorization(authorization) add_payment_method(params, credit_card) add_customer_data(params, options) else _, params[:accountToken] = split_authorization(authorization) end params[:requestAccountToken] = '1' if action == 'store' add_invoice(params, 0, options) add_credentials(params, post[:method]) post[:params] = [params] commit('v1/', post) end