<div class="panel panel-primary">
  <div class="panel-heading">
      <h3 class="panel-title">Credit Card Payment</h3>
   <form class="panel-body" id="checkout-form" onsubmit="do_when_clicking_submit_button()" action="#">
    <div class="row">
      <div class="form-group col-md-12">
          <label for="cardholder-name">Cardholder Name</label>
          <input type="text" class="form-control" id="cardholder-name">
          <span class="helper-text"></span>
       <!--Hosted Payment Field for CC number-->
       <div class="form-group col-xs-9">
          <label for="card-number">Card Number</label>
          <div class="input-group">
            <div class="form-control" id="card-number" data-bluesnap="ccn"></div>
            <div id="card-logo" class="input-group-addon"><img src="https://files.readme.io/d1a25b4-generic-card.png" height="20px"></div>
         <span class="helper-text" id="ccn-help"></span>
	<!--Hosted Payment Field for CC CVV-->
			<div class="form-group col-xs-3">
         <label for="cvv">CVV</label>
         <div class="form-control" id="cvv" data-bluesnap="cvv"></div>
         <span class="helper-text" id="cvv-help"></span>
    <!--Hosted Payment Field for CC EXP-->
       <div class="form-group col-xs-6">
          <label for="exp-date">Exp. (MM/YY)</label>
          <div class="form-control" id="exp-date" data-bluesnap="exp"></div>
          <span class="helper-text" id="exp-help"></span>
		  <div class="form-group col-xs-6">
          <label for="cardholder-name">Postal Code</label>
          <input type="text" class="form-control" id="cardholder-name">
          <span class="helper-text"></span>
		<button class="btn btn-raised btn-info btn-lg col-md-4" type="submit" id="submit-button">Pay Now</button>

<!--BlueSnap Hosted Payment Fields JavaScript file-->
		<script type="text/javascript" src="https://sandbox.bluesnap.com/services/hosted-payment-fields/v2.0/bluesnap.hpf.min.js"></script>
/* Uses bootstrap-material-design - https://fezvrasta.github.io/bootstrap-material-design */

.panel {
  width: 80%;
  margin: 2em auto;

.panel-body {
  width: 90%;
  margin: 2em auto;

body {
  font-size: 15px;

label {
  font-weight: 400;

.helper-text {
  color: #E91E63; 
  font-size: 12px;
  margin-top: 5px;
  height: 12px;
  display: block;

/* Hosted Payment Fields styles*/
.hosted-field-focus { 
  outline: none;
  background-image: linear-gradient(#009688, #009688), linear-gradient(#d2d2d2, #d2d2d2);
  animation: input-highlight 0.5s forwards;
  box-shadow: none;
  background-size: 0 2px, 100% 1px;
/* Defining helper functions/objects */
// changeImpactedElement: function that removes the provided class(es) and adds the provided class(es) to Hosted Payment Fields element
function changeImpactedElement(tagId, removeClass, addClass) {
    removeClass = removeClass || "";
    addClass = addClass || "";
    $("[data-bluesnap=" + tagId + "]")
// getErrorText: function that takes error code (received from BlueSnap) and gets associated help text
function getErrorText(errorCode) {
  switch (errorCode) {
    case "001":
      return "Please enter a valid card number";
    case "002":
      return "Please enter the CVV/CVC of your card";
    case "003":
      return "Please enter your card's expiration date";
    case "22013": 
      return "Card type is not supported by merchant"; 
    case "400":
      return "Session expired please refresh page to continue";
    case "403": 
    case "404":
    case "500":
      return "Internal server error please try again later";
// cardUrl: object that stores card type code (received from BlueSnap) and associated card image URL
var cardUrl = {
  "AmericanExpress": "https://files.readme.io/97e7acc-Amex.png", 
  "CarteBleau": "https://files.readme.io/5da1081-cb.png",
  "DinersClub": "https://files.readme.io/8c73810-Diners_Club.png",
  "Discover": "https://files.readme.io/caea86d-Discover.png",
  "JCB": "https://files.readme.io/e076aed-JCB.png",
  "MaestroUK": "https://files.readme.io/daeabbd-Maestro.png",
  "MasterCard": "https://files.readme.io/5b7b3de-Mastercard.png",
  "Solo": "https://sandbox.bluesnap.com/services/hosted-payment-fields/cc-types/solo.png", 
  "Visa": "https://files.readme.io/9018c4f-Visa.png"

/* Defining bsObj: object that stores Hosted Payment Fields 
event handlers, styling, placeholder text, etc. */
var bsObj = {
  onFieldEventHandler: {
    onFocus: function(tagId) {
      // Handle focus
      changeImpactedElement(tagId, "", "hosted-field-focus"); 
    onBlur: function(tagId) {
      // Handle blur 
      changeImpactedElement(tagId, "hosted-field-focus"); 
    onError: function(tagId, errorCode) {
      // Handle a change in validation by displaying help text
      $("#" + tagId + "-help").text(getErrorText(errorCode)); 
    onType: function(tagId, cardType) {
      // get card type from cardType and display card image
      $("#card-logo > img").attr("src", cardUrl[cardType]);
    onValid: function(tagId) {
      // Handle a change in validation by removing any help text
      $("#" + tagId + "-help").text(""); 
  style: {
    // Styling all inputs
    "input": {
      "font-size": "14px",
        "RobotoDraft,Roboto,Helvetica Neue,Helvetica,Arial,sans-serif",
      "line-height": "1.42857143",
      "color": "#555"
    // Styling input state
    ":focus": {
      "color": "#555"
  ccnPlaceHolder: "",
  cvvPlaceHolder: "",
  expPlaceHolder: "", 
  expDropDownSelector: false //set to true for exp date dropdown

/* After DOM is loaded, calling bluesnap.hostedPaymentFieldsCreation: function that takes token and bsObj as inputs and initiates Hosted Payment Fields */
$(document).ready(function() {
  ); //insert your Hosted Payment Fields token

/* Calling bluesnap.submitCredentials: function that submits card data to 
BlueSnap and calls input function with card data object if submission was successful */
function do_when_clicking_submit_button() {
    function(cardData) {
        "the card type is " +
        cardData.ccType +
        " and last 4 digits are " +
        cardData.last4Digits +
        " and exp is " +
        cardData.exp +
        " after that I can call final submit"
      // This is where you would perform final submission to your server