class OffsitePayments::Integrations::BitPay::Notification

Public Instance Methods

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

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

  request = Net::HTTP::Get.new(uri.path)
  response = http.request(request)

  received_attributes = [transaction_id, status]

  parse(response.body)

  received_attributes == [transaction_id, status]
end
complete?() click to toggle source
# File lib/offsite_payments/integrations/bit_pay.rb, line 112
def complete?
  status == "Completed"
end
currency() click to toggle source
# File lib/offsite_payments/integrations/bit_pay.rb, line 140
def currency
  params['currency']
end
gross() click to toggle source
# File lib/offsite_payments/integrations/bit_pay.rb, line 144
def gross
  params['price'].to_f
end
item_id() click to toggle source
# File lib/offsite_payments/integrations/bit_pay.rb, line 120
def item_id
  JSON.parse(params['posData'])['orderId']
end
received_at() click to toggle source

When was this payment received by the client.

# File lib/offsite_payments/integrations/bit_pay.rb, line 136
def received_at
  params['invoiceTime'].to_i
end
status() click to toggle source
# File lib/offsite_payments/integrations/bit_pay.rb, line 124
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 116
def transaction_id
  params['id']
end

Private Instance Methods

parse(body) click to toggle source
# File lib/offsite_payments/integrations/bit_pay.rb, line 165
def parse(body)
  @raw = body
  json = JSON.parse(@raw)

  @params = json.key?('data') ? json['data'] : json
end