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

Returns a new instance of Notification.



182
183
184
185
# File 'lib/offsite_payments/integrations/klarna.rb', line 182

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

Instance Method Details

#acknowledge(authcode = nil) ⇒ Object



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

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

#complete?Boolean

Returns:

  • (Boolean)


187
188
189
# File 'lib/offsite_payments/integrations/klarna.rb', line 187

def complete?
  status == 'Completed'
end

#currencyObject



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

def currency
  params["purchase_currency"].upcase
end

#grossObject



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

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

#gross_centsObject



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

def gross_cents
  params["order_amount"]
end

#item_idObject



191
192
193
# File 'lib/offsite_payments/integrations/klarna.rb', line 191

def item_id
  order
end

#payer_emailObject



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

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

#received_atObject



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

def received_at
  params["completed_at"]
end

#receiver_emailObject



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

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

#statusObject



224
225
226
227
228
229
230
231
# File 'lib/offsite_payments/integrations/klarna.rb', line 224

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

#transaction_idObject



195
196
197
# File 'lib/offsite_payments/integrations/klarna.rb', line 195

def transaction_id
  params["reference"]
end