class OffsitePayments::Integrations::BitPay::Notification

Public Instance Methods

acknowledge(authcode = nil) click to toggle source
# File lib/offsite_payments/integrations/bit_pay.rb, line 119
def acknowledge(authcode = nil)
  uri = URI.parse("#{OffsitePayments::Integrations::BitPay.invoicing_url}/#{transaction_id}")

  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  request = Net::HTTP::Get.new(uri.path)
  request.basic_auth @options[:credential1], ''

  response = http.request(request)

  posted_json = JSON.parse(@raw).tap { |j| j.delete('currentTime') }
  parse(response.body)
  retrieved_json = JSON.parse(@raw).tap { |j| j.delete('currentTime') }

  posted_json == retrieved_json
rescue JSON::ParserError
end
complete?() click to toggle source
# File lib/offsite_payments/integrations/bit_pay.rb, line 82
def complete?
  status == "Completed"
end
currency() click to toggle source
# File lib/offsite_payments/integrations/bit_pay.rb, line 111
def currency
  params['currency']
end
gross() click to toggle source
# File lib/offsite_payments/integrations/bit_pay.rb, line 115
def gross
  params['price'].to_f
end
item_id() click to toggle source
# File lib/offsite_payments/integrations/bit_pay.rb, line 90
def item_id
  JSON.parse(params['posData'])['orderId']
rescue JSON::ParserError
end
received_at() click to toggle source

When was this payment received by the client.

# File lib/offsite_payments/integrations/bit_pay.rb, line 107
def received_at
  params['invoiceTime'].to_i
end
status() click to toggle source
# File lib/offsite_payments/integrations/bit_pay.rb, line 95
def status
  case params['status']
  when 'complete'
    'Completed'
  when 'confirmed'
    'Pending'
  when 'invalid'
    'Failed'
  end
end
transaction_id() click to toggle source
# File lib/offsite_payments/integrations/bit_pay.rb, line 86
def transaction_id
  params['id']
end

Private Instance Methods

parse(body) click to toggle source
# File lib/offsite_payments/integrations/bit_pay.rb, line 139
def parse(body)
  @raw = body
  @params = JSON.parse(@raw)
rescue JSON::ParserError
end