#nathan-react
1 messages · Page 1 of 1 (latest)
Hello Nathan, I was wondering if there are any error messages within your inspector logs?
Is there a specific guide you are following for your implementation?
Are you defining the width within style?
I was following this.
https://www.youtube.com/watch?v=IhvtIbfDZJI&list=PLy1nL-pvL2M6HFApWUDSGA4Y7btyKx7cE&index=2
Learn the front end steps for accepting a payment with a card from your customers using a custom form in a React application. You'll learn how to use the CardElement component and how to use the confirmCardPayment method from Stripe.js to securely confirm a PaymentIntent client-side. This method handles 3D Secure and Secure Customer Authenticati...
This is the old guide with reference to Card Element, the new recommended guide is Payment Element, which allows multiple payment methods to be handled automatically, please find the guide: https://stripe.com/docs/payments/accept-a-payment?platform=react-native&ui=payment-sheet
I was wondering if you are wrapping the Card Element in anything else?
import React from 'react';
import {withRouter} from 'react-router-dom';
import {CardElement, useStripe, useElements} from '@stripe/react-stripe-js';
const Card = () => {
const handleSubmit = async (e) => {
e.preventDefault();
}
return (
<>
<h1>Card</h1>
<form id="payment-form" onSubmit={handleSubmit}>
<label htmlFor="card-element">Card</label>
<CardElement id="card-element" />
<button>Pay</button>
</form>
</>
)
}
export default withRouter(Card);
I wrap it in a form element
Just like the tutorial
Hi, I'm taking over this thread. This looks like a CSS issue to me. Do you have a link to your page so I can have a look? Or could you share the CSS applied to this form?
Thanks! Could you try to increase the width of your main element to see what happens? For example:
main {
width: 960px;
}
Nothing changes, the card is still collapsed
Is the width of the form larger now? Or its exactly the same as before?
Exactly the same
OK. Could you completely remove the CSS then, so we can confirm that this issue is coming from the CSS?
It becomes something like this
Great, so here the card element has the full width. So the issue does come from the CSS!
Is the CSS file the only one you are using on this page (no bootstrap or something similar)?
Yes, only CSS
Could you share your App.js file?
Thanks, this file looks correct.
Earlier when I asked you to change the width of the CSS file, it should have changed the width of the card element of you page. Since it didn't, I'm thinking you might have edited the wrong CSS file.
So can you add back your css, and try again to change the width? Make sure you are editing the correct file.
Ok, let me try it again
I add the width attribute in #payment-form and the box turns normal.
But I want to make it flexible
You can set the width of the #payment-form directly in the CSS, but you need to make sure you are editing the correct CSS file.
I think that's the correct CSS file since that's the only css file in the src folder.
What do you mean exactly by "But I want to make it flexible"?
Like the size of the form will change to fit the size of the browser
In this case a simple solution would be to do something like this:
main {
max-width: 960px;
width: 100%;
}
How about in #payment-form?
Making the main element responsive (like in my example above) should make the #payment-form also responsive, assuming there's no hardcoded width set on the #payment-form.
So don't set any fixed width in #payment-form?
Yes exactly
The box collapsed again
hard to say much without seeing your exact CSS file! happy to help but this is not completely Stripe-related really, it's just the same as styling any other component of the web page you're building.
I just added the attributes above in main and remove any fixed width in #payment-form
I'm using that code + CSS and it seems fine
Can you send me the app.js and card.js you use?
they're identical to the ones you shared in this thread(just I uncommented import './App.css'; from your App.js).
How about the index.js?