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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <form>
<div class="paymentForm">
  <div>
    <label for="cardNumberPlaceholder">Card Number</label>
    <div id="cardNumberPlaceholder">
    </div>
  </div>
  <div>
    <label for="cvvPlaceholder">Cvv</label>
    <div id="cvvPlaceholder">
    </div>
  </div>

  <button type="button" class="btn btn-primary" id="go">
    Pay (get transactionId)
  </button>
</div>
</form>

<br/>

<div id="result" class="alert alert-success" role="alert"></div>

              
            
!

CSS

              
                label {
  display: block
}

.paymentForm {
  border: 0px;
  background-color: #F7F8F9;
  padding: 10px
}

#cardNumberPlaceholder {
  display: inline-block;
  width: 300px;
  height: 38px;
}

#cvvPlaceholder {
  display: inline-block;
  width: 120px;
  height: 38px;
}

#result {
  display: none;
}
              
            
!

JS

              
                $(document).ready(function() {
  console.log("doc ready");
  
  var secureFields = new SecureFields();
  
  secureFields.initPay(
    "1100016565", {
      cardNumber: "cardNumberPlaceholder",
      cvv: "cvvPlaceholder"
    },{
      // options...          
    }    
  );
  
  secureFields.on("ready", function() {
    console.log("ready");
    
    secureFields.setStyle("cardNumber","width: 80%; background-color: white; border-radius: 4px; border: 1px solid #ccc; padding: .65em .5em; font-size: 91%;");
    secureFields.setStyle("cardNumber::placeholder","color: #D8D8D8");
    
    secureFields.setStyle("cvv","width: 80%; background-color: white; border-radius: 4px; border: 1px solid #ccc; padding: .65em .5em; font-size: 91%;");
    secureFields.setStyle("cvv::placeholder","color: #D8D8D8");
    
    secureFields.setPlaceholder("cardNumber", "4242 4242 4242 4242");
    secureFields.setPlaceholder("cvv", "123");
    
    //secureFields.focus("cardNumber");
  });
  
  secureFields.on("validate", function(data) {
    secureFields.setStyle("cardNumber", data.fields.cardNumber.valid ? "border: 1px solid #ccc": "border: 1px solid #f00");
    secureFields.setStyle("cvv", data.fields.cvv.valid ? "border: 1px solid #ccc" : "border: 1px solid #f00");
  });
  
 
  $("#go").click( function() {
    secureFields.submit({
     amount: 100,
     expm: 12, // hardcoded, ask for the expm in your own form
     expy: 21, // hardcoded, ask for the expy in your own form
     currency: "CHF",
     returnUrl: "https://pay.sandbox.datatrans.com/upp/merchant/successPage.jsp" // replace with your own returnUrl
     }); // submit the "form" providing additional details    
  });
  
  secureFields.on("success", function(data) {
    if(data.transactionId !== undefined) {
      console.log(data);
      var trxId = document.getElementById("result");
      var result = "Your transactionId is: " + data.transactionId;
      
      if(data.redirect !== undefined) {
        result = result + "<br>3D redirect URL: <a href='" + data.redirect + "' target='_blank'>Click</a>";
      }
      
     if(data.cardInfo !== undefined) {
        result = result + "<br>CardInfo: " + JSON.stringify(data.cardInfo,null,2);
      }
      trxId.innerHTML = result;
      trxId.style.display = 'block';
      
      console.log(data.cardInfo);
      
    }
  });
      
});
              
            
!
999px

Console