I'm building a simple website that will process payments with Stripe. I'm using Bootstrap for my styling. When I use Stripe Elements to insert the payment fields, they aren't styled with Bootstrap. How can I apply Bootstrap's styling to the Elements payment fields?
相关问题
- How to add a “active” class to a carousel first el
- Full Clickable Accordion in Bootstrap
- How to add Bootstrap 4 without Tether?
- Laravel overriding bootstrap template
- How to add Labels to Bootstrap dialog footer
相关文章
- Make Bootstrap tab Active on the bases of URL link
- Rails: Twitter Bootstrap Buttons when visited get
- Reduce spacing between rows
- How do use bootstrap tooltips with React?
- Need to design 8 boxes in two rows
- Trigger a Bootstrap .collapse('toggle') vi
- How to override Bootstrap mixin without modifying
- How can I ensure columns wrap equally in Twitter B
Adding another Answer since I felt the simplest one on here was slightly incomplete. Added the error display and the JavaScript used to send the token to the back-end in case you want to do that.
This HTML (which is right from their default docs with Bootstrap 4 elements added)
And This is the JavaScript (again right from their default docs but I use jQuery here but you dont have to)
This is all that was required for us using
After digging around the docs a bit more, I found that https://stripe.com/docs/stripe.js#the-element-container says "You should style the container you mount an Element to as if it were an on your page."
By adding Bootstrap's
form-control
class to the<div>
I'm mounting the Element in, the field looks almost like any other Bootstrap-styled input field:For some reason, the height of the field doesn't quite match, but through trial and error, I got it with:
Alright, so I had to figure this out, because I was using Stripe.js v2, and the security vulnerability was explained to me by Stripe tech support, so I felt obligated to switch to Stripe.js v3 "Elements". What they said was that any javascript on the same page as your credit card form elements could obtain the values of the sensitive credit card data. I suppose this could happen if a person was pulling in external scripts ... and I suppose it must have happened, or they wouldn't care about it. Anyway, this is how I got my Stripe.js v3 elements working with Bootstrap 4 input groups. It's a full working example, you'd just need to change out the public key.
Default jQuery Based Example
I tested only in Firefox, Chrome, and Chrome on Android. Seems to work fine. Let me know if you experience any issues.
Optional Vue.js Based Example
This Vue.js example could benefit from some work, but may help get you started.