Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <script src="https://checkout.sandbox.dev.clover.com/sdk.js"></script><!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>GPay and Hosted Checkout</title>
</head>
<body>
  <div class="container">
    <form action="/charge" method="post" id="payment-form">
      <div class="form-row top-row">
        <div id="payment-request-button" class="payment-request-button full-width"></div>
      </div>
      
      <div class="hr">
  <span>
    Or Pay with Card
  </span>
</div>
      
      <div class="form-row top-row">
        <div id="card-number" class="field full-width"></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>
  </div>

</body>

</html>


              
            
!

CSS

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

.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: 55px;
  margin-bottom: 30px;
  padding: 14px;
  width: 100%;
}

.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: 47px;
  width: 300px;
}

#payment-request-button {
  width: 300px;
  height: 40px;
  margin: 0 auto;
}

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

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

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

.hr {
  width: 100%; 
  height: 10px; 
  border-bottom: 1px solid black; 
  text-align: center;
  margin: 20px 0;
}

.hr span {
  font-size: 10px; 
  background-color: #FFF; 
  padding: 0 10px;
}

              
            
!

JS

              
                const clover = new Clover('fc9e4d48df0d110f12812a5190a4f424');
const elements = clover.elements();
const styles = {
  body: {
    fontFamily: 'Roboto, Open Sans, sans-serif',
    fontSize: '16px',
  },
  input: {
    fontSize: '16px',
  },
};
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)}`);
});

cardNumber.addEventListener('blur', function(event) {
  console.log(`cardNumber blur ${JSON.stringify(event)}`);
});

cardDate.addEventListener('change', function(event) {
  console.log(`cardDate changed ${JSON.stringify(event)}`);
});

cardDate.addEventListener('blur', function(event) {
  console.log(`cardDate blur ${JSON.stringify(event)}`);
});

cardCvv.addEventListener('change', function(event) {
  console.log(`cardCvv changed ${JSON.stringify(event)}`);
});

cardCvv.addEventListener('blur', function(event) {
  console.log(`cardCvv blur ${JSON.stringify(event)}`);
});

cardPostalCode.addEventListener('change', function(event) {
  console.log(`cardPostalCode changed ${JSON.stringify(event)}`);
});

cardPostalCode.addEventListener('blur', function(event) {
  console.log(`cardPostalCode blur ${JSON.stringify(event)}`);
});

// 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);
  });
});

const paymentReqData = {
  total: {
    amount: 99
  },
  options:{
    button:{
      buttonType: 'long'
    }
  }
};
  
// const paymentRequest = clover.paymentRequest(paymentReqData);
const paymentRequestButton = elements.create('PAYMENT_REQUEST_BUTTON', {
  paymentReqData
});
paymentRequestButton.mount('#payment-request-button');
// Check the availability of the Payment Request API first.
// paymentRequest.canMakePayment().then(function(result) {
//     if (result) {
//       paymentRequestButton.mount('#payment-request-button');
//     } else {
//       document.getElementById('payment-request-button').style.display = 'none';
//     }
//   });
paymentRequestButton.addEventListener('paymentMethod', function(ev) {
  alert(JSON.stringify(ev));
})

// 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