Class: OffsitePayments::Integrations::TwoCheckout::Notification

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

Instance Attribute Summary

Attributes inherited from Notification

#params, #raw

Instance Method Summary collapse

Methods inherited from Notification

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

Constructor Details

This class inherits a constructor from OffsitePayments::Notification

Instance Method Details

#acknowledge(authcode = nil) ⇒ Object

Checks against MD5 Hash



249
250
251
252
253
254
255
256
257
258
259
# File 'lib/offsite_payments/integrations/two_checkout.rb', line 249

def acknowledge(authcode = nil)
  return false if security_key.blank?
  if ins_message?
    Digest::MD5.hexdigest("#{ transaction_id }#{ params['vendor_id'] }#{ invoice_id }#{ secret }").upcase == security_key.upcase
  elsif passback?
    order_number = params['demo'] == 'Y' ? 1 : params['order_number']
    Digest::MD5.hexdigest("#{ secret }#{ params['sid'] }#{ order_number }#{ gross }").upcase == params['key'].upcase
  else
    false
  end
end

#complete?Boolean

Returns:

  • (Boolean)


190
191
192
# File 'lib/offsite_payments/integrations/two_checkout.rb', line 190

def complete?
  status == 'Completed'
end

#currencyObject

Seller currency sale was placed in



186
187
188
# File 'lib/offsite_payments/integrations/two_checkout.rb', line 186

def currency
  params['list_currency']
end

#grossObject

The money amount we received in X.2 decimal. passback || INS gross amount for new orders || default INS gross



225
226
227
# File 'lib/offsite_payments/integrations/two_checkout.rb', line 225

def gross
  params['invoice_list_amount'] || params['total'] || params['item_list_amount_1']
end

#invoice_idObject

2Checkout Invoice ID



205
206
207
# File 'lib/offsite_payments/integrations/two_checkout.rb', line 205

def invoice_id
  params['invoice_id']
end

#item_idObject

The value passed with ‘merchant_order_id’ is passed back as ‘vendor_order_id’



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

def item_id
  params['vendor_order_id'] || params['merchant_order_id']
end

#payer_emailObject

Customer Email



214
215
216
# File 'lib/offsite_payments/integrations/two_checkout.rb', line 214

def payer_email
  params['customer_email']
end

#received_atObject



209
210
211
# File 'lib/offsite_payments/integrations/two_checkout.rb', line 209

def received_at
  params['timestamp']
end

#secretObject

Secret Word defined in 2Checkout account



244
245
246
# File 'lib/offsite_payments/integrations/two_checkout.rb', line 244

def secret
  @options[:credential2]
end

#security_keyObject

The MD5 Hash



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

def security_key
  params['md5_hash'] || params['key']
end

#statusObject

Determine status based on parameter set, if the params include a fraud status we know we’re being notified of the finalization of an order (an INS message) If the params include ‘credit_card_processed’ we know we’re being notified of a new order being inbound, which we handle in the deferred demo sale scenario.



233
234
235
236
237
238
239
240
241
# File 'lib/offsite_payments/integrations/two_checkout.rb', line 233

def status
  if params['fraud_status'] == 'pass' || params['credit_card_processed'] == 'Y'
    'Completed'
  elsif params['fraud_status'] == 'wait'
    'Pending'
  else
    'Failed'
  end
end

#transaction_idObject

2Checkout Sale ID



200
201
202
# File 'lib/offsite_payments/integrations/two_checkout.rb', line 200

def transaction_id
  params['sale_id'] || params['order_number']
end

#typeObject

INS message type



181
182
183
# File 'lib/offsite_payments/integrations/two_checkout.rb', line 181

def type
  params['message_type']
end