Reputation: 5122
I am trying to integrate Paypal to my website but its been a lot of chaos.
The documentation doesn't seem to match with the PHP SDK
of theirs and hence its been a trouble please suggest appropriate integration method.
The code I have tried out is as follows :
<?php
ini_set('max_execution_time', 300);
require __DIR__ . '/bootstrap.php';
// 3. Lets try to save a credit card to Vault using Vault API mentioned here
// https://developer.paypal.com/webapps/developer/docs/api/#store-a-credit-card
$apiContext->setConfig(
array(
'log.LogEnabled' => true,
'log.FileName' => 'PayPal.log',
'log.LogLevel' => 'DEBUG'
)
);
$creditCard = new \PayPal\Api\CreditCard();
$creditCard->setType("visa")
->setNumber("403*************")
->setExpireMonth("09")
->setExpireYear("2020")
->setCvv2("123")
->setFirstName("J***")
->setLastName("M*****");
$fi = new \PayPal\Api\FundingInstrument();
$fi->setCreditcard($creditCard);
$payer = new \PayPal\Api\Payer();
$payer->setPaymentmethod('credit_card');
$payer->setFundinginstruments(array($fi));
$amount = new \PayPal\Api\Amount();
$amount->setCurrency('USD');
$amount->setTotal('7.47');
$transaction = new \PayPal\Api\Transaction();
$transaction->setAmount($amount);
$transaction->setDescription('This is the payment transaction description.');
$payment = new \PayPal\Api\Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
// 4. Make a Create Call and Print the Card
try {
//$creditCard->create($apiContext);
//$creditCard->create($apiContext);
$payment->create($apiContext);
echo $payment;
}catch (\PayPal\Exception\PayPalConnectionException $ex) {
// This will print the detailed information on the exception.
//REALLY HELPFUL FOR DEBUGGING
echo $ex->getData();
}
?>
Upvotes: 1
Views: 802
Reputation: 1599
If you are using Vault you need to have been approved to accept direct credit cards. You will need to make certain that the application that you have submitted for Rest API and Vault has been fully approved for direct credit cards.
From the PayPal Developer Site:
Store and use a customer credit card
Direct credit card payment and related features are restricted in some countries.
Here is additional information on Going Live with your Application:
Apps 101
Here are the instructions:
Upvotes: 1