Skip to content

Instantly share code, notes, and snippets.

@eastmedia
Created August 14, 2009 16:34
Show Gist options
  • Save eastmedia/167932 to your computer and use it in GitHub Desktop.
Save eastmedia/167932 to your computer and use it in GitHub Desktop.
def paypal_ipn
notify = Paypal::Notification.new(request.raw_post)
donations = Donation.find_all_from_paypal(notify.params)
user = donations.first.user
purchase = Purchase.new(:donations => donations, :user => user)
purchase.paypal_transaction_id = notify.transaction_id
if notify.acknowledge
if notify.complete? and purchase.total_amount == BigDecimal.new(notify.amount.to_s)
purchase.save
else
logger.error("PayPal acknowledgement was unpaid or the amounts didn't match for the following transaction: #{notify.params['txn_id']}")
end
else
logger.error("Failed to verify Paypal's notification, please investigate: #{notify.params['txn_id']}")
end
render :nothing => true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment