Module: Effective::Providers::Paypal

Extended by:
ActiveSupport::Concern
Included in:
OrdersController
Defined in:
app/controllers/effective/providers/paypal.rb

Instance Method Summary collapse

Instance Method Details

#paypal_postbackObject

TODO: Make paypal postback work with admin checkout workflow



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/effective/providers/paypal.rb', line 12

def paypal_postback
  raise('paypal provider is not available') unless EffectiveOrders.paypal?

  @order ||= Effective::Order.deep.where(id: (params[:invoice].to_i rescue 0)).first

  # We do this even if we're not authorized
  EffectiveResources.authorized?(self, :update, @order)

  if @order.present?
    if @order.purchased?
      order_purchased(payment: params, provider: 'paypal', card: params[:payment_type])
    elsif (params[:payment_status] == 'Completed' && params[:custom] == EffectiveOrders.paypal[:secret])
      order_purchased(payment: params, provider: 'paypal', card: params[:payment_type], current_user: current_user)
    else
      order_declined(payment: params, provider: 'paypal', card: params[:payment_type])
    end
  end

  head(:ok)
end