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

              
                <div class="container">
  <div class="row">
    <div class="col-xs-12 col-md-4"></div>
    <div class="col-xs-12 col-md-4">
      <!-- CREDIT CARD FORM STARTS HERE -->
      <div class="panel panel-default credit-card-box">
        <div class="panel-heading display-table">
          <div class="row display-tr">
            <h3 class="panel-title display-td">Payment form with 3D Secure 2 enabled</h3>
          </div>
        </div>
        <div class="panel-body">
          <div class="col-xs-12 accepted-brands">
            <img class="img-responsive center-block" src="https://www.cardrates.com/wp-content/uploads/2017/11/networks.png">
          </div>
          <form role="form" id="payment-form" method="POST" action="javascript:void(0);">
            <div class="row">
              <div class="col-xs-6">
                <div class="form-group">
                  <label>Payment amount</label>
                  <div>
                    <span class="amount">$ 500.00</span>
                  </div>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-xs-12">
                <div class="form-group">
                  <label for="cardholder-name">Name on card</label>
                  <input class="form-control" id="cardholder-name" value="John Smith" />
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-xs-12">
                <div class="form-group">
                  <label for="cardNumber">Card number</label>
                  <div class="input-group">
                    <div class="form-control" id="cardNumber"> </div>
                    <span class="input-group-addon">
                      <i class="fa fa-credit-card"></i>
                    </span>
                  </div>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-xs-7 col-md-7">
                <div class="form-group">
                  <label for="cardExpiry">
                    <span class="hidden-xs">Expiry</span>
                    <span class="visible-xs-inline">Exp</span> Date</label>
                  <div class="form-control" id="cardExpiry"></div>
                </div>
              </div>
              <div class="col-xs-5 col-md-5 pull-right">
                <div class="form-group">
                  <label for="cardCVC">CV code</label>
                  <div class="form-control" id="cardCVC"></div>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-xs-12">
                <div class="form-group">
                  <label for="zip-code">Zip/postal code</label>
                  <input class="form-control" id="zip-code" />
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-xs-12">
                <button class="pay btn btn-primary btn-lg btn-block" type="button">Pay</button>
              </div>
            </div>
            <div class="row" style="display:none;">
              <div class="col-xs-12">
                <p class="payment-errors"></p>
              </div>
            </div>
          </form>
        </div>
      </div>
      <!-- CREDIT CARD FORM ENDS HERE -->

    <p id="token"></p>
    </div>
  </div>
</div>
              
            
!

CSS

              
                body { margin-top:20px; }

.credit-card-box .panel-title {
    display: inline;
    font-weight: bold;
}
.credit-card-box .form-control.error {
    border-color: red;
    outline: 0;
    box-shadow: inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(255,0,0,0.6);
}
.credit-card-box label.error {
  font-weight: bold;
  color: red;
  padding: 2px 8px;
  margin-top: 2px;
}
.credit-card-box .payment-errors {
  font-weight: bold;
  color: red;
  padding: 2px 8px;
  margin-top: 12px;
}
.credit-card-box label {
    display: block;
}

.credit-card-box .display-tr {
    display: table-row;
}
.credit-card-box .display-td {
    display: table-cell;
    vertical-align: middle;
    width: 50%;
}

.credit-card-box .panel-heading img {
    min-width: 180px;
    border-style: solid;
    border-width: 3px;
    border-color: white;
    box-shadow: 3px 3px 5px #D3D3D3;
}

.accepted-brands {
  height: 35px;
  margin-bottom: 20px;
}

.accepted-brands img {
  max-height:100%;
  max-width: 100%;
}

.amount {
  font-size: x-large;
}

#token {
  font-size: 14pt;
  color: rgb(68, 157, 68);
  font-weight: bold;
}
              
            
!

JS

              
                var paysafeJsInstance = undefined;
// Base 64 encoded version of the Single-Use-Token API key.
// Create the key below by concatenating the API username and password
// separated by a colon and Base 64 encoding the result
var apiKey = "T1QtMTE3MDQwOkItcWEyLTAtNTk1NjRlNWMtMC0zMDJjMDIxNDdmMDU4M2I2OGY4ZWQyNjkxNDIxMDczMzZiYWIyMTZmOWMzZGJiNTEwMjE0MTgwYzY1NGQ3OTgzZmI2NTliYzEzZWY4YWMyZmQ1MTliMjVhOTQxZQ==";
var $form = $("#payment-form");
var $cardholderName = $("#cardholder-name");
$form.find(".pay").prop("disabled", true);
var options = {

  // select the Paysafe test / sandbox environment
  environment: "TEST",

  // set the CSS selectors to identify the payment field divs above
  // set the placeholder text to display in these fields
  fields: {
    cardNumber: {
      selector: "#cardNumber",
      placeholder: "Card Number"
    },
    expiryDate: {
      selector: "#cardExpiry",
      placeholder: "MM / YY"
    },
    cvv: {
      selector: "#cardCVC",
      placeholder: "CVV"
    }
  }
};

// initalize the hosted iframes using the SDK setup function
paysafe.fields.setup(apiKey, options, function (instance, error) {

  if (error) {
    console.log(error);
  } else {
    paysafeJsInstance = instance;
    var payButton = $form.find(".pay");

    console.log(payButton);

    instance.fields("cvv cardNumber expiryDate").valid(function (eventInstance, event) {
      $(event.target.containerElement).closest(".form-control").removeClass("error").addClass("success");

      if (paymentFormReady()) {
        $form.find(".pay").prop("disabled", false);
      }
    });

    instance.fields("cvv cardNumber expiryDate").invalid(function (eventInstance, event) {
      $(event.target.containerElement).closest(".form-control").removeClass("success").addClass("error");
      if (!paymentFormReady()) {
        $form.find(".pay").prop("disabled", true);
      }
    });

    payButton.bind("click", function (event) {
        instance.tokenize({
          "threeDS": {
            "amount": 5,
            "currency": "USD",
            "accountId": 1001606520,
            "useThreeDSecureVersion2": true,
            "authenticationPurpose": "PAYMENT_TRANSACTION"
          },
          "vault": {
            "holderName": $cardholderName.val()
          }
        }, function (instance, error, result) {
          if (error) {
            console.log(error);
            $form.find(".pay").html("Try again").prop("disabled", false);
            /* Show Paysafe errors on the form */
            $form.find(".payment-errors").text(error.displayMessage);
            $form.find(".payment-errors").closest(".row").show();
          } else {
            /* Visual feedback */
            $form.find(".pay").html("Processing <i class='fa fa-spinner fa-pulse'></i>");
            /* Hide Paysafe errors on the form */
            $form.find(".payment-errors").closest(".row").hide();
            $form.find(".payment-errors").text("");

            // response contains token
            console.log(result.token);

            // you would send the "token" to your server here using AJAX. The delay function simulates this process.
            delay(function () {
              $form.find(".pay").html("Payment successful <i class='fa fa-check'></i>");
              $form.find(".pay").prop("disabled", true);
              showToken(result.token);
              // do stuff
            }, 2000);// end delay
          }
        });
    });
  }
});

$cardholderName.change(function () {
  if ($cardholderName.val().length > 0) {
    $cardholderName.removeClass("error").addClass("success");
  } else {
    $cardholderName.removeClass("success").addClass("error");
  }
  if (paymentFormReady()) {
    $form.find(".pay").prop("disabled", false);
  } else {
    $form.find(".pay").prop("disabled", true);
  }
});

function paymentFormReady() {
  return $cardholderName.val().length > 0
    && paysafeJsInstance.fields.cardNumber.isValid()
    && paysafeJsInstance.fields.expiryDate.isValid()
    && paysafeJsInstance.fields.cvv.isValid();
}

var delay = (function () {
  var timer = 0;
  return function (callback, ms) {
    clearTimeout(timer);
    timer = setTimeout(callback, ms);
  };
})();

function showToken(token) {
  var codetoken = $("span:contains(\"PAYMENT TOKEN RECEIVED FROM CLIENT BROWSER\")").first();
  if (codetoken.length == 1) {
    codetoken.attr("id", "sampletoken");
  }
  else {
    codetoken = $("#sampletoken");
  }
  var tokenP = $("#token");

  codetoken.text('\"' + token + '\"');
  tokenP.text('Returned single-use token ' + token);
}
              
            
!
999px

Console