<?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>Sentia &#124; Sydney IT Consultancy, Software Development, Ruby on Rails, Web Application Development, Rails Development, Test Driven Development, Microsoft.Net, Asp.Net , Agile, Continuous Integration Training, iPhone development &#187; Recurring Billing</title>
	<atom:link href="http://www.sentia.com.au/tag/recurring-billing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sentia.com.au</link>
	<description>Sentia company website and blog about all things development, Ruby on Rails, Microsoft .Net, ASP.Net, C#.Net, Agile web development, Test Driven Development</description>
	<lastBuildDate>Thu, 02 Feb 2012 07:16:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>PayFlow recurring billing with ActiveMerchant</title>
		<link>http://www.sentia.com.au/2009/10/payflow-recurring-billing-with-activemerchant/</link>
		<comments>http://www.sentia.com.au/2009/10/payflow-recurring-billing-with-activemerchant/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 04:47:47 +0000</pubDate>
		<dc:creator>James Kong</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[activemerchant]]></category>
		<category><![CDATA[Payflow]]></category>
		<category><![CDATA[Payment Gateway]]></category>
		<category><![CDATA[paypal]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Recurring Billing]]></category>

		<guid isPermaLink="false">http://sentia.com.au/?p=612</guid>
		<description><![CDATA[Today we are going to look at using ActiveMerchant to &#8230; <a href="http://www.sentia.com.au/2009/10/payflow-recurring-billing-with-activemerchant/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today we are going to look at using ActiveMerchant to set up a recurring billing subscription with PayFlow .</p>
<p>PayFlow is Paypal&#8217;s payment gateway and you need to setup a PayFlow account.<br />
<strong>IMPORTANT!</strong> This is separate from Paypal&#8217;s development sandbox. Follow these steps to setup a Payflow testing account</p>
<ol>
<li>Go to <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_payflow-get-started-outside">https://www.paypal.com/cgi-bin/webscr?cmd=_payflow-get-started-outside<br />
</a> and fill in the details for an account.</li>
<li>When you get to the page where you need to enter your payment information, hit Save and Exit. This will create a testing PayFlow account for you.</li>
<li>You will be sent an email with your partner ID and your vendor login. Take note of your partner ID as this will be important later.</li>
<li>You should now be able to login at <a href="https://manager.paypal.com/">https://manager.paypal.com/</a></li>
</ol>
<p>Now that you have a PayFlow account, you can use ActiveMerchant to setup payments. For now we will muck around in irb to test that methods out.</p>
<p>So lets open up irb and start by including the active merchant gem and setting ActiveMerchant to test mode</p>
<pre class="brush: ruby; title: ; notranslate">
kongy@Deadpool: $ irb
irb(main):001:0&gt; require 'rubygems'
irb(main):002:0&gt; require 'active_merchant'
irb(main):003:0&gt; ActiveMerchant::Billing::Base.mode = :test
</pre>
<p>Now lets setup the gateway.</p>
<pre class="brush: ruby; title: ; notranslate">
gateway = ActiveMerchant::Billing::PayflowGateway.new(:login =&gt; 'PAYFLOW_LOGIN', :password =&gt; 'PAYFLOW_PASSWORD', :partner =&gt; 'PARTNER_ID')
</pre>
<p>This creates the gateway that we will be using to request purchases. By default ActiveMerchant passes PAYPAL as the partner value if you leave it out. I believe that this is the default for US PayFlow account. For my Aussie one, I received a VSA partner_id. I would suggest putting it in there anyway.</p>
<p>PayFlow Testing only accepts testing credit cards numbers.Ã‚Â  You can grab them from the PayFlow recurring billing documentation found <a href="https://cms.paypal.com/cms_content/US/en_US/files/developer/PayflowPro_RecurringBilling_Guide.pdf">here</a>. Here is a quick list which I can&#8217;t guarantee will be up to date.</p>
<table border="0">
<tbody>
<tr>
<td>American Express</td>
<td>378282246310005</td>
</tr>
<tr>
<td>American Express</td>
<td>371449635398431</td>
</tr>
<tr>
<td>American Express Corporate</td>
<td>378734493671000</td>
</tr>
<tr>
<td>Diners Club</td>
<td>30569309025904</td>
</tr>
<tr>
<td>Diners Club</td>
<td>38520000023237</td>
</tr>
<tr>
<td>Discover</td>
<td>6011111111111117</td>
</tr>
<tr>
<td>Discover</td>
<td>6011000990139424</td>
</tr>
<tr>
<td>JCB</td>
<td>3530111333300000</td>
</tr>
<tr>
<td>JCB</td>
<td>3566002020360505</td>
</tr>
<tr>
<td>MasterCard</td>
<td>5555555555554444</td>
</tr>
<tr>
<td>MasterCard</td>
<td>5105105105105100</td>
</tr>
<tr>
<td>Visa</td>
<td>4111111111111111</td>
</tr>
<tr>
<td>Visa</td>
<td>4012888888881881</td>
</tr>
<tr>
<td>Visa</td>
<td>4222222222222</td>
</tr>
</tbody>
</table>
<p>So lets create a Mastercard credit card.</p>
<pre class="brush: ruby; title: ; notranslate">
irb(main):004:0&gt; credit_card = ActiveMerchant::Billing::CreditCard.new( :number =&gt; '5105105105105100', :month =&gt; '9', :year =&gt; '2007', :first_name =&gt; 'Mal', :last_name =&gt; 'Reynolds', :verification_value =&gt; '123', :type =&gt; 'master' )
</pre>
<p>Now we are ready to start billing. If you want to setup a one time payment it is quite easy.</p>
<pre class="brush: ruby; title: ; notranslate">
irb(main):007:0&gt; response = gateway.purchase(1000, credit_card)
irb(main):008:0&gt; response.success?
=&gt; true
</pre>
<p>If you go into your Paypal Manager and search for transactions you should see it appear.</p>
<p>To setup a recurring billing we need to use the <b>recurring</b> method of the gateway. The recurring method accepts the amount in cents, the credit card object and the time intervals to charge the card, at a minimum. There are other options available which you can find <a href="http://activemerchant.rubyforge.org/classes/ActiveMerchant/Billing/PayflowGateway.html">here</a>. Lets charge $10/month</p>
<pre class="brush: ruby; title: ; notranslate">
irb(main):009:0&gt; response = gateway.recurring(100, credit_card, :periodicity =&gt; :monthly)
irb(main):010:0&gt; response.success?
=&gt; true
irb(main):011:0&gt; response.profile_id
=&gt; &quot;RT0000000002&quot;
</pre>
<p>You can view the recurring billings in your Paypal Manager by clicking on Service Settings > Recurring Billings > Manage Profiles. You will probably want to store the profile_id in your database for when you need to edit details of the recurring billing. You can do it quite simply by calling the <b>recurring</b> method again. Let&#8217;s change the amount we want to bill to $20/week.</p>
<pre class="brush: ruby; title: ; notranslate">
irb(main):0012:0&gt; response = gateway.recurring(2000, nil, :profile_id =&gt; &quot;RT0000000001&quot;,  :periodicity =&gt; :weekly)
irb(main):013:0&gt; response.success?
=&gt; true
</pre>
<p>You can see here that we no longer need to pass in the credit card since we have the profile_id. We update the amount, and change the periodicity of the billing.</p>
<p>And that&#8217;s it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sentia.com.au/2009/10/payflow-recurring-billing-with-activemerchant/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

