Class: TradoPaypalModule::IpnController

Inherits:
ApplicationController
  • Object
show all
Includes:
OffsitePayments::Integrations
Defined in:
app/controllers/trado_paypal_module/ipn_controller.rb

Instance Method Summary collapse

Instance Method Details

#updateObject

Handler for incoming Instant Payment Notifications from paypal about orders



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/trado_paypal_module/ipn_controller.rb', line 8

def update
  notify = Paypal::Notification.new(request.raw_post)
  
  if notify.acknowledge
    transaction = Transaction.where(order_id: notify.params['invoice']).first
    if notify.complete? and transaction.gross_amount.to_s == notify.params['mc_gross']
      transaction.fee = notify.params['mc_fee']
      transaction.completed!
    else
      transaction.failed!
    end
    if transaction.save
      Mailatron4000::Orders.confirmation_email(transaction.order) rescue Rails.logger.warn("PayPal IPN: Order #{transaction.order.id} confirmation email failed to send")
    end
  end

  render nothing: true
end