Class: ActiveMerchant::Billing::Integrations::BitPay::Notification

Inherits:
Notification
  • Object
show all
Defined in:
lib/active_merchant/billing/integrations/bit_pay/notification.rb

Instance Attribute Summary

Attributes inherited from Notification

#params, #raw

Instance Method Summary collapse

Methods inherited from Notification

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

Constructor Details

This class inherits a constructor from ActiveMerchant::Billing::Integrations::Notification

Instance Method Details

#acknowledge(authcode = nil) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/active_merchant/billing/integrations/bit_pay/notification.rb', line 45

def acknowledge(authcode = nil)
  uri = URI.parse("#{ActiveMerchant::Billing::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?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/active_merchant/billing/integrations/bit_pay/notification.rb', line 8

def complete?
  status == "Completed"
end

#currencyObject



37
38
39
# File 'lib/active_merchant/billing/integrations/bit_pay/notification.rb', line 37

def currency
  params['currency']
end

#grossObject



41
42
43
# File 'lib/active_merchant/billing/integrations/bit_pay/notification.rb', line 41

def gross
  params['price'].to_f
end

#item_idObject



16
17
18
19
# File 'lib/active_merchant/billing/integrations/bit_pay/notification.rb', line 16

def item_id
  JSON.parse(params['posData'])['orderId']
rescue JSON::ParserError
end

#received_atObject

When was this payment received by the client.



33
34
35
# File 'lib/active_merchant/billing/integrations/bit_pay/notification.rb', line 33

def received_at
  params['invoiceTime'].to_i
end

#statusObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/active_merchant/billing/integrations/bit_pay/notification.rb', line 21

def status
  case params['status']
  when 'complete'
    'Completed'
  when 'confirmed'
    'Pending'
  when 'invalid'
    'Failed'
  end
end

#transaction_idObject



12
13
14
# File 'lib/active_merchant/billing/integrations/bit_pay/notification.rb', line 12

def transaction_id
  params['id']
end