如何解决需要设置Laravel Braintree \ Configuration :: merchantId或将accessToken传递给Braintree \ Gateway
请帮助我,在正确安装braintree版本“ 5.3”之后,我试图使laravel项目上的贝宝付款有效,但它不起作用
这让我犯了这个错误:需要设置Braintree \ Configuration :: merchantId(或将accessToken传递给Braintree \ Gateway)
这是我的:
checkout.blade.php
@extends('layouts.default')
@section('content')
//code
@endsection
@section('extra-js')
<script src="https://js.braintreegateway.com/web/dropin/1.13.0/js/dropin.min.js"></script>
<script>
(function(){
var form = document.querySelector('#paypal-payment-form');
var client_token = "{{ $paypalToken }}";
braintree.dropin.create({
authorization: client_token,selector: '#bt-dropin',paypal: {
flow: 'vault'
}
},function (createErr,instance) {
if (createErr) {
console.log('Create Error',createErr);
return;
}
// remove credit card option
var elem = document.querySelector('.braintree-option__card');
elem.parentNode.removeChild(elem);
form.addEventListener('submit',function (event) {
event.preventDefault();
instance.requestPaymentMethod(function (err,payload) {
if (err) {
console.log('Request Payment Method Error',err);
return;
}
// Add the nonce to the form and submit
document.querySelector('#nonce').value = payload.nonce;
form.submit();
});
});
});
})();
</script>
@endsection
这是我的 checkoutcontroller.php
public function index()
{
$gateway = new \Braintree\Gateway([
'environment' => config('services.braintree.environment'),'merchantId' => config('services.braintree.merchantId'),'publicKey' => config('services.braintree.publicKey'),'privateKey' => config('services.braintree.privateKey')
]);
$paypalToken = $gateway->ClientToken()->generate();
return view('checkout')->with([
'paypalToken' => $paypalToken,]);
}
当然,我将其添加到了我的配置services.php
'braintree' => [
'environment' => env('BT_ENVIRONMENT','sandbox'),'merchantId' => env('BT_MERCHANT_ID'),'publicKey' => env('BT_PUBLIC_KEY'),'privateKey' => env('BT_PRIVATE_KEY'),],
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。