class ActiveMerchant::Billing::SecurionPayGateway
Constants
- 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/securion_pay.rb, line 34 def initialize(options = {}) requires!(options, :secret_key) super end
Public Instance Methods
capture(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 50 def capture(money, authorization, options = {}) post = {} add_amount(post, money, options) commit("charges/#{CGI.escape(authorization)}/capture", post, options) end
customer(options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 88 def customer(options = {}) if options[:customer_id].blank? return nil else commit("customers/#{CGI.escape(options[:customer_id])}", nil, options, :get) end end
purchase(money, payment, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 39 def purchase(money, payment, options = {}) post = create_post_for_auth_or_purchase(money, payment, options) commit('charges', post, options) end
refund(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 56 def refund(money, authorization, options = {}) post = {} add_amount(post, money, options) commit("charges/#{CGI.escape(authorization)}/refund", post, options) end
scrub(transcript)
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 100 def scrub(transcript) transcript. gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]'). gsub(%r((card\[number\]=)\d+), '\1[FILTERED]'). gsub(%r((card\[cvc\]=)\d+), '\1[FILTERED]') end
store(credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 73 def store(credit_card, options = {}) if options[:customer_id].blank? MultiResponse.run() do |r| # create charge object r.process { authorize(100, credit_card, options) } # create customer and save card r.process { create_customer_add_card(r.authorization, options) } # void the charge r.process(:ignore_result) { void(r.params['metadata']['chargeId'], options) } end else verify(credit_card, options) end end
supports_scrubbing?()
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 96 def supports_scrubbing? true end
verify(credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 66 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/securion_pay.rb, line 62 def void(authorization, options = {}) commit("charges/#{CGI.escape(authorization)}/refund", {}, options) end
Private Instance Methods
add_address(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 203 def add_address(post, options) return unless post[:card]&.kind_of?(Hash) if address = options[:billing_address] post[:card][:addressLine1] = address[:address1] if address[:address1] post[:card][:addressLine2] = address[:address2] if address[:address2] post[:card][:addressCountry] = address[:country] if address[:country] post[:card][:addressZip] = address[:zip] if address[:zip] post[:card][:addressState] = address[:state] if address[:state] post[:card][:addressCity] = address[:city] if address[:city] end end
add_amount(post, money, options, include_currency = false)
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 178 def add_amount(post, money, options, include_currency = false) currency = (options[:currency] || default_currency) post[:amount] = localized_amount(money, currency) post[:currency] = currency.downcase if include_currency end
add_creditcard(post, creditcard, options)
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 184 def add_creditcard(post, creditcard, options) card = {} if creditcard.respond_to?(:number) card[:number] = creditcard.number card[:expMonth] = creditcard.month card[:expYear] = creditcard.year card[:cvc] = creditcard.verification_value if creditcard.verification_value? card[:cardholderName] = creditcard.name if creditcard.name post[:card] = card add_address(post, options) elsif creditcard.kind_of?(String) key = creditcard.match(/^pm_/) ? :paymentMethod : :card post[key] = creditcard else raise ArgumentError.new("Unhandled payment method #{creditcard.class}.") end end
add_customer(post, payment, options)
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 119 def add_customer(post, payment, options) post[:customerId] = options[:customer_id] if options[:customer_id] end
add_customer_data(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 123 def add_customer_data(post, options) post[:description] = options[:description] post[:ip] = options[:ip] post[:user_agent] = options[:user_agent] post[:referrer] = options[:referrer] end
add_external_three_ds(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 144 def add_external_three_ds(post, options) return if options[:three_d_secure].blank? post[:threeDSecure] = { external: { version: options[:three_d_secure][:version], authenticationValue: options[:three_d_secure][:cavv], acsTransactionId: options[:three_d_secure][:acs_transaction_id], status: options[:three_d_secure][:authentication_response_status], eci: options[:three_d_secure][:eci] }.merge(xid_or_ds_trans_id(options[:three_d_secure])) } end
api_request(endpoint, parameters = nil, options = {}, method = nil)
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 286 def api_request(endpoint, parameters = nil, options = {}, method = nil) raw_response = response = nil begin if method.blank? raw_response = ssl_post(self.live_url + endpoint, post_data(parameters), headers(options)) else raw_response = ssl_request(method, self.live_url + endpoint, post_data(parameters), headers(options)) end response = parse(raw_response) rescue ResponseError => e raw_response = e.response.body response = response_error(raw_response) rescue JSON::ParserError response = json_error(raw_response) end response end
commit(url, parameters = nil, options = {}, method = nil)
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 220 def commit(url, parameters = nil, options = {}, method = nil) if parameters.present? && parameters[:threeDSecure].present? three_ds_errors = validate_three_ds_params(parameters[:threeDSecure][:external]) return three_ds_errors if three_ds_errors end response = api_request(url, parameters, options, method) success = success?(response) Response.new( success, (success ? 'Transaction approved' : response['error']['message']), response, test: test?, authorization: authorization_from(url, response), error_code: (success ? nil : STANDARD_ERROR_CODE_MAPPING[response['error']['code']]) ) end
create_customer_add_card(authorization, options)
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 109 def create_customer_add_card(authorization, options) post = {} post[:email] = options[:email] post[:description] = options[:description] post[:card] = authorization post[:metadata] = {} post[:metadata][:chargeId] = authorization commit('customers', post, options) end
create_post_for_auth_or_purchase(money, payment, options)
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 130 def create_post_for_auth_or_purchase(money, payment, options) post = {} add_amount(post, money, options, true) add_creditcard(post, payment, options) add_customer(post, payment, options) add_customer_data(post, options) add_external_three_ds(post, options) if options[:email] post[:metadata] = {} post[:metadata][:email] = options[:email] end post end
headers(options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 251 def headers(options = {}) secret_key = options[:secret_key] || @options[:secret_key] { 'Authorization' => 'Basic ' + Base64.encode64(secret_key.to_s + ':').strip, 'User-Agent' => "SecurionPay/v1 ActiveMerchantBindings/#{ActiveMerchant::VERSION}" } end
json_error(raw_response, gateway_name = 'SecurionPay')
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 304 def json_error(raw_response, gateway_name = 'SecurionPay') msg = "Invalid response received from the #{gateway_name} API." msg += " (The raw response returned by the API was #{raw_response.inspect})" { 'error' => { 'message' => msg } } end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 216 def parse(body) JSON.parse(body) end
post_data(params)
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 266 def post_data(params) return nil unless params params.map do |key, value| next if value.blank? if value.is_a?(Hash) h = {} value.each do |k, v| h["#{key}[#{k}]"] = v unless v.blank? end post_data(h) elsif value.is_a?(Array) value.map { |v| "#{key}[]=#{CGI.escape(v.to_s)}" }.join('&') else "#{key}=#{CGI.escape(value.to_s)}" end end.compact.join('&') end
response_error(raw_response)
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 260 def response_error(raw_response) parse(raw_response) rescue JSON::ParserError json_error(raw_response) end
success?(response)
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 247 def success?(response) !response.key?('error') end
test?()
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 314 def test? @options[:secret_key]&.include?('_test_') end
validate_three_ds_params(three_ds)
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 166 def validate_three_ds_params(three_ds) errors = {} supported_version = %w{1.0.2 2.1.0 2.2.0}.include?(three_ds[:version]) supported_auth_response = ['Y', 'N', 'U', 'R', 'E', 'A', nil].include?(three_ds[:status]) errors[:three_ds_version] = 'ThreeDs version not supported' unless supported_version errors[:auth_response] = 'Authentication response value not supported' unless supported_auth_response errors.compact! errors.present? ? Response.new(false, 'ThreeDs data is invalid', errors) : nil end
xid_or_ds_trans_id(three_ds)
click to toggle source
# File lib/active_merchant/billing/gateways/securion_pay.rb, line 158 def xid_or_ds_trans_id(three_ds) if three_ds[:version].to_f >= 2.0 { dsTransactionId: three_ds[:ds_transaction_id] } else { xid: three_ds[:xid] } end end