gpt4 book ai didi

php - 找不到类 'PayPal\Api\Itemlist'

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

我在生产站点上遇到了这个 PHP 错误,但在本地主机上却没有:

Fatal error: Uncaught Error: Class 'PayPal\Api\Itemlist' not found in … Stack trace: …

这是发生错误的函数:

function paypal_submit( $orderID, $cart ) {
// Get settings
global $settings;

// Init SDK
$paypal = paypal_init();

// Create payer
$payer = new \PayPal\Api\Payer();
$payer->setPaymentMethod('paypal');

// Iterate through items
$items = array();
$total = 0;

foreach( $cart as $imageID => $imagePrice ):

$total = $total + $imagePrice;

$item = new \PayPal\Api\Item();
$item->setName( 'Bild #' . $imageID )
->setCurrency( 'EUR' )
->setQuantity( 1 )
->setPrice( $imagePrice );

$items[] = $item;

endforeach;

$itemList = new \PayPal\Api\Itemlist();
$itemList->setItems( $items );

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

$transaction = new \PayPal\Api\Transaction();
$transaction->setAmount( $amount )
->setItemList( $itemList )
->setDescription( 'Bestellung #' . $orderID )
->setInvoiceNumber( 'RE' . $orderID )
->setCustom( $orderID );


$redirectURLs = new \PayPal\Api\RedirectUrls();
$redirectURLs->setReturnUrl( add_query_arg( 'success', 1, permalink( 'checkout-paypal' ) ) )
->setCancelUrl( add_query_arg( 'success', 0, permalink( 'checkout-paypal' ) ) );



$payment = new \PayPal\Api\Payment();
$payment->setIntent( 'sale' )
->setPayer( $payer )
->setRedirectUrls( $redirectURLs )
->setTransactions( [ $transaction ] );

try {

$payment->create( $paypal );

} catch( PayPal\Exception\PayPalConnectionException $ex ) {

echo $ex->getCode(); // Prints the Error Code
echo $ex->getData(); // Prints the detailed error message

die( $ex );

} catch( Exception $ex ) {
die( $ex );
}

$approvalUrl = $payment->getApprovalLink();
header( 'Location: ' . $approvalUrl ); exit;
}

这是初始化函数(只是为了完整起见):

function paypal_init() {
// Get settings
global $setting;

// Load PayPal SDK
require_once( ABSPATH . 'system/classes/paypal/autoload.php' );

// Register app
$paypal = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
$setting['paypal_clientid'],
$setting['paypal_clientsecret']
)
);

// Return app
return $paypal;
}

所有其他类都有效。

奇怪的是,完全相同的集成在 localhost 上运行正常,但在生产环境上却不行……PHP 版本是相同的。据我所知,唯一的区别是生产站点通过 https 运行。

任何想法可能是什么问题?我猜自动加载器可能出于某种原因不包含此类?

最佳答案

自动加载器查找以您正在使用的类名命名的文件。由于您正在使用 Itemlist,它会查找 Itemlist.php 文件。

将其更改为 \PayPal\Api\ItemList 将允许自动加载器找到正确的文件(在区分大小写的系统上)。因为SDK中的实际文件是ItemList.php

关于php - 找不到类 'PayPal\Api\Itemlist',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51043241/

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