#supriya

1 messages · Page 1 of 1 (latest)

worldly hamletBOT
robust steppe
#

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?

idle atlas
#

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

});

robust steppe
#

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?

idle atlas
#

form.addEventListener('submit', async (event)

#

this one not supporting in my system

robust steppe
#

Right, because form is null.

idle atlas
#

which javascript this one support

robust steppe
#

What do you mean?

idle atlas
idle atlas
#

let me check form i am getting are not

robust steppe
#

Not sure what that means, sorry.

#

Can you clarify?

idle atlas
#

okay

#

yes you said correct form getting null

#

do you have any idea why i am getting null

robust steppe
#

Probably because there's no form on the page with the ID attribute value you specified.

idle atlas
#

okay

#

help me on do you any idea regarding that

#

is it work on partial view page

robust steppe
#

I'm not sure what you mean. Are you familiar with how HTML attributes and getElementById in JavaScript work?

idle atlas
#

ya

#

i am checking that only parallely i am asking you also

robust steppe
#

I don't understand what you're asking me.

idle atlas
#

i am checking why form getting null

robust steppe
#

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.

idle atlas
#

previously i worked so many code development by using server side code i did not get any issue

robust steppe
#

Right, but that's why I said web developer.

idle atlas
#

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

robust steppe
#

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.

idle atlas
#

okay , I have one more question is ther any other way to createthepayment method id

robust steppe
#

There are many different ways to create a Payment Method with Stripe, yes.

idle atlas
#

Can you send me links

#

i can try

robust steppe
#

Why do you want to create a Payment Method ID? What are you trying to build?

idle atlas
#

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

robust steppe
#

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.

idle atlas