为了账号安全,请及时绑定邮箱和手机立即绑定

布伦特里与 laravel

布伦特里与 laravel

PHP
慕哥6287543 2022-11-12 13:50:02
我正在使用带有 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 中找不到
查看完整描述

3 回答

?
幕布斯6054654

TA贡献1876条经验 获得超7个赞

请参阅下面的示例以了解 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

    ]);

}


查看完整回答
反对 回复 2022-11-12
?
牛魔王的故事

TA贡献1830条经验 获得超3个赞

您使用 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


查看完整回答
反对 回复 2022-11-12
?
大话西游666

TA贡献1817条经验 获得超14个赞

您是否在 AppServiceProvider 中添加了 use 语句?

use App\Providers\Braintree_Configuration;


查看完整回答
反对 回复 2022-11-12
  • 3 回答
  • 0 关注
  • 130 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号