PayPal NVP SOAP payment gateway integration php tutorial
PayPal offers plenty of integration methods. The most basic and oldest is NVP/SOAP a Classic API. We will be covering up PayPal NVP SOAP payment gateway integration php tutorial with PayPal sandbox accounts creation, project setup and coding overview.
If you are looking for basic integration and don’t want to process payment on your website using RESTapi the this may be your choice. In this method hitting the submit button our code bring user to PayPal’s payment page. Where user can either use existing PayPal account or pay directly via credit card without using/crating PayPal account.
The requirements are pretty basic so does your knowledge with PayPal apis. PayPal has widest variety of payment processing to offer. Complexity and learning curve increase as you start using advanced APIs. The good news is this solution does not require composer or any sdk to download. Some line of code is enough for the integration.
- 1 Requirements:
- 2 Steps:
- 3 Step 1: PayPal developer account setup
- 4 Step 1.1: Test account for merchant
- 5 Step 1.2: Test account for buyer
- 6 Step 2: Creating project
- 7 Step 3: PayPal NVP SOAP payment gateway integration php tutorial code
- 8 Post payment processing:
- PHP 5.2 onwards
- PayPal Developers Account
- Sandbox test business and individual accounts for testing
The PayPal NVP payment gateway integration tutorial divided into four main parts namely setting up accounts, creating project, integration code and post processing.
- PayPal developer account setup
- Test account for merchant
- Test account for buyer
- Creating project
- Real Stuff! PayPal NVP SOAP payment gateway integration php tutorial code
- Post payment processing
- Return URL
- Cancel URL
- Post processing with response
- Code Download
Step 1: PayPal developer account setup
Setting developer account is quite straight forward task. You can skip this part if you already have created the account. Click to sign-up for developer sandbox account. The signup page would look something like this:
Step 1.1: Test account for merchant
Create a Business account. Login to your developer account on PayPal. Then click on Dashboard, and click on Accounts tab from the left navigation bar. Don’t forget to select Business (Merchant) account while creating account.
Step 1.2: Test account for buyer
Create a Personal account. Go to Accounts tab from the left navigation bar. Don’t forget to select Personal (Buyer) account while creating account.
Step 2: Creating project
All the prerequisites are setup. Now is the time for setting up the project and putting some code on it. We are using Netbeans for php development. We would suggest you go with any IDE that provides GIT/SVN, Composer and Plugin support. As they might help you develop things faster.
- Click File -> New Project -> PHP -> Project Name -> Apache htdocs locatlion -> Finish.
- Add new Payment.php file to the project.
Step 3: PayPal NVP SOAP payment gateway integration php tutorial code
We will be using Classic APIs for PayPal NVP SOAP payment gateway integration php tutorial code. It basically requires shopping items data along with merchant identification return URL and cancel URL.
<form method="post" action="https://www.sandbox.paypal.com/cgi-bin/webscr"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <!-- Replace the email@example.com below with your merchant account you created early on --> <input type="hidden" name="business" value="firstname.lastname@example.org"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="item_name_1" value="Item One"> <input type="hidden" name="amount_1" value="150.00"> <input type="hidden" name="item_name_2" value="Item Two"> <input type="hidden" name="amount_2" value="4250.00"> <input type="image" src="http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit"> </form>
What this should ideally do is simple. It displays a page with Submit/Pay button. When user clicks on the button it brings user to PayPal payment page where he/she can pay via their PayPal account or credit card.
The PayPal payment gateway integration guide code coverage is divided into two main parts:
- Items collection
The configuration part contains the information that helps PayPal payment gateway to understand about merchant who will receive the money. Which currency should be used and are we using single item payment or multiple items payment.
Cmd is used to tell PayPal that the user has pressed was the buy now button or the cart purchase button.
cmd = _xclick for single item payment.
cmd = _cart for multiple items payment.
Business value show case the merchant information that PayPal will look for into its database while processing payment.
Business = Paypal account email.
Currency code is used to tell PayPal that the amount filled in the form are or which currency.
currency_code = USD/CAD/AUD…
Single item payment:
Item_name = “value???
Amount = “value???
would be enough.
Multiple items payment:
Item_name_1 = “value???
Quantity_1 = “value???
amount_1 = “value???
Item_name_2 = “value???
Quantity_2 = “value???
amount_2 = “value???
Post payment processing:
Step 4.1: Return URL
It is used to redirecting the user to your website. If not provided PayPal will redirect user to its account/home page.
Step 4.2: Cancel URL
It is used to redirect the user to cancel order/error page of your website when he hit the cancel button on PayPal payment page.
Step 4.3: Notify URL
PayPal provide a notification architecture where on successful/failure payment it send a collection of data including transaction id, success…
This is very helpful for order post process, you can make the database level changes for the order i.e place transaction id, payment status etc on your database for given order.
Download the source code make the suggested changes and run it on your development machine to see it in action!
[sociallocker]Download the source code of PayPal payment gateway integration in php[/sociallocker]
Stay tuned we will be back soon with PayPal payment gateway integration guide for RESTAPI the newest offering from PayPal.