PayPal NVP SOAP payment gateway integration php tutorial

Last updated on Aug 02, 2016

darshan

Php

0

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.

Requirements:

  1. PHP 5.2 onwards
  2. PayPal Developers Account
  3. 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.

Steps:

  1. PayPal developer account setup
    1. Test account for merchant
    2. Test account for buyer
  2. Creating project
  3. Real Stuff! PayPal NVP SOAP payment gateway integration php tutorial code
  4. Post payment processing
    1. Return URL
    2. Cancel URL
    3. Post processing with response
  5. 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:PayPal NVP SOAP payment gateway integration php tutorial - PayPal Developer Account Signup

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.

PayPal NVP SOAP payment gateway integration php tutorial - PayPal Test Merchant 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.

PayPal NVP SOAP payment gateway integration php tutorial - PayPal Test Buyer 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.

  1. Click File -> New Project -> PHP -> Project Name -> Apache htdocs locatlion -> Finish.PayPal NVP SOAP payment gateway integration php tutorial - Seting up netbeans project for PayPal
  2. 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.

Code explanation:

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:

  1. Configuration
  2. Items collection

Configuration:
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!

For web app development & payment gateway integration contact us.

Stay tuned we will be back soon with PayPal payment gateway integration guide for RESTAPI the newest offering from PayPal.

Post by Darshan Joshi

Darshan shares a great passion for helping and empowering businesses around the world. With web application, he is helping businesses get more out of their business resources and an improved workflow. And the clone scripts help startups launch quickly in the market!

Leave a Reply

Your email address will not be published. Required fields are marked *