i got a problem with the Paypal-PHP-SDK.
I have this code:
<?php
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;
// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader
// Used for composer based installation
require __DIR__ . '/app/first.php';
require __DIR__ . '/../ajaxscript.php';
// Use below for direct download installation
// require __DIR__ . '/PayPal-PHP-SDK/autoload.php';
$payer = new Payer();
$payer ->setPaymentMethod('paypal');
$Bestellungsanzahl = 1;
$product = "Mousepad";
$price = 20;
$total = $price;
$item = new Item();
$item ->setName($product)
->setCurrency('EUR')
->setQuantity("4")
->setPrice($price);
$itemList = new ItemList();
$itemList ->setItems([$item]);
$details = new Details();
$details->setSubtotal($total);
$amount = new Amount();
$amount->setCurrency('EUR')
->setTotal($total)
->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription('KSTM Mousepads')
->setInvoiceNumber(uniqid());
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl('http://localhost' . '/pay.php?success=true')
->setCancelUrl('http://localhost' . '/pay.php?success=false');
$payment = new Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions([$transaction]);
try {
$payment->create($paypal);
}
catch (Exception $e) {
die($e);
}
$approvalUrl = $payment->getApprovalLink();
header("Location: {$approvalUrl}");
The problem is if i set quantity on 1 it works. So if ->setQuantity(1) or ->setQuantity("1") it works.
But if the quantity is more than 1 (->setQuantity("4") or ->setQuantity(4)) this error appears :
exception 'PayPal\Exception\PayPalConnectionException' with message 'Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment.' in C:\xampp\htdocs\paypal\vendor\paypalest-api-sdk-php\lib\PayPal\Core\PayPalHttpConnection.php:183 Stack trace: #0 C:\xampp\htdocs\paypal\vendor\paypalest-api-sdk-php\lib\PayPal\Transport\PayPalRestCall.php(73): PayPal\Core\PayPalHttpConnection->execute('{"intent":"sale...') #1 C:\xampp\htdocs\paypal\vendor\paypalest-api-sdk-php\lib\PayPal\Common\PayPalResourceModel.php(102): PayPal\Transport\PayPalRestCall->execute(Array, '/v1/payments/pa...', 'POST', '{"intent":"sale...', NULL) #2 C:\xampp\htdocs\paypal\vendor\paypalest-api-sdk-php\lib\PayPal\Api\Payment.php(579): PayPal\Common\PayPalResourceModel::executeCall('/v1/payments/pa...', 'POST', '{"intent":"sale...', NULL, Object(PayPal\Rest\ApiContext), NULL) #3 C:\xampp\htdocs\paypal\checkout.php(61): PayPal\Api\Payment->create(Object(PayPal\Rest\ApiContext)) #4 {main}
Do anyone have an idea? Thanks