Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe Elements - change in layout of 'card-element'

I am looking for a way to customise the layout of 'card number' 'expiry date' and 'CCV' fields when using Stripe Elements and injecting these fields through card.mount('#card-element'); as described in the first example of this page https://stripe.com/docs/stripe-js

It puts all the card fields in one row, I want to change that layout and put them in different rows.

Any ideas?

Thanks in advance

like image 342
Toseef Zafar Avatar asked Jun 21 '18 16:06

Toseef Zafar


People also ask

How do you customize your stripe elements?

In addition to themes , variables and rules , we have provided additional appearance configuration options to style Elements. You can customize these by adding them to the appearance object: const appearance = { labels: 'floating', // other configurations such as `theme`, `variables` and `rules`... }

What is card element in stripe?

Stripe Elements is a set of prebuilt UI components for building your web checkout flow. It's available as a feature of Stripe. js, our foundational JavaScript library for building payment flows. Stripe. js tokenizes sensitive payment details within an Element without ever having them touch your server.

Does stripe save card information?

Stripe works with card networks and automatically attempts to update saved card details whenever a customer receives a new card (for example, replacing an expired card or one that was reported lost or stolen).

Is stripe elements an iframe?

The element is an iframe, which is another window, which has its own window object and document object. The parent page cannot access these objects, unless the iframe is in the same origin.


1 Answers

You can do this by creating a separate div for each card input (number, expiry, CVC), which you can layout however you like:

<div id="example3-card-number"></div>
<div id="example3-card-expiry"></div>
<div id="example3-card-cvc"></div>

Then tell Stripe Elements about each one:

var cardNumber = elements.create('cardNumber');
cardNumber.mount('#example3-card-number');

var cardExpiry = elements.create('cardExpiry');
cardExpiry.mount('#example3-card-expiry');

var cardCvc = elements.create('cardCvc');
cardCvc.mount('#example3-card-cvc');

Ref: https://stripe.dev/elements-examples/ (Example 3)

like image 133
cometfish Avatar answered Nov 27 '22 15:11

cometfish