class OffsitePayments::Integrations::Coinbase::Notification

Public Instance Methods

acknowledge(authcode = {}) click to toggle source

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.

# File lib/offsite_payments/integrations/coinbase.rb, line 103
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)

  %w(id custom total_native status).all? { |param| posted_order[param] == @params[param] }
end
complete?() click to toggle source
# File lib/offsite_payments/integrations/coinbase.rb, line 67
def complete?
  status == "Completed"
end
currency() click to toggle source
# File lib/offsite_payments/integrations/coinbase.rb, line 87
def currency
  params['total_native']['currency_iso']
end
gross() click to toggle source
# File lib/offsite_payments/integrations/coinbase.rb, line 83
def gross
  "%.2f" % (params['total_native']['cents'].to_f / 100)
end
item_id() click to toggle source
# File lib/offsite_payments/integrations/coinbase.rb, line 71
def item_id
  params['custom']
end
received_at() click to toggle source
# File lib/offsite_payments/integrations/coinbase.rb, line 79
def received_at
  Time.iso8601(params['created_at']).to_time.to_i
end
status() click to toggle source
# File lib/offsite_payments/integrations/coinbase.rb, line 91
def status
  case params['status']
  when "completed"
    "Completed"
  else
    "Failed"
  end
end
transaction_id() click to toggle source
# File lib/offsite_payments/integrations/coinbase.rb, line 75
def transaction_id
  params['id']
end

Private Instance Methods

parse(post) click to toggle source
# File lib/offsite_payments/integrations/coinbase.rb, line 118
def parse(post)
  @raw = post.to_s
  @params = JSON.parse(post)['order']
end