Skip to content
This repository has been archived by the owner on May 23, 2021. It is now read-only.

Uncaught (in promise) TypeError: Cannot read property 'json' of undefined #60

Open
DDholiyan opened this issue Dec 24, 2020 · 4 comments

Comments

@DDholiyan
Copy link

Bug report

script.js:117 Uncaught (in promise) TypeError: Cannot read property 'json' of undefined

Describe the bug

Below line gives above error

return result.json();

@cjavilla-stripe
Copy link
Contributor

Hey @DDholiyan This is almost always because of the .env file not being correctly configured. Can you share the output of the server log when you get this error?

@DDholiyan
Copy link
Author

This is on most of the response. See below declined response.
{
"error": {
"code": "card_declined",
"decline_code": "live_mode_test_card",
"doc_url": "https://stripe.com/docs/error-codes/card-declined",
"message": "Your card was declined. Your request was in live mode, but used a known test card.",
"type": "card_error"
}
}

Console:- Uncaught (in promise) TypeError: Cannot read property 'json' of undefined
at script.js line no 118

stripe
.createPaymentMethod("card", card)
.then(function(result) {
if (result.error) {
showError(result.error.message);
} else {
orderData.paymentMethodId = result.paymentMethod.id;

        return fetch("pay.php", {
            method: "POST",
            headers: {
                "Content-Type": "application/json"
            },
            body: JSON.stringify(orderData)
        });
    }
})
.then(function(result) {
    return result.json(); // Line no 118
})

@cjavilla-stripe
Copy link
Contributor

That means the sample was configured with live mode API keys to take real payments, but a test card was used. Test cards only work with test mode API keys. Try using your test mode API keys.

@DDholiyan
Copy link
Author

I know what is this mean. I just want to tell you that this error comes every time we got response from stripe.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@DDholiyan @cjavilla-stripe and others