我已经写了这个javascript来返回Stripe的错误消息,如果这是一张无效的卡片,拒绝了,等等。它没有返回任何内容。它只需要一次....然后在应该显示错误时重新启用按钮,但错误没有显示。
$('#subscription-form button').on('click', function () {
var form = $('#subscription-form');
var submit = form.find('button');
var submitInitialText = submit.text();
submit.attr('disabled', 'disabled').text('Just one moment....');
Stripe.card.createToken(form, function (status, response) {
var token;
if (response.error) {
form.find('.stripe-errors').text(response.error.message).show();
submit.removeAttr('disabled');
submit.text(submitInitialText);
} else {
token = response.id;
form.append($('<input type="hidden" name="token">').val(token));
form.submit();
}
});
});
这是我的看法。这是在Laravel完成的。错误应显示在该div
中<div class="stripe-errors panel hide"></div>
我的表格
<form action="{{ URL::action('subscription-join') }}" method="post" id="subscription-form">
<div class="row">
<div class="large-6 columns">
Choose Plan
<label>
Chosen Plan:
<select name="plan">
<option value="small">Small ($9.99/month)</option>
<option value="large">Large (14.99/month)</option>
</select>
</label>
</div>
<div class="large-6 columns">
@include('subscription.partials._card')
<button class="button">Make payment</button>
</div>
</div>
{{ Form::token() }}
</form>