Jason wrote:
> Hi,
> Did you every get your PayPal IPN script working. If so, did you use a
> plugin or custom code? Would you be willing to share this code for
> reference? I am looking to accomplish the same task as you.
>
> Thanks,
> Jason
>
> On Aug 20 2008, 10:26�am, P�l Bergstr�m <rails-mailing-l...@andreas-
This is what I have as a IPN script.
[code]
if request.post?
#new
@params = params
@params[:cmd] = "_notify-validate"
@params.delete(:action)
@params.delete(:controller)
url = URI.parse("https://www.paypal.com/cgi-bin/webscr")
req = Net::HTTP::Post.new(url.path)
req.set_form_data(@params)
sock = Net::HTTP.new(url.host, url.port)
sock.use_ssl = true
response = sock.start {|http| http.request(req)}
item_name = params[:item_name]
payment_status = params[:payment_status]
payment_amount = params[:mc_gross]
payment_currency = params[:mc_currency]
payer_email = params[:payer_email]
receiver_email = params[:receiver_email]
txn_id = params[:txn_id]
if response
@user = User.find_by_email(payer_email)
if @user
#find account and update
@account = Account.find_by_user_id(@user.id)
unless @account
@account = Account.new()
end
@account.status = 'Init'
end
if response.body == 'VERIFIED'
if payment_status == 'Completed'
@date = Date.today() + 365
@account.ipn = 'Completed'
@account.status = 'Completed'
@account.amount = payment_amount
@account.paypal_id = txn_id
@account.expires = @date
@account.save
@user.status = "Open"
@user.expires = @date
@user.save(false)
else
@account.status = 'Not Verified'
@account.save
@account.update_attribute(:ipn,'Pending')
end
else
@account.status = 'Not-Passed'
@account.save
end
end
end
render :nothing => true
[/code]
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---