我正在尝试在我的本地主机上安装PayPal,但是当我测试Payment.php时,在此文件中得到以下警告:
警告:sizeof():参数必须是一个数组或一个对象 实现Countable in / Applications / MAMP / htdocs / functions / PayPal / vendor / paypal / 第176行的rest-api-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()警告。
任何人都可以帮助我如何解决这个问题?
答案 0 :(得分:1)
我遇到了这个问题,并且通过以下更改得到了解决方案。
文件:vendor \ paypal \ rest-api-sdk-php \ lib \ PayPal \ Common \ PayPalModel.php
更改
} else if (sizeof($v) <= 0 && is_array($v) ) {
到
} else if (is_array($v) && sizeof($v) <= 0) {