Created
August 24, 2011 07:57
-
-
Save pphetra/1167525 to your computer and use it in GitHub Desktop.
ipm
This file contains hidden or 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
| # process the PayPal <span class="caps">IPN POST</span> | |
| def paypal_ipn | |
| if @request.method == :post | |
| # use the POSTed information to create a call back URL to PayPal | |
| @query = ‘cmd=_notify-validate’ | |
| @request.params.each_pair {|key, value| @query = @query + ’&’ + key + ’=’ | |
| + value.first if key != ‘register/pay_pal_ipn.html/pay_pal_ipn’ } | |
| http = Net::HTTP.start(PAYPAL_URL, 80) | |
| response = http.post(’/cgi-bin/webscr’, @query) | |
| http.finish | |
| # PayPal values | |
| item_name = @params[:item_name] | |
| item_number = @params[:item_number] | |
| payment_status = @params[:payment_status] | |
| payment_amount = @params[:mc_gross] | |
| payment_currency = @params[:mc_currency] | |
| txn_id = @params[:txn_id] | |
| receiver_email = @params[:receiver_email] | |
| payer_email = @params[:payer_email] | |
| if response | |
| if response.body.chomp ‘VERIFIED’ | |
| # check the payment status | |
| if payment_status ‘Completed’ | |
| # check to see if the txn_id already exists | |
| # your logic here | |
| end | |
| end | |
| else | |
| # <span class="caps">GET</span> request, wtf | |
| @text = ‘I do not speak GET’ | |
| end | |
| rescue Net::HTTPError | |
| @text = ‘HTTP error’ | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment