gpt4 book ai didi

php - Paypal sizeof() : Parameter must be an array or an object that implements Countable

转载 作者:太空宇宙 更新时间:2023-11-03 16:21:25 26 4
gpt4 key购买 nike

我正在尝试在我的本地主机上安装 PayPal,但是当我测试 payment.php 时,此文件中出现以下警告:

Warning: sizeof(): Parameter must be an array or an object that implements Countable in /Applications/MAMP/htdocs/functions/PayPal/vendor/paypal/ rest-api-sdk-php/lib/PayPal/Common/PayPalModel.php on line 176

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() 警告。

我该如何解决这个问题,有人可以帮助我吗?

最佳答案

我遇到过这个问题,我通过以下更改得到了我的解决方案。

文件: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) {

关于php - Paypal sizeof() : Parameter must be an array or an object that implements Countable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54087631/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com