In this tutorial i will explain you to create a sample web service for application which require to save user credit card information on paypal. In my last tutorial i explain you that how we can create a web service if you don’t know or not yet read that post click here to read. Before we start creating this sample web service we need some paypal developer api key to make this service work. You need to create Paypal developer account to test this service .

Step to create Developer API Key in paypal

  1. Create a Paypal developer account at
  2. Verify your email and login.
  3. Click on Applications link and create new app.
  4. After creating app you get your REST API CREDENTIALS to test your service.

After getting your REST api credentials you need to download paypal rest api sdk from github and also composer to run sample of this application from this link Unzip {} file and place the unzip folder inside the sdk -> sample . Now open your localhost or website where you place this folder -> sample. Most of the things are already done by this sdk. Now you need to add your paypal api key in this sdk open sample folder->bootsrap and add your client and secret key:

Now open link: http://localhost/rest-api-sdk-php-master/sample/ and click  on execute in front of save credit card. By default there is sample information in backend which is send to paypal server and they return some Information like this:

Now our work start from here in above sample we get a card id eg.


Now with this id we can fetch user card information from paypal server and also delete user card information, so we need to save this information to our database and next time whenever user login to our website or purchase any thing then don’t need to add there card information again on any purchase.

Now we need a database where we can save this cardid.

You can download a sample code from here

Create database: paypal {you can name your database whatever you want.}

Create connection to Database:

Now i am using Advance REST Client to request to my web service and create form in REST client as shown in image below


After request to webservice, webservice process your request and send user card information to paypal and receive a unique card id and we save that card id to our database with userid. If user information is saved you can get success response message from webservice.

Now if we want to fetch user card information from Paypal server we need to send CARD ID to paypal server and get response as shown in image below


and you get this response note that i send userid to service and with this user id i will fetch card id from database and send to paypal

To learn more about web service on paypal stay tune i am continuously try to update this post thank you.

Hapy coading.

Posted in: php