布伦特里与 laravel

我正在使用带有 Laravel 框架的 Braintree PHP SDK。

我通过作曲家安装了 Braintree。

然后,在AppServiceProvider.php中,我在boot()中添加了以下代码:


Braintree_Configuration::environment('sandbox');

Braintree_Configuration::merchantId('merchand_id');

Braintree_Configuration::publicKey('public_key');

Braintree_Configuration::privateKey('private_key');

尝试生成client_token时,出现以下错误:


Symfony\Component\Debug\Exception\FatalThrowableError: Class 'App\Providers\Braintree_Configuration' 在第 34 行的 AppServiceProvider.php 中找不到


慕哥6287543
浏览 131回答 3
3回答

幕布斯6054654

请参阅下面的示例以了解 braintree/paypal 的具体示例。这是对我有用的最优雅的解决方案:app\Providers\AppServiceProvider.php:/** * Bootstrap any application services. * * @return void */public function boot(){    // braintree setup    $environment = env('BRAINTREE_ENV');    $braintree = new \Braintree\Gateway([        'environment' => $environment,        'merchantId' => 'merchant_id_example',        'publicKey' => 'public_key_example',        'privateKey' => 'private_key_example'    ]);    config(['braintree' => $braintree]);     // braintree setup for specifically for paypal direct integration for those who need it    /*$accessToken = env('PAYPAL_ACCESS_TOKEN');    $braintree = new \Braintree\Gateway([        'accessToken' => $accessToken    ]);    config(['braintree' => $braintree]);*/ }// 示例文件.php:public function token(){    $braintree = config('braintree');    $clienttoken = $braintree->clientToken()->generate();}public function sale(){    $braintree = config('braintree');    $result = $braintree->transaction()->sale([        'amount' => $amount,        'paymentMethodNonce' => $nonce    ]);}

牛魔王的故事

您使用 braintree 的方式似乎遵循一个已弃用的示例(我猜是 Braintre_php 的先前版本),因为当前包中不存在 Braintree_Configuration 类。在调用自动加载的类之前,您还需要使用“\”,例如:\Braintree。这应该在你的 app/Providers/AppServiceProvider.php 文件中使用 Braintree 5.x :/** * Bootstrap any application services. * * @return void */public function boot(){    //    $gateway = new \Braintree\Gateway([        'environment' => 'sandbox',        'merchantId' => 'use_your_merchant_id',        'publicKey' => 'use_your_public_key',        'privateKey' => 'use_your_private_key'    ]);}你可以在这里有一个最新的例子来查看一些基本的 sdk 函数来开始: https ://developers.braintreepayments.com/start/hello-server/php

大话西游666

您是否在 AppServiceProvider 中添加了 use 语句?use App\Providers\Braintree_Configuration;
打开App,查看更多内容
随时随地看视频慕课网APP