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

              
                <html>

<head>
  <link rel="shortcut icon" type="image/png" href="/favicon.png" />
  <script src="https://fattjs.fattpay.com/js/fattmerchant.js?nocache=1"></script>
</head>

<body>
  <form onsubmit="return false;">
<!--      Make your own form or copy this one -->
    <div class="group">
      <label>
        <span>First Name</span>
        <input 
 name="cardholder-first-name" class="field input-box" placeholder="Jane" />
      </label>
      <label>
        <span>Last Name</span>
        <input name="cardholder-last-name" class="field input-box" placeholder="Doe" />
      </label>
      <label>
        <span>Phone</span>
        <input name="phone" class="field input-box"  placeholder="+1000000000000" />
      </label>
    </div>
    <div class="group">
      <label>
        <span>Card</span>
        <div id="card-element" class="field">
          <div id="fattjs-number" style="width:180px; height:35px; display: inline-block; margin:3px"></div>
          <div id="fattjs-cvv" style="width:50px; height:35px; display: inline-block; margin:3px"></div>
        </div>
        <div style="width:40px; height:35px; display: inline-block;">
          <input name="month" size="3" maxlength="2" placeholder="MM" style="width: 22px; height:18px; border-radius: 3px; border: 1px solid #ccc; padding: .5em .5em; font-size: 91%;">
        </div>
        /
        <div style="width:55px; height:35px; display: inline-block;padding: 0 8px 0 0">
          <input name="year" size="5" maxlength="4" placeholder="YYYY" style="width: 40px; height:18px; border-radius: 3px; border: 1px solid #ccc; padding: .5em .5em; font-size: 91%">
        </div>
      </label>
    </div>
    <button id="paybutton">Pay $1</button>
    <button id="tokenizebutton">Tokenize Card</button>
    <!-- <button id="verifybutton">verify $1</button> -->
    <div class="outcome">
      <div class="error"></div>
      <div class="success">
        Successful! The ID is
        <span class="token"></span>
      </div>
      <div class="loader" style="margin: auto">
      </div>
  </form>
</body>

</html>
              
            
!

CSS

              
                * {
    font-family: "Helvetica Neue", Helvetica;
    font-size: 15px;
    font-variant: normal;
    padding: 0;
    margin: 0;
}

html {
    height: 100%;
}

body {
    background: #E6EBF1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100%;
}

form {
    width: 530px;
    margin: 20px 0;
}

.group {
    background: white;
    box-shadow: 0 7px 14px 0 rgba(49, 49, 93, 0.10),
    0 3px 6px 0 rgba(0, 0, 0, 0.08);
    border-radius: 4px;
    margin-bottom: 20px;
}

label {
    position: relative;
    color: #8898AA;
    font-weight: 300;
    height: 40px;
    line-height: 40px;
    margin-left: 20px;
    display: flex;
    flex-direction: row;
}

.group label:not(:last-child) {
    border-bottom: 1px solid #F0F5FA;
}

label>span {
    width: 80px;
    text-align: right;
    margin-right: 30px;
}

.field {
    background: transparent;
    font-weight: 300;
    color: #31325F;
    outline: none;
    flex: 1;
    padding-right: 10px;
    padding-left: 10px;
    cursor: text;
}

.field::-webkit-input-placeholder {
    color: #CFD7E0;
}

.field::-moz-placeholder {
    color: #CFD7E0;
}

button {
    float: left;
    display: block;
    background:#555ABF;
    color: white;
    box-shadow: 0 7px 14px 0 rgba(49, 49, 93, 0.10),
    0 3px 6px 0 rgba(0, 0, 0, 0.08);
    border-radius: 4px;
    border: 0;
    margin-top: 20px;
    font-size: 15px;
    font-weight: 400;
    width: 100%;
    height: 40px;
    line-height: 38px;
    outline: none;
    cursor: pointer
}

button:focus {
    background: #555ABF;
}

button:active {
    background: #43458B;
}

button[disabled] {
    background:  #8898AA;
    cursor: default
}

.outcome {
    float: left;
    width: 100%;
    padding-top: 8px;
    min-height: 24px;
    text-align: center;
}

.success,
.error,
.loader {
    display: none;
    font-size: 13px;
}

.success.visible,
.error.visible {
    display: inline;
}

.loader.visible {
    display: block;
}

.error {
    color: #E4584C;
}

.success {
    color: #666EE8;
}

.success .token {
    font-weight: 500;
    font-size: 13px;
}


.loader {
    border: 4px solid #f3f3f3; /* Light grey */
    border-top: 4px solid #666EE8; /* Blue */
    border-radius: 50%;
    width: 25px;
    height: 25px;
    animation: spin 2s linear infinite;
    margin: 8px
}

.loader-small {
    border: 4px solid #f3f3f3; /* Light grey */
    border-top: 4px solid #666EE8; /* Blue */
    border-radius: 50%;
    width: 2em;
    height: 2em;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.input-box {
  margin-left: 12px;
  margin-right: 6px;
  margin-top: 3px;
  margin-bottom: 3px;
  border-radius: 3px;
  border: 1px solid #ccc;
}

              
            
!

JS

              
                var payButton = document.querySelector('#paybutton');
var tokenizeButton = document.querySelector('#tokenizebutton');

// Init FattMerchant API
var fattJs = new FattJs('fattmerchantdemo', {
  number: {
    id: 'fattjs-number',
    placeholder: '0000 0000 0000 0000',
    style: 'width: 90%; height:90%; border-radius: 3px; border: 1px solid #ccc; padding: .5em .5em; font-size: 91%;'
  },
  cvv: {
    id: 'fattjs-cvv',
    placeholder: '000',
    style: 'width: 30px; height:90%; border-radius: 3px; border: 1px solid #ccc; padding: .5em .5em; font-size: 91%;'
  }
});

// tell fattJs to load in the card fields
fattJs.showCardForm().then(handler => {
  console.log('form loaded');

  // for testing!
  handler.setTestPan('4111111111111111');
  handler.setTestCvv('123');
  var form = document.querySelector('form');
  form.querySelector('input[name=month]').value = 11;
  form.querySelector('input[name=year]').value = 2020;
  form.querySelector('input[name=cardholder-first-name]').value = 'Jon';
  form.querySelector('input[name=cardholder-last-name]').value = 'Doe';
  form.querySelector('input[name=phone]').value = '+1111111111111111';
})
.catch(err => {
  console.log('error init form ' + err);
  // reinit form
});

fattJs.on('card_form_complete', (message) => {
  // activate pay button
  payButton.disabled = false;
  tokenizeButton.disabled = false;
  console.log(message);
});

fattJs.on('card_form_uncomplete', (message) => {
  // deactivate pay button
  payButton.disabled = true;
  tokenizeButton.disabled = true;
  console.log(message);
});

document.querySelector('#paybutton').onclick = () => {
  var successElement = document.querySelector('.success');
  var errorElement = document.querySelector('.error');
  var loaderElement = document.querySelector('.loader');

  successElement.classList.remove('visible');
  errorElement.classList.remove('visible');
  loaderElement.classList.add('visible');

  var form = document.querySelector('form');
  var extraDetails = {
    total: 1, // 1$
    firstname: form.querySelector('input[name=cardholder-first-name]').value,
    lastname: form.querySelector('input[name=cardholder-last-name]').value,
    company: '',
    email: '',
    month: form.querySelector('input[name=month]').value,
    year: form.querySelector('input[name=year]').value,
    phone: form.querySelector('input[name=phone]').value,
    address_1: '100 S Orange Ave',
    address_2: '',
    address_city: 'Orlando',
    address_state: 'FL',
    address_zip: '32811',
    address_country: 'USA',
    url: "https://omni.fattmerchant.com/#/bill/",
    method: 'card',
    // validate is optional and can be true or false. 
    // determines whether or not fattmerchant.js does client-side validation.
    // the validation follows the sames rules as the api.
    // check the api documentation for more info:
    // https://fattmerchant.com/api-documentation/
    validate: false,
    // meta is optional and each field within the POJO is optional also
    meta: {
      reference: 'invoice-reference-num',// optional - will show up in emailed receipts
      memo: 'notes about this transaction',// optional - will show up in emailed receipts
      otherField1: 'other-value-1', // optional - we don't care
      otherField2: 'other-value-2', // optional - we don't care
      subtotal: 1, // optional - will show up in emailed receipts
      tax: 0, // optional - will show up in emailed receipts
      lineItems: [ // optional - will show up in emailed receipts
        {"id": "optional-fm-catalog-item-id", "item":"Demo Item","details":"this is a regular, demo item","quantity":10,"price":.1}
      ] 
    }
  };
  
  console.log(extraDetails);

  // call pay api
  fattJs.pay(extraDetails).then((result) => {
    console.log('pay:');
    console.log(result);
    if (result.id) {
      successElement.querySelector('.token').textContent = result.payment_method_id;
      successElement.classList.add('visible');
      loaderElement.classList.remove('visible');
    }
  })
  .catch(err => {
    errorElement.textContent = err.message;
    errorElement.classList.add('visible');
    loaderElement.classList.remove('visible');
  });
}

document.querySelector('#tokenizebutton').onclick = () => {
  var successElement = document.querySelector('.success');
  var errorElement = document.querySelector('.error');
  var loaderElement = document.querySelector('.loader');

  successElement.classList.remove('visible');
  errorElement.classList.remove('visible');
  loaderElement.classList.add('visible');

  var form = document.querySelector('form');
  var extraDetails = {
    total: 1, // 1$
    firstname: form.querySelector('input[name=cardholder-first-name]').value,
    lastname: form.querySelector('input[name=cardholder-last-name]').value,
    month: form.querySelector('input[name=month]').value,
    year: form.querySelector('input[name=year]').value,
    phone: form.querySelector('input[name=phone]').value,
    address_1: '100 S Orange Ave',
    address_2: '',
    address_city: 'Orlando',
    address_state: 'FL',
    address_zip: '32811',
    address_country: 'USA',
    url: "https://omni.fattmerchant.com/#/bill/",
    method: 'card',
    // validate is optional and can be true or false. 
    // determines whether or not fattmerchant.js does client-side validation.
    // the validation follows the sames rules as the api.
    // check the api documentation for more info:
    // https://fattmerchant.com/api-documentation/
    validate: false, 
  };

  // call tokenize api
  fattJs.tokenize(extraDetails).then((result) => {
    console.log('tokenize:');
    console.log(result);
    if (result) {
        successElement.querySelector('.token').textContent = result.id;
        successElement.classList.add('visible');
    }
    loaderElement.classList.remove('visible');
  })
  .catch(err => {
    errorElement.textContent = err.message;
    errorElement.classList.add('visible');
    loaderElement.classList.remove('visible');
  });
}
              
            
!
999px

Console