class Workarea::Klarna::Gateway::Request
Attributes
method[R]
order[R]
path[R]
summary[R]
Public Class Methods
new(order)
click to toggle source
# File lib/workarea/klarna/gateway/request.rb, line 7 def initialize(order) @order = order @summary = I18n.t('workarea.klarna.gateway.request.base') @path = '' @method = 'get' end
Public Instance Methods
body()
click to toggle source
# File lib/workarea/klarna/gateway/request.rb, line 24 def body; end
continent()
click to toggle source
# File lib/workarea/klarna/gateway/request.rb, line 63 def continent payment.address&.country&.continent end
continent_key()
click to toggle source
# File lib/workarea/klarna/gateway/request.rb, line 67 def continent_key return unless continent.present? Workarea.config.klarna_continent_keys[continent] end
password()
click to toggle source
# File lib/workarea/klarna/gateway/request.rb, line 55 def password return unless continent_key.present? ENV["WORKAREA_KLARNA_#{continent_key}_PASSWORD"].presence || rails_credentials[:password] || Workarea.config.send("klarna_#{continent_key.downcase}_password") end
sesssion()
click to toggle source
# File lib/workarea/klarna/gateway/request.rb, line 39 def sesssion @session ||= Payment::KlarnaSession.find_or_initialize_by(id: order.id) end
subdomain()
click to toggle source
# File lib/workarea/klarna/gateway/request.rb, line 43 def subdomain Workarea.config.klarna_subdomains[continent_key] end
url()
click to toggle source
# File lib/workarea/klarna/gateway/request.rb, line 26 def url @url ||= begin host = if Workarea.config.klarna_playground "https://#{subdomain}.playground.klarna.com" else "https://#{subdomain}.klarna.com" end "#{host}/#{path}" end end
username()
click to toggle source
# File lib/workarea/klarna/gateway/request.rb, line 47 def username return unless continent_key.present? ENV["WORKAREA_KLARNA_#{continent_key}_USERNAME"].presence || rails_credentials[:username] || Workarea.config.send("klarna_#{continent_key.downcase}_username") end
validate!()
click to toggle source
# File lib/workarea/klarna/gateway/request.rb, line 14 def validate! unless continent_key.present? && subdomain.present? && username.present? && password.present? raise Gateway::ContinentNotSupported.new end end
Private Instance Methods
order_id()
click to toggle source
# File lib/workarea/klarna/gateway/request.rb, line 79 def order_id @order.id end
payment()
click to toggle source
# File lib/workarea/klarna/gateway/request.rb, line 83 def payment @payment ||= Workarea::Payment.find(order_id) rescue Mongoid::Errors::NotFound, Mongoid::Errors::InvalidFind @payment = Workarea::Payment.new end
rails_credentials()
click to toggle source
# File lib/workarea/klarna/gateway/request.rb, line 74 def rails_credentials return {} unless continent_key.present? Rails.application.credentials.klarna.try(:[], continent_key.downcase.to_sym) || {} end