So I'm playing around with the Paypal Sandbox and I just implemented Credit card transactions. I followed the Paypal Dev example closely but it seems to continuously return an error. I have tried multiple credit cards. Everything was working correctly before I addec direct credit card transactions.
<?php
use PayPal\Api\Payer;
use PayPal\Api\Details;
use PayPal\Api\Amount;
use PayPal\Api\Transaction;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\CreditCard;
use PayPal\Api\FundingInstrument;
use PayPal\Exception\PayPalConnectionException;
require 'protected/extensions/paypal/src/start.php';
$payer = new Payer();
$details = new Details();
$amount = new Amount();
$transaction = new Transaction();
$payment = new Payment();
$redirectUrls = new RedirectUrls();
$card = new CreditCard();
$card->setType("visa")
->setNumber("4214024046137679")
->setExpireMonth("03")
->setExpireYear("2020")
// ->setCvv2("012")
->setFirstName("asdf")
->setLastName("asdf");
$fi = new FundingInstrument();
$fi->setCreditCard($card);
//PAYER
$payer->setPaymentMethod("credit_card")
->setFundingInstruments(array($fi));
//Details
//acutal prices(20 dollars is a test)
//Amount
$details->setShipping(0.0)
->setSubtotal(20.00);
$amount->setCurrency("CAD")
->setTotal(20.00)
->setDetails($details);
//Transaction
$transaction->setAmount($amount)
->setDescription('Membership');
//Payment
$payment->setIntent("sale")
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction));
$payment->setRedirectUrls($redirectUrls);
try{
$payment->create($api);
$currentId = Yii::app()->user->getId();
$transactionHash = $payment->getId();
// $_SESSION['transactionId'] = $transactionHash;
$update = Yii::app()->db->createCommand()
->update('member', array(
'transactionId'=> $transactionHash,
), 'id=:id', array(':id'=> $currentId));
var_dump($payment->create($api));
} catch(PayPal\Exception\PayPalConnectionException $ex){
echo $ex->getData();
}
// $approvalUrl = $payment->getApprovalLink();
// $redirectUrl = $payment->getHref();
// header('Location: ' . $approvalUrl);
?>
This is the error it is returning:
{"name":"VALIDATION_ERROR","details":[{"field":"payer.funding_instruments[0].credit_card.number","issue":"Value is invalid"},{"field":"payer.funding_instruments[0].credit_card.number","issue":"Must be numeric"}],"message":"Invalid request - see details","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#VALIDATION_ERROR","debug_id":"d25b7c74793c9"}