【问题标题】:Error with ApiContextfunctoin in netshel paypalnetshel paypal 中的 ApiContextfunctoin 错误
【发布时间】:2017-01-03 22:39:48
【问题描述】:

我该如何解决这个错误:

BadMethodCallException in Controller.php line 107: Method [ApiContext]
does not exist.

这是代码:

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;

class paypalel 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('paypalel@getDone'));
        $redirectUrls->setCancelUrl(action('paypalel@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 ); 
    } 
}

【问题讨论】:

    标签: php laravel paypal


    【解决方案1】:

    此行有拼写错误

     $this->_apiContext = Paypalel::ApiContext(
    

    我想应该是

    $this->_apiContext = PayPal::ApiContext(
    

    希望这能解决您的问题

    在你的类声明之前添加以下行

      use PayPal;
      use Redirect;
    

    【讨论】:

    • 请添加paypal库文档url或者paypal的git url
    • 使用贝宝;使用重定向;
    • 使用贝宝;使用重定向;你是认真的吗?
    • 是的,我希望您已根据您发送的链接在提供程序数组中的 config.php 中设置外观配置
    猜你喜欢
    • 2017-01-03
    • 2020-04-02
    • 2016-04-02
    • 2014-06-27
    • 2016-08-22
    • 1970-01-01
    • 2016-09-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多