Laravel 收银员 10 - 条纹支付元素为空
Laravel Cashier 10 - Stripe payment element empty
我正在尝试显示 Stripe 支付元素,但它没有显示。
使用 dd()
语句,我可以看出用户 PaymentMethods
为空(正如新用户所期望的那样)并且 Intent
不为空。
show()
PlanController.php中的方法:
public function show(Plan $plan, Request $request)
{
$user = $request->user();
$user->createOrGetStripeCustomer();
$paymentMethods = $user->paymentMethods();
$intent = $user->createSetupIntent();
return view('plans.show', compact('plan', 'intent'));
}
Javascript,被截断了,因为 SO 不会让我 post 这一切:
<script src="https://js.stripe.com/v3/"></script>
...
// Submit the form with the token ID.
function stripeTokenHandler(paymentMethod) {
// Insert the token ID into the form so it gets submitted to the server
var form = document.getElementById('payment-form');
var hiddenInput = document.createElement('input');
hiddenInput.setAttribute('type', 'hidden');
hiddenInput.setAttribute('name', 'paymentMethod');
hiddenInput.setAttribute('value', paymentMethod);
form.appendChild(hiddenInput);
// Submit the form
form.submit();
}
我的问题是 show.blade.php 中的 javascript 根本没有加载。修复了 Stripe 元素出现的问题。
我正在尝试显示 Stripe 支付元素,但它没有显示。
使用 dd()
语句,我可以看出用户 PaymentMethods
为空(正如新用户所期望的那样)并且 Intent
不为空。
show()
PlanController.php中的方法:
public function show(Plan $plan, Request $request)
{
$user = $request->user();
$user->createOrGetStripeCustomer();
$paymentMethods = $user->paymentMethods();
$intent = $user->createSetupIntent();
return view('plans.show', compact('plan', 'intent'));
}
Javascript,被截断了,因为 SO 不会让我 post 这一切:
<script src="https://js.stripe.com/v3/"></script>
...
// Submit the form with the token ID.
function stripeTokenHandler(paymentMethod) {
// Insert the token ID into the form so it gets submitted to the server
var form = document.getElementById('payment-form');
var hiddenInput = document.createElement('input');
hiddenInput.setAttribute('type', 'hidden');
hiddenInput.setAttribute('name', 'paymentMethod');
hiddenInput.setAttribute('value', paymentMethod);
form.appendChild(hiddenInput);
// Submit the form
form.submit();
}
我的问题是 show.blade.php 中的 javascript 根本没有加载。修复了 Stripe 元素出现的问题。