未找到“PayPal \ Api \ Itemlist”类

问题描述 投票:0回答:1

我在生产站点上遇到此PHP错误,但不是localhost:

致命错误:未捕获错误:未找到类'PayPal \ Api \ Itemlist'...堆栈跟踪:...

以下是发生错误的函数:

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;
}

这是init函数(仅为了完整性):

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上。

有什么想法可以解决问题吗?我想自动加载器可能出于任何原因不包括这个类?

php paypal paypal-rest-sdk
1个回答
1
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.