Skip to content

Commit

Permalink
25-stripe-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Sevilleja committed Aug 10, 2016
1 parent 92ead5c commit eb812eb
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
26 changes: 26 additions & 0 deletions public/js/all.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/js/all.js.map

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions resources/assets/js/subscribe.js
@@ -1,3 +1,29 @@
$(document).ready(function() {

// target the form
// on form submission, create a token
$('#subscribe-form').submit(function(e) {
var form = $(this);

// disable the form button
form.find('button').prop('disabled', true);

Stripe.card.createToken(form, function(status, response) {
if (response.error) {
form.find('.stripe-errors').text(response.error.message).addClass('alert alert-danger');
form.find('button').prop('disabled', false);
} else {
console.log(response);

// append the token to the form
form.append($('<input type="hidden" name="cc_token">').val(response.id));

// submit the form
form.get(0).submit();
}
});

e.preventDefault();
});

});
2 changes: 1 addition & 1 deletion resources/views/layouts/app.blade.php
Expand Up @@ -28,7 +28,7 @@
{{-- JS --}}
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script>
Stripe.setPublishableKey({{ env('STRIPE_KEY') }});
Stripe.setPublishableKey("{{ env('STRIPE_KEY') }}");
</script>
<script src="js/all.js"></script>
</body>
Expand Down
2 changes: 2 additions & 0 deletions resources/views/pages/subscribe.blade.php
Expand Up @@ -114,6 +114,8 @@
</div>
</div>

<div class="stripe-errors"></div>

<div class="form-group text-center">
<button type="submit" class="btn btn-lg btn-success btn-block">Join</button>
</div>
Expand Down

0 comments on commit eb812eb

Please sign in to comment.