Paypal credit card vault to store credit card details on paypal side.

@mit $ingh. January 03, 2015 Comments

Store the credit card details by using the PayPal api SDK

Click on below link to download the paypal SDK

Download PayPal PHP SDK

Process of using the paypal api

Include the autoload file to load the required class files.


use PayPal\Auth\OAuthTokenCredential;
use PayPal\Rest\ApiContext;
use PayPal\Api\CreditCard;
use PayPal\Api\CreditCardToken;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Payer;
use PayPal\Api\Amount;
use PayPal\Api\Transaction;
use PayPal\Api\Payment;	
use PayPal\Api\ItemList;
use PayPal\Api\Item;

Now get PayPal App clientid and secredid from PayPal App

$clientId = 'AQkquBDf1zctJOWGKWUEtKXm6qVhueUEMvXO_-MCI4DQQ4-LWvkDLIN2fGsd';
$secredId = 'EL1tVxAjhT7cJimnz5-Nsx9k2reTKSVfErNQF-CmrwJgxRtylkGTKlU4RvrX';
$sdkConfig = array( "mode" => "sandbox" );

$cred = new OAuthTokenCredential($clientId, $secredId, $sdkConfig);

$apiContext = new ApiContext($cred, 'Request' . time());


$card = new CreditCard();

$response = $card->create($apiContext);

In the response you will get the credit card id by which you can do the paypment.



Now you can make the payment by using credit card id given by the PayPal.

$cred = new OAuthTokenCredential($clientId, $secredId, $sdkConfig);
$apiContext = new ApiContext($cred, 'Request' . time());


$creditCardToken = new CreditCardToken();

$fundingInstrument = new FundingInstrument();

$payer = new Payer();

$amount = new Amount();

$transaction = new Transaction();
$transaction->setDescription("creating a payment with saved credit card");

You can set item details by the below example.

$item1 = new Item();
	  ->setName('Product 1')

$item2 = new Item();
	  ->setName('Product 2')

In the SDK there in no any methods available to send the discount price. For sending discount price you need to set the price in negative as you can see the below example.

$item3 = new Item();
	  ->setName('Coupon Discount')

Now you have to pass the Items object in an array in argument of setItems method of the ItemList class.

$itemList = new ItemList();
$itemList->setItems(array($item1, $item2, $item3)); 

In the setIntent method you pass "sale" for final payment and "authorize" for aurthorizing.

$payment = new Payment();

Now you will get the payment response by calling the create method of Payment class.

$finalPayment = $payment->create($apiContext);



The above code is enough for storing the credit card details and make payment by using the credit card id.

  • paypal-vault
  • creditcard