• Resolved user9876789

    (@user9876789)


    When in test mode on Woopayments and going into My Account > Add Payment method and adding the info of card number ‘0000 0000 0000 0000’, any valid expiry, any security code, and any country – you get the error “Cannot destructure property ‘id’ of ‘undefined’ as it is undefined.”

    Can this be made more user friendly?

    From researching the error comes from in plugins/woocommerce-payments/dist/checkout.js, submitting the add-payment-method form does this (de-minified):

    const result = await stripe.createPaymentMethod({ elements, params });
    
    if (result.error) {
        // Save Stripe's error details as hidden inputs on the form
        appendErrorInputs(form, result.error);
    } else {
        appendPaymentMethodInput(form, result.paymentMethod.id);
    }
    
    // ...but then carries on regardless of the error
    await afterCreate(result.paymentMethod, form, api);   // paymentMethod is undefined
    

    On the add-payment-method page, afterCreate is this function:

    const wt = ({ id }, form, api) => api.setupIntent(id, ...)
    

    When Stripe rejects the card, result.paymentMethod is undefined. Destructuring { id } from it throws a TypeError. The catch block then shows that raw JavaScript message (e.message) to the user.

    At checkout, the same code works because the step after the error does nothing. The form submits, and the server turns the hidden error fields into a proper message. The add-payment-method page runs the setup intent step in the browser, so it crashes first. Stripe’s real, friendly message is sitting in a hidden #wcpay-payment-method-error-message input that nothing reads.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @user9876789!

    Thank you for the detailed report and for tracing the behavior through the WooPayments code.

    I’ve reproduced the issue using the test card 0000 0000 0000 0000 and reported it to the team that maintains WooPayments. We’ve specifically raised the issue with the My Account → Add Payment Method flow so that, when Stripe returns a payment-method error, the page can surface the appropriate user-friendly error message instead of exposing the raw JavaScript error.

    Your investigation into the result.paymentMethod being undefined and the subsequent destructuring error was particularly helpful in isolating why this behaves differently from the checkout flow.

    Thank you for taking the time to dig into the source and provide those details. This should help the team investigate the issue more efficiently.
    ::

    Thread Starter user9876789

    (@user9876789)

    Thank you

    shahzeen(woo-hc)

    (@shahzeenfarooq)

    Hi @user9876789!

    You’re very welcome! If you face any issues in the future, we’re always here to help.

    Please feel free to create a new ticket whenever you need assistance.

    Thank you, and have a great day!

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.