Working with Paypal can be a bit difficult not because of the code required, but rather because their website can be a hassle to navigation. I already have ActiveMerchant integrated into my application. My problem was figuring out how to change it from Braintree to Paypal. Here are the quick steps for getting going.
- Sign up for an account here:
https://developer.paypal.com - Click on ‘Test Accounts’ then choose ‘Seller’ and create an account
- If you want you can also create a ‘Buyer’ account that you can use to test transactions.
- Select the ‘Seller’ account and then press ‘Enter Sandbox Test Site’. You will be asked to login as the ‘Buyer’ user. Login and then under ‘My Account’ which should be the first screen you see there will be 3 steps towards the bottom of the page. Click on the ‘Go’ button to accept the billing agreement and then you will be provided with API credentials. Note that it will tell you that you will be billed $30 a month. However since you are in the sandbox your test account is free so don’t fret. At least I hope they are free. Maybe I should watch my account :-).
- If you don’t copy the credentials provided no worries you can always get the API Credentials from inside your sandbox account by clicking on ‘View Details’ under the buy account. Copy the credentials they are the information you need to setup ActiveMerchant.
- You can now setup your application to talk to Paypal with something like this:
gateway = ActiveMerchant::Billing::PaypalGateway.new( :login => "seller_432342373_p.example.com", :password => "WUDJOWK4M92C6HBE", :signature => "28dusj#8skaTiKxtkm6L9DcSUCUgePAUDQ3L-9s83usj@$osja82haDYtSu" ) </pre>
- I won't go into all the details of how to build a payment system instead watch the Railscasts and buy the ActiveMerchant pdf </ol> Note: If you get this error during your work:
</li>You can then use that account to login just like a real business user with the exception that you will log in to the sandbox and no money will exchange hands.</li>
Error: There's an error with this transaction. Please enter a complete billing address. </pre>
It's because Paypal requires billing information even in test mode. You'll need to include something like this in the 'options' argument to the various method calls in ActiveMerchant::billing_address => { :name => "Test Guy", :address1 => "123 W 423 E", :city => "Somewhere", :state => "CA", :country => "US", :zip => "88888" } </pre>
If you get an error stating 'This transaction cannot be processed due to an invalid merchant configuration' then you need to sign into your 'Buyer' account and accept the API Railscasts are awesome. PayPal Basics, Active Merchant Basics, and Integrating Active Merchant for a complete walk through.