Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <div class="panel panel-default bootstrap-basic">
   <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">Name on Card</label>
          <input type="text" class="form-control" id="cardholder-name" placeholder="Full Name">
          <span class="helper-text"></span>
       <!--Hosted Field for CC number-->
       <div class="form-group col-md-12">
          <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="" height="20px"></div>
         <span class="helper-text" id="ccn-help"></span>
			 <!--Hosted Field for CC EXP-->
       <div class="form-group col-xs-7">
          <label for="exp-date">Exp. Date</label>
          <div class="form-control" id="exp-date" data-bluesnap="exp"></div>
          <span class="helper-text" id="exp-help"></span>
			<!--Hosted Field for CC CVV-->
			<div class="form-group col-xs-5">
         <label for="cvv">Security Code</label>
         <div class="form-control" id="cvv" data-bluesnap="cvv"></div>
         <span class="helper-text" id='cvv-help'></span>

		<button class="btn btn-success btn-lg col-xs-6 col-xs-offset-3" type="submit" id="submit-button">Pay Now</button>

<!--BlueSnap Hosted Payment Fields JavaScript file-->
<script type="text/javascript" src=""></script>
              /* Bootstrap styles*/

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

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

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

.helper-text-green {
  color: green;

/* Hosted Payment Fields styles*/
.hosted-field-focus { 
  border: 1px solid #66afe9;
  box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6);

.hosted-field-invalid {
  border: 1px solid #e93143;
  box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(233,49,67, 0.8);

.hosted-field-valid {
  border: 1px solid #14ba57 ;

              /* 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 returns 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 and associated card image URL
var cardUrl = {
  "AmericanExpress": "", 
  "CarteBleau": "",
  "DinersClub": "",
  "Discover": "",
  "JCB": "",
  "MaestroUK": "",
  "MasterCard": "",
  "Solo": "", 
  "Visa": ""

/* 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-valid hosted-field-invalid", "hosted-field-focus"); 
    onBlur: function(tagId) {
      // Handle blur
      changeImpactedElement(tagId, "hosted-field-focus"); 
    onError: function(tagId, errorCode, errorDescription) {
      // Handle a change in validation
      changeImpactedElement(tagId, "hosted-field-valid hosted-field-focus", "hosted-field-invalid");     
      $("#" + tagId + "-help").removeClass('helper-text-green').text(errorCode + " - " + errorDescription); 
    onType: function(tagId, cardType, cardData) {
      // get card type from cardType and display card image
      $("#card-logo > img").attr("src", cardUrl[cardType]);
      if (null != cardData) {
         $("#" + tagId + "-help").addClass('helper-text-green').text(JSON.stringify(cardData));
    onValid: function(tagId) {
      // Handle a change in validation
      changeImpactedElement(tagId, "hosted-field-focus hosted-field-invalid", "hosted-field-valid"); 
      $("#" + tagId + "-help").text(""); 
  //styling is optional
  style: {
    // Styling all inputs
    "input": {
      "font-size": "14px",
      "font-family": "Helvetica Neue,Helvetica,Arial,sans-serif",
      "line-height": "1.42857143",
      "color": "#555"

    // Styling a specific field
    /*"#ccn": {

    // Styling Hosted Payment Field input state
    ":focus": {
      "color": "#555"
  ccnPlaceHolder: "4111222233334444",
  cvvPlaceHolder: "123",
  expPlaceHolder: "MM/YY",
  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() {
  bluesnap.hostedPaymentFieldsCreation("95a19f640f236b6c6397f3f1a3131f136d030184acab3d23b9c6576d7577de79_", bsObj); //insert your Hosted Payment Fields token

/* Calling bluesnap.submitCredentials: function that submits card data to BlueSnap, where it will be associated with token, and calls input function with card data object if submission was successful */
function do_when_clicking_submit_button() {
  bluesnap.submitCredentials(function(callback) {
      if (null != callback.error) {
        var errorArray = callback.error;
            for (i in errorArray) {
        $("#" + errorArray[i].tagId + "-help").text(errorArray[i].errorCode + " - " + errorArray[i].errorDescription); 
      } else {
        var cardData = callback.cardData;
        "Card Type: " +
        cardData.ccType +
        " Last 4 Digits: " +
        cardData.last4Digits +
        " Issuing Country: " +
        cardData.issuingCountry +
        " Is Regulated Card: " +
        cardData.isRegulatedCard + 
        " Card Sub Type: " + 
        cardData.cardSubType + 
        " Bin Category: " +
        cardData.binCategory +    
        " Exp: " +
        cardData.exp +
        " after that I can call final submit"
      // This is where you would perform final submission to your server
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.