Braintree\Configuration::merchantId需要设置(或者accessToken需要传递给Braintree\Gateway)

Braintree\Configuration::merchantId needs to be set (or accessToken needs to be passed to Braintree\Gateway)

现在我得到了错误

Uncaught exception 'Braintree\Exception\Configuration' with message 'Braintree\Configuration::merchantId needs to be set (or accessToken needs to be passed to Braintree\Gateway).

问题是,如果我的商户 ID 不是它创建子商户的方式,因为我可以在我的仪表板中看到子商户帐户,但我要打电话 这个方法:

$webhookNotification = Braintree\WebhookNotification::parse($sampleNotification['bt_signature'], $sampleNotification['bt_payload']);

它说

Uncaught exception 'Braintree\Exception\Configuration' with message 'Braintree\Configuration::merchantId needs to be set (or accessToken needs to be passed to Braintree\Gateway).

完全披露:我在 Braintree 工作。如果您有任何其他问题,请随时联系 [支持][支持]

merchant ID 是所有 Braintree API 调用所必需的 API 凭据,以及 public 和私钥。您可以在没有商户 ID 的情况下在仪表板中看到子商户,因为我们的系统将您登录仪表板识别为有效身份验证,而不是依赖于 API 凭据。

使用我们的 SDK 时,您需要 set up your API Credentials appropriately. You can find the API Credentials for your account by following the instructions in our documentation. We now support both class level and instance methods

Class 级别示例

Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('use_your_merchant_id');
Braintree_Configuration::publicKey('use_your_public_key');
Braintree_Configuration::privateKey('use_your_private_key');

实例方法示例

$gateway = new Braintree_Gateway([
    'environment' => 'sandbox',
    'merchantId' => 'use_your_merchant_id',
    'publicKey' => 'use_your_public_key',
    'privateKey' => 'use_your_private_key'
]);

我用Laravel。就我而言,问题出在配置文件缓存中。由于某些原因 Laravel 没有从命令生成配置缓存: php artisan config:cache.

我解决了删除配置缓存的问题:

php artisan config:clear

但我的实际问题是 Laravel 配置缓存生成。

希望有用。

更新

我的配置缓存不起作用,因为我没有将 env() 帮助程序放在配置文件中,而是放在其他文件中(在我的例子中:AppServiceProvider)。 在生产模式下,.env 参数只能从配置文件中调用..

If you are using the config:cache command during deployment, you must make sure that you are only calling the env function from within your configuration files, and not from anywhere else in your application.