#supriya
1 messages · Page 1 of 1 (latest)
Hello! Pulling this info into the thread:
iin my system its not supporting its showing Uncaught TypeError: Cannot read properties of null (reading 'addEventListener')
is there any way to do modify the code
Can you share the code that's throwing that error?
ya sure
const form = document.getElementById('payment-form');
const submitBtn = document.getElementById('submit');
const handleError = (error) => {
const messageContainer = document.querySelector('#error-message');
messageContainer.textContent = error.message;
submitBtn.disabled = false;
}
form.addEventListener('submit', async (event) => {
// We don't want to let default form submission happen here,
// which would refresh the page.
event.preventDefault();
// Prevent multiple form submissions
if (submitBtn.disabled) {
return;
}
// Disable form submission while loading
submitBtn.disabled = true;
// Trigger form validation and wallet collection
const { error: submitError } = await elements.submit();
if (submitError) {
handleError(submitError);
return;
}
// Create the PaymentMethod using the details collected by the Payment Element
const { error, paymentMethod } = await stripe.createPaymentMethod({
elements,
params: {
billing_details: {
name: 'Jenny Rosen',
}
}
});
if (error) {
// This point is only reached if there's an immediate error when
// creating the PaymentMethod. Show the error to your customer (for example, payment details incomplete)
handleError(error);
return;
}
// Now that you have a PaymentMethod, you can use it in the following steps to render a confirmation page or run additional validations on the server
});
Sounds like this line isn't working: const form = document.getElementById('payment-form');
If you log the form variable immediately after setting it what do you see?
Right, because form is null.
which javascript this one support
What do you mean?
oKay
actually i am thinking any files we need update ?
let me check form i am getting are not
okay
yes you said correct form getting null
do you have any idea why i am getting null
Probably because there's no form on the page with the ID attribute value you specified.
I'm not sure what you mean. Are you familiar with how HTML attributes and getElementById in JavaScript work?
I don't understand what you're asking me.
i am checking why form getting null
I recommend you work with an experienced web developer to help you build your Stripe integration. I do not recommend trying to get an integration working on your own without the required development experience.
Alternatively you could use our no-code solutions: https://stripe.com/docs/no-code
previously i worked so many code development by using server side code i did not get any issue
Right, but that's why I said web developer.
Actualy i am not femilar with javascript script beacause i am struggling
i thought you are also developper right
you have some idea to give solution
but i did get any proper solution from you
Yes, but I can only help with Stripe. What you're asking about is basic web development, which is outside the scope of what we can help with here.
okay , I have one more question is ther any other way to createthepayment method id
There are many different ways to create a Payment Method with Stripe, yes.
Why do you want to create a Payment Method ID? What are you trying to build?
previously we are using our custom payment page and in server side now we are trying to change the payment element
doing the payment through stripe side
my idea was if i am able crete the payment method id in ui side and pss that id to server side after that i have alredy existing server side code
i will use that
That's not really how it works. There's more to payments now than just getting a Payment Method ID and attempting to charge it.
If you want to use the Payment Element on your page you can follow this guide: https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements
But I recommend you use Stripe Checkout instead, which is easier to use and doesn't require JavaScript: https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=checkout
Ya i tried this one but call back url not working for me