Class: OffsitePayments::Integrations::Klarna::Notification

Inherits:
Notification
  • Object
show all
Defined in:
lib/offsite_payments/integrations/klarna.rb

Defined Under Namespace

Classes: Verifier

Instance Attribute Summary

Attributes inherited from Notification

#params, #raw

Instance Method Summary collapse

Methods inherited from Notification

#amount, #empty!, #iso_currency, #test?, #valid_sender?

Constructor Details

#initialize(post, options = {}) ⇒ Notification


198
199
200
201
# File 'lib/offsite_payments/integrations/klarna.rb', line 198

def initialize(post, options = {})
  super
  @shared_secret = @options[:credential2]
end

Instance Method Details

#acknowledge(authcode = nil) ⇒ Object


249
250
251
# File 'lib/offsite_payments/integrations/klarna.rb', line 249

def acknowledge(authcode = nil)
  Verifier.new(@options[:authorization_header], @raw, @shared_secret).verify
end

#complete?Boolean


203
204
205
# File 'lib/offsite_payments/integrations/klarna.rb', line 203

def complete?
  status == 'Completed'
end

#currencyObject


227
228
229
# File 'lib/offsite_payments/integrations/klarna.rb', line 227

def currency
  params["purchase_currency"].upcase
end

#grossObject


231
232
233
234
# File 'lib/offsite_payments/integrations/klarna.rb', line 231

def gross
  amount = Float(gross_cents) / 100
  sprintf("%.2f", amount)
end

#gross_centsObject


236
237
238
# File 'lib/offsite_payments/integrations/klarna.rb', line 236

def gross_cents
  params["cart"]["total_price_including_tax"]
end

#item_idObject


207
208
209
# File 'lib/offsite_payments/integrations/klarna.rb', line 207

def item_id
  order
end

#payer_emailObject


219
220
221
# File 'lib/offsite_payments/integrations/klarna.rb', line 219

def payer_email
  params["billing_address"]["email"]
end

#received_atObject


215
216
217
# File 'lib/offsite_payments/integrations/klarna.rb', line 215

def received_at
  params["completed_at"]
end

#receiver_emailObject


223
224
225
# File 'lib/offsite_payments/integrations/klarna.rb', line 223

def receiver_email
  params["shipping_address"]["email"]
end

#statusObject


240
241
242
243
244
245
246
247
# File 'lib/offsite_payments/integrations/klarna.rb', line 240

def status
  case params['status']
  when 'checkout_complete'
    'Completed'
  else
    params['status']
  end
end

#transaction_idObject


211
212
213
# File 'lib/offsite_payments/integrations/klarna.rb', line 211

def transaction_id
  params["reference"]
end