Sha256: fbbb6b69b289a79c3382d8298d037ad0aa9295005be342360ae9ba0d41cb34ae
Contents?: true
Size: 1.34 KB
Versions: 27
Compression:
Stored size: 1.34 KB
Contents
// Create a Stripe client. var stripe = Stripe(window.stripe_publishable_key); // Create an instance of Elements. var elements = stripe.elements(); var card = elements.create('card'); card.mount('#card-element'); card.addEventListener('change', function(event) { var displayError = document.getElementById('card-errors'); if (event.error) { displayError.textContent = event.error.message; } else { displayError.textContent = ''; } }); var form = document.getElementById('stripe-form'); form.addEventListener('submit', function(event) { event.preventDefault(); stripe.createToken(card).then(function(result) { if (result.error) { // Inform the user if there was an error. var errorElement = document.getElementById('card-errors'); errorElement.textContent = result.error.message; } else { // Send the token to your server. stripeTokenHandler(result.token); } }); }) function stripeTokenHandler(token) { // Insert the token ID into the form so it gets submitted to the server var form = document.getElementById('stripe-form'); var hiddenInput = document.createElement('input'); hiddenInput.setAttribute('type', 'hidden'); hiddenInput.setAttribute('name', 'stripeToken'); hiddenInput.setAttribute('value', token.id); form.appendChild(hiddenInput); // Submit the form form.submit(); }
Version data entries
27 entries across 27 versions & 1 rubygems