css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

            
              <form method="post" action="" id="payment-form" name="dalenysForm" onsubmit="return tokenizeHandler()">
		<div id="card">
			<p>
				<label id="card-label" onclick="focusIframe('hosted-fields-frame-card');">Card number</label>
				<span class="input-container" id="card-container" onclick="focusIframe('hosted-fields-frame-card');"></span>
			</p>

			<p class="w1-2">
				<label id="expiry-label" onclick="focusIframe('hosted-fields-frame-expiry');">MM/YY</label>
				<span class="input-container" id="expiry-container" onclick="focusIframe('hosted-fields-frame-expiry');"></span>
			</p>

			<p class="w1-2">
				<label id="cryptogram-label" onclick="focusIframe('hosted-fields-frame-cryptogram');">
					Cryptogram <i id="crytogram-info" class="fas fa-question-circle" onclick="cryptogramAlert();" ></i>
				</label>
				<span class="input-container" id="cryptogram-container" onclick="focusIframe('hosted-fields-frame-cryptogram');"></span>
			</p>

		</div>

		<!-- This hidden input field will receive the token -->
		<input type="hidden" name="hf-token" id="hf-token">

		<p class="submit">
			<button class="droppable OFF" id="plop">Pay <span class="price">49.50</span><span class="symbol">€</span></button>
		</p>
	</form>

	<div id="info">
		<p><strong>This is a "sandbox environment" payment form: all transaction will be simulated.</strong></p>
		<p><strong>DO NOT</strong> use real bank card data, please use instead one of these test cards:</p>
		<ul>
			<li>VISA: 4111 1111 1111 1111</li>
			<li>MasterCard: 5111 1111 1111 1118</li>
		</ul>
		<p>With any expiry date, and any 3 digits cryptogram.</p>
	</div>
            
          
!
            
              html, body {
    width: 100%;
    height: 100%;
}
body {
	background:#2b4c8a;
    font-size: 1.2em;
}
body * {
    font-family: "Open Sans", "Century Gothic", "Calibri", "Trebuchet MS", Arial, Helvetica, sans-serif;
}
form {
    position: absolute;
    top: 42px;
    left: 50%;
    margin-left: -225px;
    width: 450px;
    transition: top 250ms ease-in-out, height 250ms ease-in-out;
}
#card {
    z-index: 1;
    position: relative;
    height: 140px;
    box-sizing: border-box;
    padding: 30px;
    border-radius: 2px;
    border: 1px solid #e7e6e6;
    background: white;
    box-shadow: 1px 1px 5px rgba(0,0,0,.1);
    transition: height 250ms ease-in-out, padding 250ms ease-in-out, border-radius 250ms ease-in-out, box-shadow 250ms ease-in-out, background-color 250ms ease-in-out;
}
form.up {
    top: 35px;
    height: 180px;
}
form.up #card {
    height: 200px;
    padding: 60px 50px 45px 50px;
}
#card:before,
#card:after {
    opacity: 0;
    transition: opacity 250ms ease-in-out;
}
form.up #card:before {
    content: '';
    z-index: 1;
    display: block;
    position: absolute;
    bottom: 0.75px;
    left: 0;
    width: 100%;
    height: 40px;
    border-bottom: 3px solid rgba(255,255,255,.75);
    border-radius: 20px;
}
form.up #card:after {
    content: '';
    z-index: 1;
    display: block;
    position: absolute;
    top: 10px;
    right: 10px;
    width: 80px;
    height: 40px;
    background-position: 50% 50%;
    background-size: contain;
    background-repeat: no-repeat;
}
form p {
    position: relative;
    height: 40px;
    transition: all 250ms ease-in-out;
}
form.up p:nth-last-child(n+2) {
    margin-bottom: 35px;
}
iframe { height: 40px; } /* FF iframe overflow hack */

.input-container,
.hosted-fields-valid-state.hosted-fields-focus-state {
    position: relative;
    display: inline-block;
    max-width: 100%;
    height: 40px;
    box-sizing: border-box;
    padding: 7px 15px 3px 15px;
    border: 1px solid #fff;
    background: #f3f3f3;
}
.hosted-fields-valid-state.hosted-fields-focus-state {
    overflow: hidden;
}
#card-container {
    width: 100%;
}
#expiry-container,
#cryptogram-container {
    display: block; width: 100%;
}

.w1-2 {
    display: block;
    box-sizing: border-box;
    float: left;
}
.w1-2:nth-child(even) { width: 50%; }
.w1-2:nth-child(odd) { width: 50%; }
label {
    z-index: 1;
    position: absolute;
    padding: 10px 15px;
    left: 0;
    bottom: 0;
    display: block;
    width: 100%;
    height: 40px;
    box-sizing: border-box;
    color: #9c9c9c;
    font-style: italic;
    font-size: 85%;
    cursor: text;
    transition: all 250ms ease-in-out;
}
label.up {
    padding: 0;
    bottom: 42px;
    height: 20px;
    font-size: 75%;
    font-style: normal;
    font-weight:bold;
    color: #353535;
}
label #crytogram-info {
    display: none;
    opcatity: 1;
    vertical-align: middle;
    font-size: 1.2em !important;
    cursor: pointer;
    color:#3e96db;
}
label.up #crytogram-info {
    display: inline-block;
    opacity: 1;
}

.submit {
    position: absolute;
    top: 230px;
    left: 0;
    width: 100%;
    text-align: center;
    opacity: 0;
    transition: opacity 250ms ease-in-out;
}
form.up .submit { opacity: 1; }

button {
    min-width: 200px;
    height: 40px;
	background: #3e96db;
    color:#fff;
    border-radius: 4px;
    border: 1px solid #124981;
    font-size: 1em;
    cursor: pointer;
    transition: background 250ms ease-in-out, box-shadow 250ms ease-in-out;
}
button .price,
button .symbol {
    font-weight: 600;
}

button:hover {
    background: #3e96db;
    border: 1px solid #3e96db;
}

button:after {
    content: "";
    z-index: 2;
    position: absolute;
    top: -50%;
    left: 50%;
    margin-left: -50px;
    width: 100px;
    height: 100px;
    border-radius: 15px;
    background-image: url(https://sapereaude.io/codepen/RjLdaN/assets/contactless.svg);
    background-position: 50% 50%;
    background-size: 80% 80%;
    background-repeat: no-repeat;
    opacity: .25;
}
button.OFF:after {
    display: none;
}
/*button.ON:after,*/
button.ui-state-hover:after
{
    display: block !important;
}

/*
#card.american_express label.up,
#card.bancontact label.up,
#card.maestro label.up,
#card.mastercard label.up,
#card.visa label.up { color: white; }*/

#card.american_express:before,
#card.bancontact:before,
#card.maestro:before,
#card.mastercard:before,
#card.visa:before,
#card.american_express:after,
#card.bancontact:after,
#card.maestro:after,
#card.mastercard:after,
#card.visa:after { opacity: 1; }

/*#card.american_express { background: #007cc3; }
#card.bancontact { background: #bd1922; }
#card.maestro { background: linear-gradient(115deg, #009ddd, #009ddd 50%, #ed1c2e 50%, #ed1c2e) }
#card.mastercard { background: linear-gradient(115deg, #d82332, #d82332 50%, #f1ad3d 50%, #f1ad3d); }
#card.visa { background: #0d4aa2; }*/

#card.american_express:after { background-image: url(https://sapereaude.io/codepen/RjLdaN/assets/american_express.svg); }
#card.bancontact:after { background-image: url(https://sapereaude.io/codepen/RjLdaN/assets/bancontact.svg); }
#card.maestro:after { background-image: url(https://sapereaude.io/codepen/RjLdaN/assets/maestro.svg); }
#card.mastercard:after { background-image: url(https://sapereaude.io/codepen/RjLdaN/assets/mastercard.svg); }
#card.visa:after { background-image: url(https://sapereaude.io/codepen/RjLdaN/assets/visa.svg); }

.hosted-fields-focus-state {
    border: 2px solid #92d5f6; 
}
.hosted-fields-invalid-state {
    border: 2px solid #ec694a;
    animation-name: wriggle;
    animation-duration: 75ms;
    animation-iteration-count: 2;
    animation-direction: normal;
    animation-timing-function: linear;
}
.hosted-fields-valid-state {
    position: relative;
    border: 0;
    background: 0;
    overflow: visible; /* force the native hosted-field property */
}
.hosted-fields-valid-state:after {
    content: "✓"; /* not working font awesome '\f26e' */
    z-index: 1;
    display: block;
    position: absolute;
    top: -25px;
    width: 25px;
    height: 25px;
    /*font-family: "Font Awesome 5 Solid";*/
    color: #29b495;
}
#card-container.hosted-fields-valid-state:after {
    left: 100px;
}
#expiry-container.hosted-fields-valid-state:after {
    left: 60px;
}
#cryptogram-container.hosted-fields-valid-state:after {
    left: 110px;
}
.hosted-fields-disabled-state {
    background: 0;
    border: 0;
    overflow: visible; /* force the native hosted-field property */
}
.hosted-fields-disabled-state:after {
    content: "";
    z-index: 1;
    display: block;
    position: absolute;
    top: -14px;
    left: -2px;
    width: 70px;
    height: 1px;
    border-top: 1px solid white;
}

@keyframes wriggle {
    from { transform: translateY(-3px); }
    to { transform: translateY(0); }
}

/* hackh Chrome autofill style */
input:-webkit-autofill, textarea:-webkit-autofill, select:-webkit-autofill {
    background: inherit;
    color: inherit;
}

body #info {
    position: absolute;
    top: 380px;
    left: 51.5%;
	width: 500px;
    box-sizing: border-box;
    margin: 40px 0 42px -250px;
    padding: 7px 14px;
    border-left: 2px solid #f59d00;
	line-height: 125%;
    text-align: justify;
    font-size: 11px;
    color: #fff;
}
#info p+p,
#info p+ul,
#info ul+p {
    margin-top: .5em;
}
strong {
    font-weight: 600;
}
            
          
!
            
              
/**
 * The purpose is to reproduce the Material Design's floating labels effect.
 *
 * The input fields being hosted on an external page, outside the DOM, it is inconceivable to consider animating their placeholder attributes.
 * So you have to fake it, making labels look like placeholders.
 *
 *
 * We first need to detect the focus into the hosted-fields.
 * The difficulty lies in the fact that these fields are hosted in iframes, outside our DOM, therefore we can only base ourselves on 3 events:
 *     - When user is clicking or pressing a key
 *     - When focus is lost on the DOM
 *     - If the hosted-fields container's classes have changed, indicating that the focus is on one of them
 * Then, we could trigger an animation on the labels and apply a specific style on the containers
 */

// Detects the use of any key, and in particular the use of the TAB key to focus on a hosted-field
document.onkeydown = function(){
    formDynamics();
};

// Detects the use of the mouse
document.onclick = function(){
    formDynamics();
};

// Imitates Material Design input fields placeholder's animations
function formDynamics() {
    var paymentForm =       document.getElementById("payment-form");
    var cardField =         document.getElementById("card-container");
    var cardLabel =         document.getElementById("card-label");
    var expiryField =       document.getElementById("expiry-container");
    var expiryLabel =       document.getElementById("expiry-label");
    var cryptogramField =   document.getElementById("cryptogram-container");
    var cryptogramLabel =   document.getElementById("cryptogram-label");

    // Hold on 100ms before checking for the presence of a "focus" class on the hosted-fields containers
    setTimeout(function() {
        // If the focus is confirmed on any hosted-field...
        if( cardField.className.indexOf("hosted-fields-focus-state") > -1
            ||  expiryField.className.indexOf("hosted-fields-focus-state") > -1
            ||  cryptogramField.className.indexOf("hosted-fields-focus-state") > -1
        ) {
            // ...Then add classes to trigger animations
            paymentForm.classList.add("up");
            cardLabel.classList.add("up");
            expiryLabel.classList.add("up");
            cryptogramLabel.classList.add("up");
        }
    }, 100);
}

/**
 * Simulatse the <label> "for" attribute when clicking on the fake labels
 *
 * @param id
 */
function focusIframe(id)
{
    var iframe = document.getElementById(id);
    iframe.contentWindow.focus();
    return true;
}

// display a dialogbox with information about CVV
function cryptogramAlert()
{
    alert('CB | VISA | MasterCard : the last 3 digits on the back of the card.\n\nAmerican Express : the 4 digits on the front of the card.\n\nBancontact and some Maestro cards have no cryptogram.');
}

function isEmptyHostedField(elem)
{
    if(elem.className.indexOf("hosted-fields-empty-state") > -1) {
        return true;
    }
    return false;
}

// give a class to the form when a card type is detected
function formCustom(cardType)
{
    var card = document.getElementById("card");
    card.className = cardType;
}

/**
 * Prepare the style to be used in the hosted-fields API call
 */

var style = {
    "input": {
        "background-color": "transparent",
        "font-size": "1.2em",
        "letter-spacing": "3px",
        "color": "#666"
    },
    ":valid": {
        "font-family": "consolas, system, sans-serif",
        "font-size": "1.5em",
        "color": "#29b495",
    }
};

/**
 * Hosted-fields API Cal
 */
var hfields = dalenys.hostedFields({
    key: {
        id: "970c4f7c-c62e-40d2-8084-b61781326c81",
        value: "lr3*{F/4?nLnTq.t"
    },
    fields: {
        'card': {
            id: 'card-container',
            style: style,
            onBlur: function(event) {
                console.log(event);
            },
            onInput: function(event) {
                console.log(event);
                if(event.cardType) {
                    formCustom(event['cardType']);
                }
            }
        },
        'expiry': {
            id: 'expiry-container',
            //placeholder: 'MM/YY',
            style: style
        },
        'cryptogram': {
            id: 'cryptogram-container',
            placeholder: '',
            style: style,
            onInput: function(event) {
                console.log(event);
            }
        }
    },
    locale: 'fr'
});

/**
 * Generates and collects a token while submitting the payment form
 *
 * @returns {boolean}
 */
function tokenizeHandler() {
    hfields.createToken(function(result) {
        console.log(result);
        if (result.execCode == '0000') {
            // Add token to payment form request
            document.getElementById('hf-token').value = result.hfToken;
            prompt("Generated token:", result.hfToken); // Displays the generated token for this demo
            // Form submission is disabled for this demo, think to uncomment the line below to make it works in your integration
            // document.dalenysForm.submit();
        } else {
            alert(result.execCode+': '+result.message);
        }
    });
    return false;
}

hfields.load();
            
          
!
999px
🕑 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.
Loading ..................

Console