spree_paypal_express/app/controllers/paypal_express_callbacks_co...

43 lines
1.1 KiB
Ruby
Raw Normal View History

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