Class: OffsitePayments::Integrations::Coinbase::Notification

Inherits:
Notification
  • Object
show all
Defined in:
lib/offsite_payments/integrations/coinbase.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 = {}) ⇒ Object

Acknowledge the transaction to Coinbase. This method has to be called after a new apc arrives. Coinbase will verify that all the information we received are correct and will return a ok or a fail.



107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/offsite_payments/integrations/coinbase.rb', line 107

def acknowledge(authcode = {})
  uri = URI.parse(Coinbase.notification_confirmation_url % transaction_id)

  response = Coinbase.do_request(uri, @options[:credential1], @options[:credential2])
  return false if response.nil?

  posted_order = @params
  parse(response)

  return false unless @params
  %w(id custom total_native status).all? { |param| posted_order[param] == @params[param] }
end

#complete?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/offsite_payments/integrations/coinbase.rb', line 67

def complete?
  status == "Completed"
end

#currencyObject



91
92
93
# File 'lib/offsite_payments/integrations/coinbase.rb', line 91

def currency
  params['total_native']['currency_iso']
end

#grossObject



83
84
85
86
87
88
89
# File 'lib/offsite_payments/integrations/coinbase.rb', line 83

def gross
  if params['total_original'].present?
    "%.2f" % (params['total_original']['cents'].to_f / 100)
  else
    "%.2f" % (params['total_native']['cents'].to_f / 100)
  end
end

#item_idObject



71
72
73
# File 'lib/offsite_payments/integrations/coinbase.rb', line 71

def item_id
  params['custom']
end

#received_atObject



79
80
81
# File 'lib/offsite_payments/integrations/coinbase.rb', line 79

def received_at
  Time.iso8601(params['created_at']).to_time.to_i
end

#statusObject



95
96
97
98
99
100
101
102
# File 'lib/offsite_payments/integrations/coinbase.rb', line 95

def status
  case params['status']
  when "completed"
    "Completed"
  else
    "Failed"
  end
end

#transaction_idObject



75
76
77
# File 'lib/offsite_payments/integrations/coinbase.rb', line 75

def transaction_id
  params['id']
end