I'm using the paypal REST SDK for PHP, using the laravel wrapper which gives me a 400 error (bad input from what I understand) I mostly copied from the example found at: enter link description here Yet I'm getting a 400 error sent back. I can't figure out what I'm doing wrong: here's the code.
$payer = Paypalpayment::Payer();
$payer->setPayment_method("paypal");
$item1 = Paypalpayment::Item();
$item1->setName('Lavender 6 oz')
->setCurrency('USD')
->setQuantity(1)
->setPrice('7.50');
$itemList = Paypalpayment::ItemLIst();
$itemList->setItems(array($item1));
$amount = Paypalpayment::Amount();
$amount->setCurrency("USD")
->setTotal("20.00");
$transaction = Paypalpayment::Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription("Buying from ButterflyOils.com");
$redirectUrls = Paypalpayment::RedirectUrls();
$baseUrl = Paypalpayment::getBaseUrl();
$redirectUrls->setReturnUrl($baseUrl + "/ExecutePayment.php?success=true&message='PayPal+Worked!'")
->setCancelUrl($baseUrl + "/ExecutePayment.php?success=false&message='PayPal+Cancel'");
$payment = Paypalpayment:: Payment();
$payment->setIntent("sale");
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
$payment->setTransactions(array($transaction));
try {
$payment->create($this->_apiContext);
} catch (\PPConnectionException $ex) {
return "Exception: " . $ex->getMessage() . PHP_EOL;
var_dump($ex->getData());
exit(1);
}
foreach($payment->getLinks() as $link) {
if($link->getRel() == 'approval_url') {
$redirectUrl = $link->getHref();
break;
}
}
// yeah I know this is a bad idea
$_SESSION['paymentId'] = $payment->getId();
if(isset($redirectUrl)) {
header("Location: $redirectUrl");
exit;
}