我使用条纹但是为用户提供自定义表单字段会引入信用卡号,卡日期来为卡充值。
但是当"确认"单击按钮会出现错误:
Must provide source or customer.
可能会出现此错误,因为在控制台上显示:
"Uncaught ReferenceError: StripeCheckout is not defined"
用" Stripe.setPublishableKey({{config('services.stripe.key')}});
"在它出现的JavaScript代码之前:
jquery.min.js:2 Uncaught ReferenceError: pk_test_.... is not defined
at HTMLDocument.<anonymous>
你知道如何纠正这个问题吗?
RegistrationController charge():
public function charge(Request $request)
{
Stripe::setApiKey(config('services.stripe.secret'));
$source = $request->stripeToken;
dd($source); //shows null
Charge::create([
'currency' => 'eur',
'amount' => 1000,
'source' => $source,
]);
}
路线:
Route::post('/charge', [
'uses' => 'RegistrationController@charge',
'as' => 'registration.charge'
]);
形式:
<form action="{{ route('registration.charge') }}" method="post" id="paymentForm">
{{csrf_field()}}
<input type="hidden" name="stripeToken" id="stripeToken"/>
<div class="form-group font-size-sm">
<label class="text-gray">Card Number</label>
<input type="text" required class="form-control">
</div>
<div class="form-row">
<div class="form-group col-lg-6 font-size-sm">
<label class="text-gray">Date</label>
<input type="text" required class="form-control"/>
</div>
<div class="form-group font-size-sm col-lg-6">
<label class="text-gray">CVC</label>
<input type="text" required class="form-control">
</div>
</div>
<input type="submit" href="" id="confirmPayment"
class="btn btn-primary" value="Confirm"/>
</form>
然后我有javascript来整合条带:
<script src="https://js.stripe.com/v3/"></script>
<script>
let stripe = StripeCheckout.configure({
key: "{{config('services.stripe.key')}}",
image: "/square-image.png",
locale: "auto",
token: function(token){
document.querySelector('#stripeToken').value = token.id;
document.querySelector('#paymentForm').submit();
}
});
document.getElementById('#confirmPayment').addEventListener('click', function(e){
stripe.open({
amount: 1000
});
e.preventDefault();
});
</script>
如果我直接传递密钥:
var stripe = Stripe({{config(&#39; pk _....&#39;)}});
它显示:
jquery.min.js:2 Uncaught Error: Invalid value for Stripe(): apiKey should be a string. You specified: undefined.