<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>random ripples - groovy tag</title>
  <link>http://www.rippleinteractive.com:80/blog/tags/groovy/</link>
  <description>java, groovy and other random thoughts</description>
  <language>en</language>
  <copyright>Edward Povazan</copyright>
  <lastBuildDate>Fri, 29 Aug 2008 05:24:00 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  
  <item>
    <title>Groovily Verifying a PayPal Event</title>
    <link>http://www.rippleinteractive.com:80/blog/2008/08/28/1219987440000.html</link>
    
      
        <description>
          &lt;p&gt;
I&#039;ve been dealing with PayPal subscriptions for a little while now, using it to manage quite a complex subscription scheme. Though I encrypt my PayPal buttons, the notifications from PayPal are sent to an unencrypted URL, so I need check with PayPal to make sure the notifications are in fact from them. To do this, one sends back the notification&#039;s request parameters, to which PayPal respond with a &#039;VERIFIED&#039; or &#039;INVALID&#039; string.
&lt;p&gt;
&lt;p&gt;
After digging about for some Java code to do this, I couldn&#039;t resist converting it to Groovy. I like to do this, both to understand what the code does, and also to practice some of the Groovy APIs I don&#039;t get to use every day. And of course, any excuse to call one of my favourites, &lt;code&gt;inject&lt;/code&gt;.&lt;br/&gt;
The code is quite terse:
&lt;pre class=&#034;codeSample&#034;&gt;
def verifyIPN(request) {
    def names = request.getParameterNames().toList()
    def paramString = names.inject(&#039;cmd=_notify-validate&#039;) { result, name -&gt;
        def value = request.getParameter(name)
        result &lt;&lt; &#034;&amp;${name}=${URLEncoder.encode(value)}&#034;
    }

    def url = new URL(grailsApplication.config.grails.paypal.url)
    def conn = url.openConnection()
    conn.setDoOutput(true)
    conn.setRequestProperty(&#034;Content-Type&#034;, &#034;application/x-www-form-urlencoded&#034;)

    conn.getOutputStream().withWriter { writer -&gt; writer &lt;&lt; paramString }
    return conn.getInputStream().withReader { reader -&gt; reader.readLine() }
}
&lt;/pre&gt;
In the end, all I want is clear code. &lt;br /&gt;
I sometimes think my code will start appealing to Perl hackers. What do you think?
&lt;/p&gt;
        </description>
      
      
    
    
    
    <category>Programming</category>
    
    <category>Groovy</category>
    
    <category>Snippets</category>
    
    <category>Grails</category>
    
    <comments>http://www.rippleinteractive.com:80/blog/2008/08/28/1219987440000.html#comments</comments>
    <guid isPermaLink="true">http://www.rippleinteractive.com:80/blog/2008/08/28/1219987440000.html</guid>
    <pubDate>Fri, 29 Aug 2008 05:24:00 GMT</pubDate>
  </item>
  
  </channel>
</rss>
