# PayPal IPN and SSL

**URL:** <https://www.ruby-forum.com/t/paypal-ipn-and-ssl/146396>\
**Category:** Rails\
**Created:** [August 20, 2008, 4:26pm UTC](https://www.ruby-forum.com/t/paypal-ipn-and-ssl/146396 "2008-08-20T16:26:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [August 20, 2008, 4:26pm UTC](https://www.ruby-forum.com/t/paypal-ipn-and-ssl/146396/1 "2008-08-20T16:26:12Z")

</div>

I have a PayPal IPN working. Well it did work. Now it doesn’t and I  
believe it has to do that they now want it to be posted via 443. Can I  
just change 80 to 443 and be ok?

@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.new(‘[www.paypal.com](http://www.paypal.com)’, 80)  
response = http.post(‘/cgi-bin/webscr’, @query)

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [August 20, 2008, 4:39pm UTC](https://www.ruby-forum.com/t/paypal-ipn-and-ssl/146396/2 "2008-08-20T16:39:38Z")

</div>

Frederick C. wrote:

> On 20 Aug 2008, at 15:26, Pï¿½l Bergstrï¿½m wrote:
> 
> > I have a PayPal IPN working. Well it did work. Now it doesn’t and I  
> > believe it has to do that they now want it to be posted via 443. Can I  
> > just change 80 to 443 and be ok?
> 
> you also need to set it to use ssl (just set http.use\_ssl to true)
> 
> Fred

Where and how do I add that?

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [August 20, 2008, 4:32pm UTC](https://www.ruby-forum.com/t/paypal-ipn-and-ssl/146396/3 "2008-08-20T16:32:51Z")

</div>

On 20 Aug 2008, at 15:26, Pål Bergström wrote:

> I have a PayPal IPN working. Well it did work. Now it doesn’t and I  
> believe it has to do that they now want it to be posted via 443. Can I  
> just change 80 to 443 and be ok?

you also need to set it to use ssl (just set http.use\_ssl to true)

Fred

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [August 20, 2008, 5:03pm UTC](https://www.ruby-forum.com/t/paypal-ipn-and-ssl/146396/4 "2008-08-20T17:03:37Z")

</div>

PÃ¥l BergstrÃ¶m wrote:

> Frederick C. wrote:
> 
> > On 20 Aug 2008, at 15:26, Pï¿½l Bergstrï¿½m wrote:
> > 
> > > I have a PayPal IPN working. Well it did work. Now it doesn’t and I  
> > > believe it has to do that they now want it to be posted via 443. Can I  
> > > just change 80 to 443 and be ok?
> > 
> > you also need to set it to use ssl (just set http.use\_ssl to true)
> > 
> > Fred
> 
> Is this correct?
> 
> http = Net::HTTP.new(‘[www.paypal.com](http://www.paypal.com)’, 80)  
> http.use\_ssl  
> response = http.post(‘/cgi-bin/webscr’, @query)

Another thing related to this. In the paypalipn respons I first check  
request.post? Is that ok?

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [August 20, 2008, 4:48pm UTC](https://www.ruby-forum.com/t/paypal-ipn-and-ssl/146396/5 "2008-08-20T16:48:58Z")

</div>

Frederick C. wrote:

> On 20 Aug 2008, at 15:26, Pï¿½l Bergstrï¿½m wrote:
> 
> > I have a PayPal IPN working. Well it did work. Now it doesn’t and I  
> > believe it has to do that they now want it to be posted via 443. Can I  
> > just change 80 to 443 and be ok?
> 
> you also need to set it to use ssl (just set http.use\_ssl to true)
> 
> Fred

Is this correct?

http = Net::HTTP.new(‘[www.paypal.com](http://www.paypal.com)’, 80)  
http.use\_ssl  
response = http.post(‘/cgi-bin/webscr’, @query)

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [May 18, 2009, 3:32pm UTC](https://www.ruby-forum.com/t/paypal-ipn-and-ssl/146396/6 "2009-05-18T15:32:50Z")

</div>

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-

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [May 18, 2009, 4:03pm UTC](https://www.ruby-forum.com/t/paypal-ipn-and-ssl/146396/7 "2009-05-18T16:03:26Z")

</div>

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.

```auto

 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

```

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [May 19, 2009, 6:30am UTC](https://www.ruby-forum.com/t/paypal-ipn-and-ssl/146396/8 "2009-05-19T06:30:30Z")

</div>

Hi PÃ¥l BergstrÃ¶m,

I suggest you use paypal plugin which is available  
here[http://dist.leetsoft.com/api/paypal/](http://dist.leetsoft.com/api/paypal/)…  
in the sanbox we can generate virtual ipn… but most of people gave  
negavtive feedback about ipn…

let me know anything else…  
Thanks  
Arun

Sent from Bangalore, KA, India

2009/5/18 PÃ¥l BergstrÃ¶m [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [May 20, 2009, 4:00am UTC](https://www.ruby-forum.com/t/paypal-ipn-and-ssl/146396/9 "2009-05-20T04:00:45Z")

</div>

Thanks Pål, I really appreciate your sample code.
