Sha256: 631d69852f95638f8e81d8b2d1edb00debb7612e43dce8a0a81487269e52a55b

Contents?: true

Size: 1.98 KB

Versions: 4

Compression:

Stored size: 1.98 KB

Contents

# Handle payment related logic
#------------------------------------------------------------------------------
class Payment
  include OffsitePayments::Integrations

  # Handle Payment notification logic
  #------------------------------------------------------------------------------
  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

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dm_event-4.2.3.10 app/models/payment.rb
dm_event-4.2.3.9 app/models/payment.rb
dm_event-4.2.3.8 app/models/payment.rb
dm_event-4.2.3.7 app/models/payment.rb