Class: OffsitePayments::Integrations::BitPay::Notification

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



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# 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?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/offsite_payments/integrations/bit_pay.rb', line 112

def complete?
  status == "Completed"
end

#currencyObject



140
141
142
# File 'lib/offsite_payments/integrations/bit_pay.rb', line 140

def currency
  params['currency']
end

#grossObject



144
145
146
# File 'lib/offsite_payments/integrations/bit_pay.rb', line 144

def gross
  params['price'].to_f
end

#item_idObject



120
121
122
# File 'lib/offsite_payments/integrations/bit_pay.rb', line 120

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

#received_atObject

When was this payment received by the client.



136
137
138
# File 'lib/offsite_payments/integrations/bit_pay.rb', line 136

def received_at
  params['invoiceTime'].to_i
end

#statusObject



124
125
126
127
128
129
130
131
132
133
# 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_idObject



116
117
118
# File 'lib/offsite_payments/integrations/bit_pay.rb', line 116

def transaction_id
  params['id']
end