2010-11-21 13:41:06 +00:00
|
|
|
class PaypalExpressCallbacksController < Spree::BaseController
|
|
|
|
include ActiveMerchant::Billing::Integrations
|
|
|
|
skip_before_filter :verify_authenticity_token
|
|
|
|
|
2011-01-25 11:30:18 +00:00
|
|
|
ssl_required
|
|
|
|
|
2010-11-21 13:41:06 +00:00
|
|
|
def notify
|
2010-11-24 09:31:31 +00:00
|
|
|
retrieve_details #need to retreive details first to ensure ActiveMerchant gets configured correctly.
|
|
|
|
|
2011-01-24 19:56:04 +00:00
|
|
|
|
2010-11-21 13:41:06 +00:00
|
|
|
@notification = Paypal::Notification.new(request.raw_post)
|
|
|
|
|
|
|
|
# we only care about eChecks (for now?)
|
2011-01-11 13:13:58 +00:00
|
|
|
if @notification.params["payment_type"] == "echeck" && @notification.acknowledge && @payment && @order.total >= @payment.amount
|
2011-01-24 19:56:04 +00:00
|
|
|
@payment.started_processing!
|
|
|
|
@payment.log_entries.create(:details => @notification.to_yaml)
|
|
|
|
|
2010-11-21 13:41:06 +00:00
|
|
|
case @notification.params["payment_status"]
|
|
|
|
when "Denied"
|
2011-01-24 19:56:04 +00:00
|
|
|
@payment.fail!
|
2010-11-21 13:41:06 +00:00
|
|
|
|
|
|
|
when "Completed"
|
2011-01-24 19:56:04 +00:00
|
|
|
@payment.complete!
|
2010-11-21 13:41:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
render :nothing => true
|
2010-01-22 16:29:55 +00:00
|
|
|
end
|
2010-11-21 13:41:06 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
def retrieve_details
|
2010-11-24 09:31:31 +00:00
|
|
|
@order = Order.find_by_number(params["invoice"])
|
|
|
|
|
|
|
|
if @order
|
2011-01-24 19:56:04 +00:00
|
|
|
@payment = @order.payments.where(:state => "pending", :source_type => "PaypalAccount").try(:first)
|
2010-11-24 09:31:31 +00:00
|
|
|
|
|
|
|
@payment.try(:payment_method).try(:provider) #configures ActiveMerchant
|
|
|
|
end
|
2010-11-21 13:41:06 +00:00
|
|
|
end
|
|
|
|
|
2010-01-22 16:29:55 +00:00
|
|
|
end
|