<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>paypal ipn variables instant payment notification subscr recurring_payment on random thoughts</title><link>https://awesomeprogrammer.com/categories/paypal-ipn-variables-instant-payment-notification-subscr-recurring_payment/</link><description>Recent content in paypal ipn variables instant payment notification subscr recurring_payment on random thoughts</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Mon, 04 Feb 2013 00:00:00 +0000</lastBuildDate><atom:link href="https://awesomeprogrammer.com/categories/paypal-ipn-variables-instant-payment-notification-subscr-recurring_payment/index.xml" rel="self" type="application/rss+xml"/><item><title>PayPal IPN madness with Ruby on Rails</title><link>https://awesomeprogrammer.com/blog/2013/02/04/paypal-ipn-madness-with-ruby-on-rails/</link><pubDate>Mon, 04 Feb 2013 00:00:00 +0000</pubDate><guid>https://awesomeprogrammer.com/blog/2013/02/04/paypal-ipn-madness-with-ruby-on-rails/</guid><description><![CDATA[<p>Lately I&rsquo;ve been implementing <a href="https://www.paypal.com/ipn">Instant Payment Notification</a> - <em>great</em> feature provided by PayPal. To be honest it cost me quite some time and a little bit of my dignity. I mean you can <a href="https://www.x.com/sites/default/files/ipnguide.pdf">read the official guide</a> and play with <a href="https://developer.paypal.com/cgi-bin/devscr?cmd=_ipn-link-session">Instant Payment Notification (IPN) simulator</a> - but in the end it&rsquo;s back to trials and errors.</p>
<p>So here we go, here are some tips for you, I hope you will find them useful and it will save you some time.</p>
<ol>
<li>
<p>When you receive an IPN notification you obviously have to send it back to paypal for verification (with additional <code>cmd=_notify-validate</code> option), don&rsquo;t forget to escape parameters while you do that (it may depend how you send it, but <code>URI.escape</code> may be your friend).</p>
</li>
<li>
<p>You may receive <code>txn_type</code> you didn&rsquo;t expect, here a (incomplete) list of possible variables:
<code>subscr_signup</code>,
<code>subscr_modify</code>,
<code>subscr_failed</code>,
<code>subscr_cancel</code>,
<code>subscr_payment</code>,
<code>subscr_eot</code>,
<code>recurring_payment_profile_created</code>,
<code>recurring_payment_profile_cancel</code>,
<code>recurring_payment_failed</code>,
<code>recurring_payment_outstanding_payment_failed</code>,
<code>recurring_payment</code>,
<code>recurring_payment_skipped</code>,
<code>recurring_payment_expired</code>,
<code>recurring_payment_suspended_due_to_max_failed_payment</code></p>
</li>
<li>
<p>What&rsquo;s more interesting (so to speak) is that you may receive different parameters depending on txn_type - for example if you get <code>subscr_</code> you can identify your buyer with <code>subscr_id</code>. On the other hand if you get a <code>recurring_payment_</code> you will have to use <code>recurring_payment_id</code>. There are more differences but you will have to debug it yourself - this is just a heads up.</p>
</li>
<li>
<p>PayPal tends to return a time in some messed up format (like <code>01:00:00 Jan 11, 2013 PST</code>) that can&rsquo;t be parsed using regular <code>Time.parse</code> method, instead you have to write your own parser:</p>
</li>
</ol>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">paypal_time</span>(time)
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">DateTime</span><span style="color:#f92672">.</span>strptime(time, <span style="color:#e6db74">&#34;%H:%M:%S %b %e, %Y %Z&#34;</span>)
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># you may also want to convert it back to UTC using .utc on in</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">end</span>
</span></span></code></pre></div><p>And thats four simple tips that can save A LOT of time.</p>]]></description><content:encoded><![CDATA[<p>Lately I&rsquo;ve been implementing <a href="https://www.paypal.com/ipn">Instant Payment Notification</a> - <em>great</em> feature provided by PayPal. To be honest it cost me quite some time and a little bit of my dignity. I mean you can <a href="https://www.x.com/sites/default/files/ipnguide.pdf">read the official guide</a> and play with <a href="https://developer.paypal.com/cgi-bin/devscr?cmd=_ipn-link-session">Instant Payment Notification (IPN) simulator</a> - but in the end it&rsquo;s back to trials and errors.</p>
<p>So here we go, here are some tips for you, I hope you will find them useful and it will save you some time.</p>
<ol>
<li>
<p>When you receive an IPN notification you obviously have to send it back to paypal for verification (with additional <code>cmd=_notify-validate</code> option), don&rsquo;t forget to escape parameters while you do that (it may depend how you send it, but <code>URI.escape</code> may be your friend).</p>
</li>
<li>
<p>You may receive <code>txn_type</code> you didn&rsquo;t expect, here a (incomplete) list of possible variables:
<code>subscr_signup</code>,
<code>subscr_modify</code>,
<code>subscr_failed</code>,
<code>subscr_cancel</code>,
<code>subscr_payment</code>,
<code>subscr_eot</code>,
<code>recurring_payment_profile_created</code>,
<code>recurring_payment_profile_cancel</code>,
<code>recurring_payment_failed</code>,
<code>recurring_payment_outstanding_payment_failed</code>,
<code>recurring_payment</code>,
<code>recurring_payment_skipped</code>,
<code>recurring_payment_expired</code>,
<code>recurring_payment_suspended_due_to_max_failed_payment</code></p>
</li>
<li>
<p>What&rsquo;s more interesting (so to speak) is that you may receive different parameters depending on txn_type - for example if you get <code>subscr_</code> you can identify your buyer with <code>subscr_id</code>. On the other hand if you get a <code>recurring_payment_</code> you will have to use <code>recurring_payment_id</code>. There are more differences but you will have to debug it yourself - this is just a heads up.</p>
</li>
<li>
<p>PayPal tends to return a time in some messed up format (like <code>01:00:00 Jan 11, 2013 PST</code>) that can&rsquo;t be parsed using regular <code>Time.parse</code> method, instead you have to write your own parser:</p>
</li>
</ol>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">paypal_time</span>(time)
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">DateTime</span><span style="color:#f92672">.</span>strptime(time, <span style="color:#e6db74">&#34;%H:%M:%S %b %e, %Y %Z&#34;</span>)
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># you may also want to convert it back to UTC using .utc on in</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">end</span>
</span></span></code></pre></div><p>And thats four simple tips that can save A LOT of time.</p>]]></content:encoded></item></channel></rss>