Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Paypal 500错误:javax.validation.ValidationException_Php_Paypal_Paypal Sandbox_Paypal Rest Sdk - Fatal编程技术网

Php Paypal 500错误:javax.validation.ValidationException

Php Paypal 500错误:javax.validation.ValidationException,php,paypal,paypal-sandbox,paypal-rest-sdk,Php,Paypal,Paypal Sandbox,Paypal Rest Sdk,在我第一次尝试使用PayPal的RESTAPI时,我遇到了500个错误。我在谷歌上搜索了一下,找不到关于PayPal 500错误的有用信息,我不知道是什么原因造成的。 错误如下 500 javax.validation.ValidationException: HV000028: Unexpected exception during isValid call.[java.lang.NullPointerException] exception 'PayPal\Exception\PayPalC

在我第一次尝试使用PayPal的RESTAPI时,我遇到了500个错误。我在谷歌上搜索了一下,找不到关于PayPal 500错误的有用信息,我不知道是什么原因造成的。 错误如下

500
javax.validation.ValidationException: HV000028: Unexpected exception during isValid call.[java.lang.NullPointerException]
exception 'PayPal\Exception\PayPalConnectionException' with message 'Got Http response code 500 when accessing https://api.sandbox.paypal.com/v1/payments/payment.' in /home/user/public_html/sandbox/vendor/paypal/rest-api-sdk-php/lib/PayPal/Core/PayPalHttpConnection.php:154
Stack trace: 
#0 /home/user/public_html/sandbox/vendor/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php(73): PayPal\Core\PayPalHttpConnection->execute('{"intent":"sale...') 
#1 /home/user/public_html/sandbox/vendor/paypal/rest-api-sdk-php/lib/PayPal/Common/PayPalResourceModel.php(102): PayPal\Transport\PayPalRestCall->execute(Array, '/v1/payments/pa...', 'POST', '{"intent":"sale...', NULL) 
#2 /home/user/public_html/sandbox/vendor/paypal/rest-api-sdk-php/lib/PayPal/Api/Payment.php(565): PayPal\Common\PayPalResourceModel::executeCall('/v1/payments/pa...', 'POST', '{"intent":"sale...', NULL, Object(PayPal\Rest\ApiContext), NULL) 
#3 /home/user/public_html/sandbox/checkout.php(41): PayPal\Api\Payment->create(Object(PayPal\Rest\ApiContext)) 
#4 {main}
我也无法找到一种方法来获取更详细的错误消息。 我的代码:

<?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;
//include 'app.php';

require __DIR__  . '/vendor/autoload.php';

$apiContext = new \PayPal\Rest\ApiContext(
    new \PayPal\Auth\OAuthTokenCredential(
        'AfynNvA-2KwijS3pZ56jFPZwMxvObkwav8Vk4HMLc2foLahtCTPqzd_wfgt_wBtOCqqhLyk95T8LFUe0',     // ClientID
        'REDACTED'      // ClientSecret
    )
);
$price = 12;
$product = "Test";
$shipping = 0;
$total = $price + $shipping;

$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item = new Item();
$item->setName($product)->setCurrency('USD')->setQuantity(1)->setPrice($price);

$itemList = new ItemList();
$itemList->setItems([$item]);

$details = new Details();
$details->setShipping($shipping)->setSubtotal($price);

$amount = new Amount();
$amount->setCurrency('USD')->setTotal($total)->setDetails($details);

$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription("Test Payment")->setInvoiceNumber(uniqid());

$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("REDACTED")->setCancelUrl("REDACTED");

$payment = new Payment();
$payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions([$transactions]);

try{
    $payment->create($apiContext);
} catch (PayPal\Exception\PayPalConnectionException $ex) {
    echo $ex->getCode(); // Prints the Error Code
     echo "<br>";
    echo $ex->getData(); // Prints the detailed error message 
    echo "<br>";
    die($ex);
} catch (Exception $ex) {
    die($ex);
}

echo ($payment->getApprovalLink());


?>

我很想为此责备PayPal,因为它是500,但这是我第一次使用RESTAPI,所以我认为我犯了一个愚蠢的错误。我还尝试将uniqid()更改为静态数字,但没有改变。我应该向PayPal提交联系请求吗?如果是,我如何获得必要的信息