Module: OffsitePayments::Integrations::Klarna

Defined in:
lib/offsite_payments/integrations/klarna.rb

Defined Under Namespace

Classes: Helper, Notification

Constant Summary collapse

REQUIRED_FIELDS =
%w(amount checkout_token merchant_base_uri merchant_checkout_uri merchant_confirmation_uri merchant_id merchant_terms_uri purchase_currency)

Class Method Summary collapse

Class Method Details

.cart_items_payload(fields, cart_items) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/offsite_payments/integrations/klarna.rb', line 17

def self.cart_items_payload(fields, cart_items)
  check_required_fields!(fields)

  payload = ""
  REQUIRED_FIELDS.sort.each do |field|
     payload << fields[field].to_s
  end

  payload
end

.digest(payload, shared_secret) ⇒ Object



34
35
36
# File 'lib/offsite_payments/integrations/klarna.rb', line 34

def self.digest(payload, shared_secret)
  Digest::SHA256.base64digest(payload + shared_secret.to_s)
end

.notification(post_body, options = {}) ⇒ Object



9
10
11
# File 'lib/offsite_payments/integrations/klarna.rb', line 9

def self.notification(post_body, options = {})
  Notification.new(post_body, options)
end

.return(query_string, options = {}) ⇒ Object



13
14
15
# File 'lib/offsite_payments/integrations/klarna.rb', line 13

def self.return(query_string, options = {})
  Return.new(query_string, options)
end

.sign(fields, cart_items, shared_secret) ⇒ Object



28
29
30
31
32
# File 'lib/offsite_payments/integrations/klarna.rb', line 28

def self.sign(fields, cart_items, shared_secret)
  payload = cart_items_payload(fields, cart_items)

  digest(payload, shared_secret)
end