Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 4.38 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport"
  6.          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7.     <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8.     <title>Document</title>
  9.  
  10.     <style type="text/css">
  11.         /**
  12.  * The CSS shown here will not be introduced in the Quickstart guide, but shows
  13.  * how you can use CSS to style your Element's container.
  14.  */
  15.         .StripeElement {
  16.             box-sizing: border-box;
  17.  
  18.             height: 40px;
  19.  
  20.             padding: 10px 12px;
  21.  
  22.             border: 1px solid transparent;
  23.             border-radius: 4px;
  24.             background-color: white;
  25.  
  26.             box-shadow: 0 1px 3px 0 #e6ebf1;
  27.             -webkit-transition: box-shadow 150ms ease;
  28.             transition: box-shadow 150ms ease;
  29.         }
  30.  
  31.         .StripeElement--focus {
  32.             box-shadow: 0 1px 3px 0 #cfd7df;
  33.         }
  34.  
  35.         .StripeElement--invalid {
  36.             border-color: #fa755a;
  37.         }
  38.  
  39.         .StripeElement--webkit-autofill {
  40.             background-color: #fefde5 !important;
  41.         }
  42.     </style>
  43. </head>
  44. <body>
  45. <div class="row">
  46.     <div class="col-12">
  47.         <form action="{{ route('bundles.charge') }}" method="post" id="payment-form">
  48.             @csrf
  49.  
  50.             <div class="form-row">
  51.                 <label for="card-element">
  52.                     Credit or debit card
  53.                 </label>
  54.                 <div id="card-element">
  55.                     <!-- A Stripe Element will be inserted here. -->
  56.                 </div>
  57.  
  58.                 <!-- Used to display form errors. -->
  59.                 <div id="card-errors" role="alert"></div>
  60.             </div>
  61.  
  62.             <button>Submit Payment</button>
  63.         </form>
  64.     </div>
  65. </div>
  66.  
  67.  
  68. <script src="https://js.stripe.com/v3/"></script>
  69.  
  70. <script>
  71.     // Create a Stripe client.
  72.     var stripe = Stripe('pk_test_j8J6ZkZNeCbbguMFf2BWszRP0045uQeRgv');
  73.  
  74.     // Create an instance of Elements.
  75.     var elements = stripe.elements();
  76.  
  77.     // Custom styling can be passed to options when creating an Element.
  78.     // (Note that this demo uses a wider set of styles than the guide below.)
  79.     var style = {
  80.         base: {
  81.             color: '#32325d',
  82.             fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
  83.             fontSmoothing: 'antialiased',
  84.             fontSize: '16px',
  85.             '::placeholder': {
  86.                 color: '#aab7c4'
  87.             }
  88.         },
  89.         invalid: {
  90.             color: '#fa755a',
  91.             iconColor: '#fa755a'
  92.         }
  93.     };
  94.  
  95.     // Create an instance of the card Element.
  96.     var card = elements.create('card', {style: style});
  97.  
  98.     // Add an instance of the card Element into the `card-element` <div>.
  99.     card.mount('#card-element');
  100.  
  101.     // Handle real-time validation errors from the card Element.
  102.     card.addEventListener('change', function(event) {
  103.         var displayError = document.getElementById('card-errors');
  104.         if (event.error) {
  105.             displayError.textContent = event.error.message;
  106.         } else {
  107.             displayError.textContent = '';
  108.         }
  109.     });
  110.  
  111.     // Handle form submission.
  112.     var form = document.getElementById('payment-form');
  113.     form.addEventListener('submit', function(event) {
  114.         event.preventDefault();
  115.  
  116.         stripe.createToken(card).then(function(result) {
  117.             if (result.error) {
  118.                 // Inform the user if there was an error.
  119.                 var errorElement = document.getElementById('card-errors');
  120.                 errorElement.textContent = result.error.message;
  121.             } else {
  122.                 // Send the token to your server.
  123.                 stripeTokenHandler(result.token);
  124.             }
  125.         });
  126.     });
  127.  
  128.     // Submit the form with the token ID.
  129.     function stripeTokenHandler(token) {
  130.         // Insert the token ID into the form so it gets submitted to the server
  131.         var form = document.getElementById('payment-form');
  132.         var hiddenInput = document.createElement('input');
  133.         hiddenInput.setAttribute('type', 'hidden');
  134.         hiddenInput.setAttribute('name', 'stripeToken');
  135.         hiddenInput.setAttribute('value', token.id);
  136.         form.appendChild(hiddenInput);
  137.  
  138.         // Submit the form
  139.         form.submit();
  140.     }
  141. </script>
  142.  
  143. </body>
  144. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement