【问题标题】:netshel paypal configration errornetshell 贝宝配置错误
【发布时间】:2017-01-04 00:25:43
【问题描述】:

我在https://packagist.org/packages/netshell/paypal 中进行了所有配置 用贝宝付款 但我有这个错误

paywithpaypal.php 第 15 行中的 FatalErrorException:类 'App\Http\Controllers\PayPal' 未找到

这是代码

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use PayPal;
use Redirect;
use App\Http\Requests;


class paywithpaypal extends Controller {
    private $_apiContext;

    public function __construct()
    {
        $this->_apiContext = PayPal::ApiContext(
            config('services.paypal.client_id'),
            config('services.paypal.secret'));

        $this->_apiContext->setConfig(array(
            'mode' => 'sandbox',
            'service.EndPoint' => 'https://api.sandbox.paypal.com',
            'http.ConnectionTimeOut' => 30,
            'log.LogEnabled' => true,
            'log.FileName' => storage_path('logs/paypal.log'),
            'log.LogLevel' => 'FINE'
        ));

    }

    public function getCheckout() {
    $payer = PayPal::Payer();
    $payer->setPaymentMethod('paypal');

    $amount = PayPal:: Amount();
    $amount->setCurrency('EUR');
    $amount->setTotal(42); // This is the simple way,
    // you can alternatively describe everything in the order separately;
    // Reference the PayPal PHP REST SDK for details.

    $transaction = PayPal::Transaction();
    $transaction->setAmount($amount);
    $transaction->setDescription('What are you selling?');

    $redirectUrls = PayPal:: RedirectUrls();
    $redirectUrls->setReturnUrl(action('paywithpaypal@getDone'));
    $redirectUrls->setCancelUrl(action('paywithpaypal@getCancel'));

    $payment = PayPal::Payment();
    $payment->setIntent('sale');
    $payment->setPayer($payer);
    $payment->setRedirectUrls($redirectUrls);
    $payment->setTransactions(array($transaction));

    $response = $payment->create($this->_apiContext);
    $redirectUrl = $response->links[1]->href;

    return Redirect::to( $redirectUrl ); }

public function getDone(Request $request) {
    $id = $request->get('paymentId');
    $token = $request->get('token');
    $payer_id = $request->get('PayerID');

    $payment = PayPal::getById($id, $this->_apiContext);

    $paymentExecution = PayPal::PaymentExecution();

    $paymentExecution->setPayerId($payer_id);
    $executePayment = $payment->execute($paymentExecution, $this->_apiContext);

    // Clear the shopping cart, write to database, send notifications, etc.

    // Thank the user for the purchase
    return view('checkout.done'); }

public function getCancel() {
    // Curse and humiliate the user for cancelling this most sacred payment (yours)
    return view('checkout.cancel'); } }

【问题讨论】:

    标签: php laravel paypal


    【解决方案1】:

    你一定没有添加

    'aliases' => array(
        // ...
        'Paypal' => 'Netshell\Paypal\Facades\Paypal',
    )
    

    aliases 数组中的app/config/app.php,如docs 中所述。

    另外,你可以试试换行

    use PayPal;
    

    use Netshell\Paypal\Facades\Paypal;
    

    在您的 paywithpaypal 控制器中。

    【讨论】:

      猜你喜欢
      • 2014-08-25
      • 2015-09-14
      • 2018-08-11
      • 2016-05-04
      • 2015-12-26
      • 2017-01-10
      • 2017-08-13
      • 1970-01-01
      • 2015-12-08
      相关资源
      最近更新 更多