kingpabel blog payapl integration php

Paypal Integration in PHP

Paypal is a very renounce and popular payment method.Most of the web application use paypal for their payment method.Here we know how to use paypal integration in your web project.There is two method to paypal integration.One is Use PayPal Using Form.Another is Paypal integration in php.If you want to use PayPal as a test account you need to create a paypal developer account.After create account and login you will found your developer account dashboard.There is three menu

  1. Documentation
  2. Dashboard
  3. Support

Then you need to create an app for your project to PayPal integration.To create app just click Dashboard menu.Then you found a button that is like Click here and put your information.After create app you will found ClientID and Secret Key.Collect this information,for further.

Then go on your project open your composer.json file.And add this in your composer require portion.

Paypal Integration in Composer Require

Here i gave you Github Url

See also Packagist

Here is the documentation that you know how to paypal integration with your php project.You can follow this.It’s very helpfull.

Then execute composer update in your terminal.

If you are not using composer.json file create a folder vendor in your projects directory and download this file and put it in vendor folder.

Make it sure that you have required bootstrap.php in your index.php file like that

Then execute composer dumpautoloader for autoload classmap.Or use composer install.

You can found this file in this directory

projectName/vendor/paypal

Now you have all the files of PayPal-PHP-SDK.

Connect with Paypal Using Credential

For paypal integration i created a class which name is Paypal.php and make some method and property and call paypal classes.Here i give an example how to use that.

In paypal class first i made a public property name $apiContext
Then make a construct method and initialize that property for use credential.Credential information are gave from paypal when create app done.

For paypal transaction it’s need only a card information.By using card information you can payment a amount with your others info.

Paypal Card ID

Let see how to make a card for customer.It’s very easy

Then call this Paypal class and make an object and run this method for create your Card like that

$payPal = new Paypal();
var_dump($payPal->createCreditCard());die();

For creating card i made a public method that is createCreditCard().Call paypal CreditCard class.And set information.That’s it.If you var_dump() the response you can find there’s have many information.From this you will store your needed information.Here i gave you a response example:

object(PayPal\Api\CreditCard)[140]
  private '_propMap' (PayPal\Common\PayPalModel) => 
    array (size=13)
      'type' => string 'visa' (length=4)
      'number' => string 'xxxxxxxxxxxx0331' (length=16)
      'expire_month' => string '11' (length=2)
      'expire_year' => string '2019' (length=4)
      'cvv2' => string '012' (length=3)
      'first_name' => string 'Imtiaz' (length=6)
      'last_name' => string 'Pabel' (length=5)
      'id' => string 'CARD-8KC75320MG899220EKTZQPBA' (length=29)
      'state' => string 'ok' (length=2)
      'valid_until' => string '2018-02-28T00:00:00Z' (length=20)
      'create_time' => string '2015-03-01T12:35:16Z' (length=20)
      'update_time' => string '2015-03-01T12:35:16Z' (length=20)
      'links' => 
        array (size=3)
          0 => 
            object(PayPal\Api\Links)[141]
              private '_propMap' (PayPal\Common\PayPalModel) => 
                array (size=3)
                  'href' => string 'https://api.sandbox.paypal.com/v1/vault/credit-cards/CARD-8KC75320MG899220EKTZQPBA' (length=82)
                  'rel' => string 'self' (length=4)
                  'method' => string 'GET' (length=3)
          1 => 
            object(PayPal\Api\Links)[162]
              private '_propMap' (PayPal\Common\PayPalModel) => 
                array (size=3)
                  'href' => string 'https://api.sandbox.paypal.com/v1/vault/credit-cards/CARD-8KC75320MG899220EKTZQPBA' (length=82)
                  'rel' => string 'delete' (length=6)
                  'method' => string 'DELETE' (length=6)
          2 => 
            object(PayPal\Api\Links)[163]
              private '_propMap' (PayPal\Common\PayPalModel) => 
                array (size=3)
                  'href' => string 'https://api.sandbox.paypal.com/v1/vault/credit-cards/CARD-8KC75320MG899220EKTZQPBA' (length=82)
                  'rel' => string 'patch' (length=5)
                  'method' => string 'PATCH' (length=5)

You can retrieve your cardId’s information by using this

public function getCardInfo($id)
    {
        return \PayPal\Api\CreditCard::get($id, $this->apiContext);
    }
Paypal Transaction

You can transaction amount by using your existing cardID
For transaction i made a method in my way,here this is:

Then made an object of Paypal Class and run this method.Like that

$payPal = new Paypal();
var_dump($payPal->transaction());die();

By using this public transaction() method You can transaction a amount with it’s item name,tax,total amount etc.After var_dump() it’s response you can find many information like as Unique Transaction ID,Invoice ID,Date,Time,Status etc.From that response you can store information what you needed.

Paypal Transaction With Random Card ID

There is another option it will create a single card for every single transaction.For this here is the coding technique:

By using this method there will be create a single card for every single payment.You can send also billing address.
You can also create billing plan,check billing plan,update billing plan,Card save update delete,create,send,update,delete Invoice and many others what you needed.
So this is the technique to paypal integration.For more any help just check this:
http://paypal.github.io/PayPal-PHP-SDK/sample/
Or comment me.
Enjoy with Paypal!!!!!!!