当前位置: 首页 > 知识库问答 >
问题:

PayPalsizeof():参数必须是数组或实现可数的对象

黎奇略
2023-03-14

我试图安装PayPal我的localhost,但当我测试payment.php得到以下警告在这个文件:

警告:sizeof():参数必须是在第176行的/Applications/MAMP/htdocs/functions/PayPal/vendor/PayPal/restapi sdk php/lib/PayPal/Common/PayPalModel.php中实现可数的数组或对象

payment.php代码如下:

<?php   
$client_ID =  '********';
$client_Secret = '********';
require __DIR__ . '/PayPal/vendor/autoload.php'; 

$apiContext = new \PayPal\Rest\ApiContext(
        new \PayPal\Auth\OAuthTokenCredential(
            $client_ID,     // ClientID
            $client_Secret      // ClientSecret
        )
);

$apiContext->setConfig([
 'mode'=>'sandbox',
 'http.ConnectionTimeOut'=>30,
 'log.LogEnabled'=>false,
 'log.FileName'=>'',
 'log.LogLevel'=>'FINE',
 'validation.level'=>'log'
]);
//$total = $amount;
// After Step 2
$payer = new \PayPal\Api\Payer();
$payer->setPaymentMethod('paypal');

$amount = new \PayPal\Api\Amount();
$amount->setTotal('1.00');
$amount->setCurrency('USD');

$transaction = new \PayPal\Api\Transaction();
$transaction->setAmount($amount);

$redirectUrls = new \PayPal\Api\RedirectUrls();
$redirectUrls->setReturnUrl("https://example.com/your_redirect_url.html")
    ->setCancelUrl("https://example.com/your_cancel_url.html");

$payment = new \PayPal\Api\Payment();
$payment->setIntent('sale')
    ->setPayer($payer)
    ->setTransactions(array($transaction))
    ->setRedirectUrls($redirectUrls);
try {
           $payment->create($apiContext);
           echo $payment;

           echo "\n\nRedirect user to approval_url: " . $payment->getApprovalLink() . "\n";


} catch (\PayPal\Exception\PayPalConnectionException $ex) {
    // This will print the detailed information on the exception.
    //REALLY HELPFUL FOR DEBUGGING
    echo $ex->getData();
}

?>

我必须试着用这个页面https://github.com/paypal/PayPal-PHP-SDK/wiki/Making-First-Call

但我得到了sizeof()警告。

我怎样才能解决这个问题?有人能帮我吗?

共有1个答案

申宜
2023-03-14

我已经面对了这个问题,我通过以下改变得到了我的解决方案。

文件:vendor\paypal\restapisdkphp\lib\paypal\Common\PayPalModel.php

改变

} else if (sizeof($v) <= 0 && is_array($v) ) {

} else if (is_array($v) && sizeof($v) <= 0) {
 类似资料: