<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Wylie &#187; PayPal</title>
	<atom:link href="http://www.wyliethomas.com/blog/category/paypal/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wyliethomas.com/blog</link>
	<description>web consultant.developer.angler</description>
	<lastBuildDate>Wed, 07 Dec 2011 18:14:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PayPal Recurring Payments with ActiveMerchant</title>
		<link>http://www.wyliethomas.com/blog/2011/02/22/paypal-recurring-payments-with-activemerchant/</link>
		<comments>http://www.wyliethomas.com/blog/2011/02/22/paypal-recurring-payments-with-activemerchant/#comments</comments>
		<pubDate>Tue, 22 Feb 2011 08:38:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PayPal]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.wyliethomas.com/blog/?p=164</guid>
		<description><![CDATA[I found several pieces to the puzzle but it took me a while to put it all together. After I got it working I thought I should write it down in case I needed to remember what I did or maybe someone else would find it useful.
The first thing you should know is that ActiveMerchant [...]]]></description>
			<content:encoded><![CDATA[<p>I found several pieces to the puzzle but it took me a while to put it all together. After I got it working I thought I should write it down in case I needed to remember what I did or maybe someone else would find it useful.</p>
<p>The first thing you should know is that ActiveMerchant does not support recurring payments with PayPal. But Raymond Law generously made a fork that fixes this. I couldnt get the fix as a gem so I just installed it as a plug in. <a href="https://github.com/rayvinly/active_merchant/">https://github.com/rayvinly/active_merchant/</a></p>
<p>Then I went to the Railscasts on PayPal with ActiveMerchant. <a href="http://railscasts.com/episodes/146-paypal-express-checkout">http://railscasts.com/episodes/146-paypal-express-checkout</a></p>
<p>In my config/environments I made a slight change from the Railscasts example:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">config.<span class="me1">after_initialize</span> <span class="kw1">do</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re2">ActiveMerchant::Billing::Base</span>.<span class="me1">mode</span> = <span class="re3">:test</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; paypal_options = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re3">:login</span> =&gt; <span class="st0">&quot;mysandboxlogingoeshere&quot;</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="re3">:password</span> =&gt; <span class="st0">&quot;MYSANDBOXAPIPASSWORD&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re3">:signature</span> =&gt; <span class="st0">&quot;SANDBOXAPI&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; ::STANDARD_GATEWAY = <span class="re2">ActiveMerchant::Billing::PaypalGateway</span>.<span class="me1">new</span><span class="br0">&#40;</span>paypal_options<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; ::EXPRESS_GATEWAY = <span class="re2">ActiveMerchant::Billing::PaypalExpressGateway</span>.<span class="me1">new</span><span class="br0">&#40;</span>paypal_options<span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">::EXPRESS_RECURRING_GATEWAY = <span class="re2">ActiveMerchant::Billing::PaypalExpressRecurringGateway</span>.<span class="me1">new</span><span class="br0">&#40;</span>paypal_options<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">end</span></div>
</li>
</ol>
</div>
<p>I made a registration controller:<br />
rails g controller index new checkout complete</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">def</span> checkout</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;response = EXPRESS_RECURRING_GATEWAY.<span class="me1">setup_agreement</span><span class="br0">&#40;</span><span class="re3">:description</span> =&gt; description, return_url =&gt; registration_complete_url, <span class="re3">:cancel_return_url</span> =&gt; registration_new_url<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; redirect_to EXPRESS_RECURRING_GATEWAY.<span class="me1">redirect_url_for</span><span class="br0">&#40;</span>response.<span class="me1">token</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="kw1">end</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">def</span> complete</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;token = params<span class="br0">&#91;</span><span class="re3">:token</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;response = EXPRESS_RECURRING_GATEWAY.<span class="me1">create_profile</span><span class="br0">&#40;</span>token, <span class="re3">:description</span> =&gt; description, <span class="re3">:start_date</span> =&gt; start_date, <span class="re3">:frequency</span> =&gt; frequency_in_months, <span class="re3">:amount</span> =&gt; amount_in_dollars, <span class="re3">:auto_bill_outstanding</span> =&gt; <span class="kw2">true</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="kw1">if</span> response. <span class="me1">success</span>?</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">#handle success</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">#handle failure</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp;<span class="kw1">end</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">end</span></div>
</li>
</ol>
</div>
<p>You can figure out your own way to handle the values and details of the transaction. The Date format can be set with</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">start_date = <span class="kw4">Time</span>.<span class="me1">now</span></div>
</li>
</ol>
</div>
<p>The amount can be just a number. Dont put it in quotes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wyliethomas.com/blog/2011/02/22/paypal-recurring-payments-with-activemerchant/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PayPal API from GoDaddy</title>
		<link>http://www.wyliethomas.com/blog/2008/05/20/paypal-api-from-godaddy/</link>
		<comments>http://www.wyliethomas.com/blog/2008/05/20/paypal-api-from-godaddy/#comments</comments>
		<pubDate>Wed, 21 May 2008 06:31:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PayPal]]></category>

		<guid isPermaLink="false">http://www.wyliethomas.com/2008/05/20/paypal-api-from-godaddy/</guid>
		<description><![CDATA[The PHP SDK form PayPal worked great from my dev server but when I went to load it for the client it either completely stalled or timed out. I learned that GoDaddy has a special proxy server you need to use for the cURL option.

$URL="https://api-3t.sandbox.paypal.com/nvp";
if (isset($_GET["site"])) { $URL = $_GET["site"]; }
$ch = curl_init();
//echo "URL = [...]]]></description>
			<content:encoded><![CDATA[<p>The PHP SDK form PayPal worked great from my dev server but when I went to load it for the client it either completely stalled or timed out. I learned that GoDaddy has a special proxy server you need to use for the cURL option.</p>
<pre>
$URL="https://api-3t.sandbox.paypal.com/nvp";
if (isset($_GET["site"])) { $URL = $_GET["site"]; }
$ch = curl_init();
//echo "URL = $URL &lt;br&gt;n";
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($ch, CURLOPT_PROXY,"http://proxy.shr.secureserver.net:3128");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$nvpreq="METHOD=".urlencode('doDirectPayment')."&amp;VERSION=".urlencode('3.0')."&amp;PWD=".urlencode('yourpass')."&amp;USER=".urlencode('your username)."&amp;SIGNATURE=".urlencode('your signature').$nvpStr;

//setting the nvpreq as POST FIELD to curl
curl_setopt($ch,CURLOPT_POSTFIELDS,$nvpreq);

$response = curl_exec ($ch);</pre>
<p>This worked fine for me so i re-created the PayPal Class from their sample code and modified to work with this cURL setting.</p>
<p>Hope it saves you the time I lost.</p>
<p><a href="http://www.wyliethomas.com/lab/paypalgatewaygodaddy.php.zip">PayPal GoDaddy Class</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wyliethomas.com/blog/2008/05/20/paypal-api-from-godaddy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

