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
# File 'app/controllers/effective/providers/paypal.rb', line 12

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

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

  (EffectiveResources.authorize!(self, :update, @order) rescue false)

  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])
    else
      order_declined(payment: params, provider: 'paypal', card: params[:payment_type])
    end
  end

  head(:ok)
end