使用Omnipay Paypal for Laravel 5时缺少CreditCard类

时间:2015-12-02 21:39:55

标签: paypal laravel-5 omnipay

以下是我作曲家中的回购曲目:

omnipay& paypal

在我的config / laravel-omnipay.php中:

'gateways' => [
    'paypal' => [
        'driver'  => 'PayPal_Rest',
        'options' => [
            'solutionType'   => '',
            'landingPage'    => '',
            'headerImageUrl' => ''
        ]
    ]
]

这是我的控制器:

// omnipay start
        $gateway = Omnipay::create('PayPal_Rest');

        // Initialise the gateway
        $gateway->initialize(array(
            'clientId' => 'xxxxxx',
            'secret'   => 'xxxxxx',
           'testMode' => true, // Or false when you are ready for live transactions
        ));

        // Create a credit card object
        // DO NOT USE THESE CARD VALUES -- substitute your own
        $card = new CreditCard(array(
                   'firstName'              => $request->firstname,
                   'lastName'               => $request->lastname,
                   'number'                 => $request->cardnumber,
                   'expiryMonth'            => $month_year[0],
                   'expiryYear'             => $month_year[1],
                   'cvv'                    => $request->ccv,
                   'billingAddress1'        => $request->address
                   /*
                   'billingCountry'         => 'AU',
                   'billingCity'            => 'Scrubby Creek',
                   'billingPostcode'        => '4999',
                   'billingState'           => 'QLD',*/
        ));

        // Do an authorisation transaction on the gateway
        $transaction = $gateway->authorize(array(
           'amount'        => '100',
           'currency'      => 'USD',
           'description'   => $eventName->event_title,
           'card'          => $card,
        ));
        $response = $transaction->send();
        if ($response->isSuccessful()) {
           echo "Authorize transaction was successful!\n";
           // Find the authorization ID
           $auth_id = $response->getTransactionReference();
        }

我有这个错误:

Class 'App\Http\Controllers\CreditCard' not found

注意:如果我使用RestGateway替换PayPal_Rest,我会收到此错误:

Class '\Omnipay\RestGateway\Gateway' not found

长时间搜索答案,但找不到适合我的解决方案。所以,不完全确定如何继续。

2 个答案:

答案 0 :(得分:1)

您需要将此文件放在班级文件的顶部:

use Omnipay\Common\CreditCard;

答案 1 :(得分:0)

$creditCard = new \Omnipay\Common\CreditCard([...]);

反斜杠

进一步阅读:https://stackoverflow.com/questions/4790020/what-does-a-backslash-do-in-php-5-3#:~:text=%5C%20(backslash)%20is%20the%20namespace,name%20in%20the%20current%20namespace

问题是因为它将从全局名称空间(而不是当前名称空间)获取类。