Paypal-PHP-SDK有问题
我有这样的代码:
<?php
use PayPalApiPayer;
use PayPalApiItem;
use PayPalApiItemList;
use PayPalApiDetails;
use PayPalApiAmount;
use PayPalApiTransaction;
use PayPalApiRedirectUrls;
use PayPalApiPayment;
// 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}");
问题是,如果我设置数量为1,它的工作。因此,如果->setQuantity(1)或->setQuantity("1")有效。
但如果数量大于1 (->setQuantity("4")或->setQuantity(4)),则出现此错误:
exception 'PayPalExceptionPayPalConnectionException' with message 'Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment.' in C:xampphtdocspaypalvendorpaypalrest-api-sdk-phplibPayPalCorePayPalHttpConnection.php:183 Stack trace: #0 C:xampphtdocspaypalvendorpaypalrest-api-sdk-phplibPayPalTransportPayPalRestCall.php(73): PayPalCorePayPalHttpConnection->execute('{"intent":"sale...') #1 C:xampphtdocspaypalvendorpaypalrest-api-sdk-phplibPayPalCommonPayPalResourceModel.php(102): PayPalTransportPayPalRestCall->execute(Array, '/v1/payments/pa...', 'POST', '{"intent":"sale...', NULL) #2 C:xampphtdocspaypalvendorpaypalrest-api-sdk-phplibPayPalApiPayment.php(579): PayPalCommonPayPalResourceModel::executeCall('/v1/payments/pa...', 'POST', '{"intent":"sale...', NULL, Object(PayPalRestApiContext), NULL) #3 C:xampphtdocspaypalcheckout.php(61): PayPalApiPayment->create(Object(PayPalRestApiContext)) #4 {main}
有谁有主意吗?由于
2017 :c, total = quantity *price