SHARE
TWEET

stripe setup intent js

a guest Aug 16th, 2019 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    
  2.  
  3.     var stripe = Stripe('<%= Rails.configuration.stripe[:publishable_key] %>');
  4.     var elements = stripe.elements();
  5.     var cardElement = elements.create('card', {
  6.       hidePostalCode: true,
  7.       style: {
  8.         base: {
  9.           iconColor: '#F99A52',
  10.           color: '#32315E',
  11.           lineHeight: '48px',
  12.           fontWeight: 400,
  13.           fontFamily: '"Helvetica Neue", "Helvetica", sans-serif',
  14.           fontSize: '15px',
  15.  
  16.           '::placeholder': {
  17.             color: '#CFD7DF',
  18.           }
  19.         },
  20.       }
  21.     });
  22.     cardElement.mount('#card-element');
  23.  
  24.  
  25.     var cardholderName = document.getElementById('cardholder-name');
  26.     var cardButton = document.getElementById('card-button');
  27.     var clientSecret = cardButton.dataset.secret;
  28.  
  29.     var errorElement = document.querySelector('.error');
  30.  
  31.     cardButton.addEventListener('click', function(ev) {
  32.       stripe.handleCardSetup(
  33.         clientSecret, cardElement, {
  34.           payment_method_data: {
  35.             billing_details: {
  36.               name: cardholderName.value
  37.               }
  38.           }
  39.         }
  40.       ).then(function(result) {
  41.         if (result.error) {
  42.           console.log(result.error)
  43.         } else {
  44.           console.log(result)
  45.         }
  46.       });
  47.     });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top