Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
    <meta charset="utf-8"><!DOCTYPE html>
<!--suppress ALL -->
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
    <title>Parent Window</title>
<!-- <script src="https://checkout.dev1.dev.clover.com/sdk.js"></script> -->
    <script src="https://checkout.sandbox.dev.clover.com/sdk.js"></script>
   
</head>
<body>
  <div class="container">
    <form action="/charge" method="post" id="payment-form">
      
      <div class="form-row top-row">
        <div id="card-number" class="field card-number"></div>
        <div class="input-errors" id="card-number-errors" role="alert"></div>
      </div>

      <div class="form-row">
        <div id="card-date" class="field third-width"></div>
        <div class="input-errors" id="card-date-errors" role="alert"></div>
      </div>

      <div class="form-row">
        <div id="card-cvv" class="field third-width"></div>
        <div class="input-errors" id="card-cvv-errors" role="alert"></div>
      </div>
      
      <div class="form-row">
        <div id="card-postal-code" class="field third-width"></div>
        <div class="input-errors" id="card-postal-code-errors" role="alert"></div>
      </div>

      <!-- Used to display form errors. -->
      <div id="card-errors" role="alert"></div>

      <!-- Testing -->
      <div id="card-response" role="alert"></div>

      <div class="button-container">
        <button>Submit Payment</button>
      </div>
    </form>
  </div>
  
</body>

</html>

              
            
!

CSS

              
                body {
  background-color: #192130;
  margin: 1px;
  width: 300px;
}

form {
/*   background-color: #123456; */
background-image: linear-gradient(rgba(0, 0, 255, 0.5), rgba(255, 255, 0, 0.5)), url("https://interactive-examples.mdn.mozilla.net/media/examples/lizard.png");
  padding: 20px;
}

.container {
  background-color: #FFFFFF;
  border-top-left-radius: 15px;
  border-top-right-radius: 15px;
  box-shadow: 0 0 6px 0 rgba(141,151,158,0.2);
  padding: 24px;
}

.container * {
  font-family: Roboto, "Open Sans", sans-serif;
  font-size: 16px;
}

.container .form-row {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-between;
}

.container .form-row.top-row {
  margin-top: 16px;
}

.input-errors {
  font-size: 12px;
  position: absolute;
  margin-left: 5px;
  margin-top: 54px;
  color: red;
}

.container .form-row .field {
  box-sizing: border-box;
  border: 1px solid #DEE0E1;
  border-radius: 3px;
  height: 51px;
  margin-bottom: 35px;
  padding: 10px;
  width: 100%;
  background-color: beige;
}

.container .button-container {
  display: flex;
  flex-direction: row;
  justify-content: center;
}

.container .button-container button {
  background-color: #228800;
  border: none;
  border-radius: 3px;
  color: #FFFFFF;
  display: block;
  height: 51px;
  width: 300px;
}

@media (min-width: 300px) {
  body {
    width: auto;
  }
}

@media (min-width: 750px) {
  body {
    width: 750px;
  }
  
  .container {
    height: 410px;
  }

  .container .form-row .field.card-number {
    width: 460px;
  }
  
  .container .form-row .field.third-width {
    width: 218px;
  }
}

              
            
!

JS

              
                const clover = new Clover('fc9e4d48df0d110f12813a5190a4f424');
 const elements = clover.elements();
 const styles = {
   body: {
     fontFamily: 'Roboto, Open Sans, sans-serif',
     fontSize: '16px',
   },
   input: {
     fontSize: '16px',
// Fixes for https://community.clover.com/questions/24714/issue-in-clover-hosted-iframe-application-running.html
     padding: '0px',
     margin: '0px',
     backgroundColor: 'beige'
   },
   "input:focus": { border: "1px solid red" }
 };
 const cardNumber = elements.create('CARD_NUMBER', styles);
 const cardDate = elements.create('CARD_DATE', styles);
 const cardCvv = elements.create('CARD_CVV', styles);
 const cardPostalCode = elements.create('CARD_POSTAL_CODE', styles);
 
 cardNumber.mount('#card-number');
 cardDate.mount('#card-date');
 cardCvv.mount('#card-cvv');
 cardPostalCode.mount('#card-postal-code');  

 const cardResponse = document.getElementById('card-response');

 const displayCardNumberError = document.getElementById('card-number-errors');
 const displayCardDateError = document.getElementById('card-date-errors');
 const displayCardCvvError = document.getElementById('card-cvv-errors');
 const displayCardPostalCodeError = document.getElementById('card-postal-code-errors');
 
 // Handle real-time validation errors from the card Element.
 cardNumber.addEventListener('change', function(event) {
   console.log(`cardNumber changed ${JSON.stringify(event)}`);
   displayCardNumberError.innerHTML = event.CARD_NUMBER.error || '';
 });

 cardNumber.addEventListener('blur', function(event) {
   console.log(`cardNumber blur ${JSON.stringify(event)}`);
   displayCardNumberError.innerHTML = event.CARD_NUMBER.error || '';
 });

 cardDate.addEventListener('change', function(event) {
   console.log(`cardDate changed ${JSON.stringify(event)}`);
   displayCardDateError.innerHTML = event.CARD_DATE.error || '';
 });

 cardDate.addEventListener('blur', function(event) {
   console.log(`cardDate blur ${JSON.stringify(event)}`);
   displayCardDateError.innerHTML = event.CARD_DATE.error || '';
 });

 cardCvv.addEventListener('change', function(event) {
   console.log(`cardCvv changed ${JSON.stringify(event)}`);
   displayCardCvvError.innerHTML = event.CARD_CVV.error || '';
 });

 cardCvv.addEventListener('blur', function(event) {
   console.log(`cardCvv blur ${JSON.stringify(event)}`);
   displayCardCvvError.innerHTML = event.CARD_CVV.error || '';
 });

 cardPostalCode.addEventListener('change', function(event) {
   console.log(`cardPostalCode changed ${JSON.stringify(event)}`);
   displayCardPostalCodeError.innerHTML = event.CARD_POSTAL_CODE.error || '';
 });

 cardPostalCode.addEventListener('blur', function(event) {
   console.log(`cardPostalCode blur ${JSON.stringify(event)}`);
   displayCardPostalCodeError.innerHTML = event.CARD_POSTAL_CODE.error || '';
 });

 // TODO: Register event handlers
 const form = document.getElementById('payment-form');
 form.addEventListener('submit', function(event) {
   event.preventDefault();

   clover.createToken()
     .then(function(result) {
       if (result.errors) {
         Object.values(result.errors).forEach(function (value) {
console.log(value);
         });
       } else {
         alert(result.token);
       }
     }).catch(function(data){
       console.log(data);
     });
 });


 // Submit the form with the token ID.
function cloverTokenHandler(token) {
 // Insert the token ID into the form so it gets submitted to the server
 var form = document.getElementById('payment-form');
 var hiddenInput = document.createElement('input');
 hiddenInput.setAttribute('type', 'hidden');
 hiddenInput.setAttribute('name', 'cloverToken');
 hiddenInput.setAttribute('value', token);
 form.appendChild(hiddenInput);
 alert(token);
 // Submit the form
 // form.submit();
}
              
            
!
999px

Console