I am trying to use the paypal developer SDK for PHP for the first time. I have followed a tutorial on youtube all going well until I tried to execute it and the response I recieved was malformed_request JSON request doesn not map to API request. How do I get the struscture and contents of the JSON object so I can investigate further? please see code below error happens on the try. I am developing in netbeans 7.4
<?PHP
//this is copied from this tutorial here on youtube https://www.youtube.com/watch?v=BD1dOWIABe0
use PayPal\Api\Payer;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Details;
use PayPal\Api\Amount;
use PayPal\Api\Transaction;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Payment;
require '/../app/start.php';
$pTotal = 20.00;
$shipping = 1.00;
$Total = $pTotal + $shipping ;
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item = new Item();
$item->setName("tieThisToSomething")
->setCurrency('GBP')
->setQuantity(1)
->setPrice($pTotal);
$itemList = new ItemList();
$itemList->setItems($item); //I have removed square brackets from here []
$details = new Details();
$details->setShipping($shipping)
->setSubtotal($pTotal);
$amount = new Amount();
$amount->setCurrency('GBP')
->setTotal($Total)
->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription('Pay for all your santa fun')
->setInvoiceNumber(uniqid());//perhaps tie this to order number?
$redirectUrls = new RedirectUrls();
$redirectUrls->setCancelUrl(SITE_URL . '/pay.php?success=false')
->setReturnUrl(SITE_URL . '/pay.php?success=true');
$payment = new Payment();
$payment->setPayer($payer)
->setTransactions($transaction)
->setIntent('sale')
->setRedirectUrls($redirectUrls) ; //should [] be needed here?
//try {
// $payment->create($paypal);
//} catch (Exception $e) {
// die($e);
//}
try {
$payment->create($paypal); //Error happens here!
} catch (PayPal\Exception\PayPalConnectionException $ex) {
echo $ex->getCode(); // Prints the Error Code
echo $ex->getData(); // Prints the detailed error message
die($ex);
} catch (Exception $ex) {
die($ex);
}
$approvalUrl = $payment->getApprovalLink();
header("Location: {$approvalUrl}");