Created
March 23, 2009 19:23
-
-
Save copyhacker/83727 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def notify | |
notify = Paypal::Notification.new(request.raw_post) | |
enrollment = Enrollment.find(notify.item_id) | |
if notify.acknowledge | |
@payment = Payment.find_by_confirmation(notify.transaction_id) || | |
enrollment.invoice.payments.create(:amount => notify.amount, | |
:payment_method => 'paypal', :confirmation => notify.transaction_id, | |
:description => notify.params['item_name'], :status => notify.status, | |
:test => notify.test?) | |
begin | |
if notify.complete? | |
@payment.status = notify.status | |
else | |
logger.error("Failed to verify Paypal's notification, please investigate") | |
end | |
rescue => e | |
@payment.status = 'Error' | |
raise | |
ensure | |
@payment.save | |
end | |
end | |
render :nothing => true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment