Class: Payment

Inherits:
Object
  • Object
show all
Includes:
OffsitePayments::Integrations
Defined in:
app/models/payment.rb

Overview

Handle payment related logic


Class Method Summary collapse

Class Method Details

.event_payment_ipn(notify, payment_method = '') ⇒ Object

Handle Payment notification logic




8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/payment.rb', line 8

def self.event_payment_ipn(notify, payment_method = '')
  Rails.logger.error('===> Enter: Payment.event_payment_ipn')
  Rails.logger.error(notify.inspect)
  registration = Registration.find_by_receipt_code(notify.item_id)
  
  if notify.acknowledge
    if registration
      Rails.logger.error(registration.inspect)
      payment_history = PaymentHistory.find_by_transaction_id(notify.transaction_id) ||
                          registration.manual_payment( nil,
                                        notify.amount.to_f.to_s,
                                        notify.currency,
                                        nil,
                                        payment_method: payment_method,
                                        payment_date: notify.received_at,
                                        notify_data: notify,
                                        transaction_id: notify.transaction_id,
                                        status: notify.status
                    )
        Rails.logger.error(payment_history.inspect)
      begin
        if notify.complete?
          payment_history.status = notify.status
        else
          # TODO need to handle refunding, etc
          Rails.logger.error("Failed to verify #{payment_method} payment notification, please investigate")
        end
      rescue => e
        payment_history.status = 'Error'
        raise
      ensure
        payment_history.save
      end
    else
      #--- [todo] a linked registration was not found.  Should be stored in payment table anyway
      Rails.logger.error("   > Error: Registration was not found: #{notify.item_id}")
    end
  end
end