Recently I got a need to implement Paypal integration with Salesforce for a basic payment for Merchant Type account, the payments would be from Customers using Credit Cards like Visa etc. I started looking into Paypal methods to find out which is best to implement using Apex, then i found one old blog post very helpful (Unfortunately that blog post is removed recently so not able to paste url here). The method which i preferred is DoDirectPayment. I did some modification in that code and provided in this blog.
The main problem i faced, was not the code, the testing. Like me, many new developers face this problem, thats why i came with this blog to describe step by step procedure to do a simple test with your paypal payment process using salesforce code. This might be useful for the developers who dealing with Paypal first time as well as want to integrate it with Salesforce.
1) Setup one sandbox account.
Go to http://developer.paypal.com and create one account there. After creating, login there only. In the left menu you will find “Test Accounts” link. Click on that.
From the right side screen, you can create multiple test accounts.
For testing purpose generally you need two type of accounts. One is “Seller” and one is “Buyer”. Its always better to create preconfigured accounts.
Click on “PreConfigured” link to create one ‘Buyer’ account, set some amount there.
Click on “PreConfigured” link to create one ‘Seller’ account, set some amount there.
Click on “PreConfigured” link to create one ‘Website Payments Pro’ account, used for Merchant (Seller), set some amount there. Dont choose seller account this time because we going to use “DoDirectPayment” API method which need this type of account.
We dont need “Seller” account but i found after some struggle that if you not create any Seller account first then if you create any ‘Website Payments Pro’, then it will always be “unverified”. I am not sure why it is like this. But this is “My Best Practice” that you should first create one Seller account, then create this ”Website Payments Pro’ account. And verify, that one is marked as “Verified” as shown in the below screenshot.
2) Test Merchant Account API Setup
Now, select your ‘website payments pro’ account using radio button there and click ‘Enter Sandbox Test Site’.
Login with your password.
Click on Profile link after you login. It will be on top right side.
Click on ‘Request API Credentials’ link in bottom left side.
Click on ‘Set up PayPal API credentials and permissions’ link.
Click on ‘View API Signature’ link and note down your API Username, API Password, API Signature
Click on ‘Grant API Access’ link on previous screen. Here give your API username and Check all checkboxes and Save
Now you ok with configuration.
2) Salesforce Code setup
Now copy paste following Apex Class code in your org.
Add “https://api-3t.sandbox.paypal.com/2.0/” url into “Remote Site Setting”.
In the below code change your API Username, API Password and Signature.
3) Run and Test
Now you can use below code to do a sample payment. Run this code either on your VF screen or from System Log screen.
You will see that you got one Transaction Id and ‘Success’ message. If you dont find success message, then print “err” property to check whats wrong.
Log into your test pro account and check your balance, it might be increased. If so, its all fine🙂