lib/active_merchant/billing/gateways/dibs.rb in activemerchant-1.79.2 vs lib/active_merchant/billing/gateways/dibs.rb in activemerchant-1.80.0

- old
+ new

@@ -1,15 +1,15 @@ module ActiveMerchant #:nodoc: module Billing #:nodoc: class DibsGateway < Gateway - self.display_name = "DIBS" - self.homepage_url = "http://www.dibspayment.com/" + self.display_name = 'DIBS' + self.homepage_url = 'http://www.dibspayment.com/' - self.live_url = "https://api.dibspayment.com/merchant/v1/JSON/Transaction/" + self.live_url = 'https://api.dibspayment.com/merchant/v1/JSON/Transaction/' - self.supported_countries = ["US", "FI", "NO", "SE", "GB"] - self.default_currency = "USD" + self.supported_countries = ['US', 'FI', 'NO', 'SE', 'GB'] + self.default_currency = 'USD' self.money_format = :cents self.supported_cardtypes = [:visa, :master, :american_express, :discover] def initialize(options={}) requires!(options, :merchant_id, :secret_key) @@ -87,16 +87,16 @@ end private CURRENCY_CODES = Hash.new{|h,k| raise ArgumentError.new("Unsupported currency: #{k}")} - CURRENCY_CODES["USD"] = "840" - CURRENCY_CODES["DKK"] = "208" - CURRENCY_CODES["NOK"] = "578" - CURRENCY_CODES["SEK"] = "752" - CURRENCY_CODES["GBP"] = "826" - CURRENCY_CODES["EUR"] = "978" + CURRENCY_CODES['USD'] = '840' + CURRENCY_CODES['DKK'] = '208' + CURRENCY_CODES['NOK'] = '578' + CURRENCY_CODES['SEK'] = '752' + CURRENCY_CODES['GBP'] = '826' + CURRENCY_CODES['EUR'] = '978' def add_invoice(post, money, options) post[:orderId] = options[:order_id] || generate_unique_id post[:currency] = CURRENCY_CODES[options[:currency] || currency(money)] end @@ -112,11 +112,11 @@ post[:expMonth] = payment_method.month post[:startMonth] = payment_method.start_month if payment_method.start_month post[:startYear] = payment_method.start_year if payment_method.start_year post[:issueNumber] = payment_method.issue_number if payment_method.issue_number - post[:clientIp] = options[:ip] || "127.0.0.1" + post[:clientIp] = options[:ip] || '127.0.0.1' post[:test] = true if test? end def add_reference(post, authorization) @@ -126,16 +126,16 @@ def add_amount(post, amount) post[:amount] = amount end ACTIONS = { - authorize: "AuthorizeCard", - authorize_ticket: "AuthorizeTicket", - capture: "CaptureTransaction", - void: "CancelTransaction", - refund: "RefundTransaction", - store: "CreateTicket" + authorize: 'AuthorizeCard', + authorize_ticket: 'AuthorizeTicket', + capture: 'CaptureTransaction', + void: 'CancelTransaction', + refund: 'RefundTransaction', + store: 'CreateTicket' } def commit(action, post) post[:merchantId] = @options[:merchant_id] @@ -153,21 +153,21 @@ unparsable_response(raw) end def headers { - "Content-Type" => "application/x-www-form-urlencoded" + 'Content-Type' => 'application/x-www-form-urlencoded' } end def build_request(post) add_hmac(post) post.to_json end def add_hmac(post) - data = post.sort.collect { |key, value| "#{key}=#{value.to_s}" }.join("&") + data = post.sort.collect { |key, value| "#{key}=#{value.to_s}" }.join('&') digest = OpenSSL::Digest.new('sha256') key = [@options[:secret_key]].pack('H*') post[:MAC] = OpenSSL::HMAC.hexdigest(digest, key, data) end @@ -178,26 +178,26 @@ def parse(body) JSON.parse(body) end def success_from(raw_response) - raw_response["status"] == "ACCEPT" + raw_response['status'] == 'ACCEPT' end def message_from(succeeded, response) if succeeded - "Succeeded" + 'Succeeded' else - response["status"] + ": " + response["declineReason"] || "Unable to read error message" + response['status'] + ': ' + response['declineReason'] || 'Unable to read error message' end end def authorization_from(request, response) response['transactionId'] || response['ticketId'] || request[:transactionId] end def unparsable_response(raw_response) - message = "Invalid JSON response received from Dibs. Please contact Dibs if you continue to receive this message." + message = 'Invalid JSON response received from Dibs. Please contact Dibs 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 end end