class ActiveMerchant::Billing::DecidirGateway
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/decidir.rb, line 44 def initialize(options={}) requires!(options, :api_key) super @options[:preauth_mode] ||= false end
Public Instance Methods
capture(money, authorization, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/decidir.rb, line 66 def capture(money, authorization, options={}) raise ArgumentError, 'Capture is not supported on Decidir gateways unless the preauth_mode option is enabled' unless @options[:preauth_mode] post = {} add_amount(post, money, options) commit(:put, "payments/#{authorization}", post) end
purchase(money, payment, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/decidir.rb, line 50 def purchase(money, payment, options={}) raise ArgumentError, 'Purchase is not supported on Decidir gateways configured with the preauth_mode option' if @options[:preauth_mode] post = {} add_auth_purchase_params(post, money, payment, options) commit(:post, 'payments', post) end
refund(money, authorization, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/decidir.rb, line 74 def refund(money, authorization, options={}) post = {} add_amount(post, money, options) commit(:post, "payments/#{authorization}/refunds", post) end
scrub(transcript)
click to toggle source
# File lib/active_merchant/billing/gateways/decidir.rb, line 98 def scrub(transcript) transcript. gsub(%r((apikey: )\w+)i, '\1[FILTERED]'). gsub(%r((\"card_number\\\":\\\")\d+), '\1[FILTERED]'). gsub(%r((\"security_code\\\":\\\")\d+), '\1[FILTERED]'). gsub(%r((\"emv_issuer_data\\\":\\\")\d+), '\1[FILTERED]') end
supports_scrubbing?()
click to toggle source
# File lib/active_merchant/billing/gateways/decidir.rb, line 94 def supports_scrubbing? true end
verify(credit_card, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/decidir.rb, line 85 def verify(credit_card, options={}) raise ArgumentError, 'Verify is not supported on Decidir gateways unless the preauth_mode option is enabled' unless @options[:preauth_mode] 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/decidir.rb, line 80 def void(authorization, options={}) post = {} commit(:post, "payments/#{authorization}/refunds", post) end
Private Instance Methods
add_amount(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/decidir.rb, line 127 def add_amount(post, money, options) currency = (options[:currency] || currency(money)) post[:amount] = localized_amount(money, currency).to_i end
add_auth_purchase_params(post, money, credit_card, options)
click to toggle source
# File lib/active_merchant/billing/gateways/decidir.rb, line 108 def add_auth_purchase_params(post, money, credit_card, options) post[:payment_method_id] = options[:payment_method_id] ? options[:payment_method_id].to_i : 1 post[:site_transaction_id] = options[:order_id] post[:bin] = credit_card.number[0..5] post[:payment_type] = options[:payment_type] || 'single' post[:installments] = options[:installments] ? options[:installments].to_i : 1 post[:description] = options[:description] if options[:description] post[:email] = options[:email] if options[:email] post[:sub_payments] = [] add_invoice(post, money, options) add_payment(post, credit_card, options) end
add_invoice(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/decidir.rb, line 122 def add_invoice(post, money, options) add_amount(post, money, options) post[:currency] = (options[:currency] || currency(money)) end
add_payment(post, credit_card, options)
click to toggle source
# File lib/active_merchant/billing/gateways/decidir.rb, line 132 def add_payment(post, credit_card, options) card_data = {} card_data[:card_number] = credit_card.number card_data[:card_expiration_month] = format(credit_card.month, :two_digits) card_data[:card_expiration_year] = format(credit_card.year, :two_digits) card_data[:security_code] = credit_card.verification_value if credit_card.verification_value? card_data[:card_holder_name] = credit_card.name if credit_card.name # additional data used for Visa transactions card_data[:card_holder_door_number] = options[:card_holder_door_number].to_i if options[:card_holder_door_number] card_data[:card_holder_birthday] = options[:card_holder_birthday] if options[:card_holder_birthday] card_data[:card_holder_identification] = {} card_data[:card_holder_identification][:type] = options[:card_holder_identification_type] if options[:card_holder_identification_type] card_data[:card_holder_identification][:number] = options[:card_holder_identification_number] if options[:card_holder_identification_number] post[:card_data] = card_data end
commit(method, endpoint, parameters, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/decidir.rb, line 159 def commit(method, endpoint, parameters, options={}) url = "#{(test? ? test_url : live_url)}/#{endpoint}" begin raw_response = ssl_request(method, url, post_data(parameters), headers(options)) response = parse(raw_response) rescue ResponseError => e raw_response = e.response.body response = parse(raw_response) end success = success_from(response) Response.new( success, message_from(success, response), response, authorization: authorization_from(response), test: test?, error_code: success ? nil : error_code_from(response) ) end
error_code_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/decidir.rb, line 219 def error_code_from(response) error_code = nil if error = response.dig('status_details', 'error') code = error.dig('reason', 'id') error_code = STANDARD_ERROR_CODE_MAPPING[code] error_code ||= error['type'] elsif response['error_type'] error_code = response['error_type'] if response['validation_errors'] end error_code || STANDARD_ERROR_CODE[:processing_error] end
headers(options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/decidir.rb, line 151 def headers(options = {}) { 'apikey' => @options[:api_key], 'Content-type' => 'application/json', 'Cache-Control' => 'no-cache' } end
message_from(success, response)
click to toggle source
# File lib/active_merchant/billing/gateways/decidir.rb, line 193 def message_from(success, response) return response['status'] if success return response['message'] if response['message'] message = nil if error = response.dig('status_details', 'error') message = error.dig('reason', 'description') elsif response['error_type'] if response['validation_errors'] message = response['validation_errors'].map { |errors| "#{errors['code']}: #{errors['param']}" }.join(', ') end message ||= response['error_type'] end message end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/decidir.rb, line 185 def parse(body) JSON.parse(body) rescue JSON::ParserError { 'message' => "A non-JSON response was received from Decidir where one was expected. The raw response was:\n\n#{body}" } end
post_data(parameters = {})
click to toggle source
# File lib/active_merchant/billing/gateways/decidir.rb, line 181 def post_data(parameters = {}) parameters.to_json end
success_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/decidir.rb, line 211 def success_from(response) response['status'] == 'approved' || response['status'] == 'pre_approved' end