#mehroo

1 messages · Page 1 of 1 (latest)

wheat moatBOT
grave frost
#

Hi there!

#

But based on the error message I'm guessing you forgot to set the apiVersion in your request.

craggy tide
#

@grave frost can I share my code here?

#

const functions = require("firebase-functions");
const stripe = require('stripe')("my-secret-key", {
apiVersion: '2020-08-27',
});

grave frost
#

Sure, feel free to share your code that generated this error.

craggy tide
#

exports.stripePaymentIntentRequest = functions.https.onRequest(async (req, res) => {
try {

    let customerId;

    //Gets the customer who's email id matches the one sent by the client
    const customerList = await stripe.customers.list({
        email: req.body.email,
        limit: 1
    });

    //Checks the if the customer exists, if not creates a new customer
    if (customerList.data.length !== 0) {
        customerId = customerList.data[0].id;
    }
    else {
        const customer = await stripe.customers.create({
            email: req.body.email
        });
        customerId = customer.data.id;
    }

    //Creates a temporary secret key linked with the customer
 const ephemeralKey = await stripe.ephemeralKeys.create(
            { customer: customerId },
            { apiVersion: '2020-08-27' }
        );

    //Creates a new payment intent with amount passed in from the client
    const paymentIntent = await stripe.paymentIntents.create({
        amount: parseInt(req.body.amount),
        currency: 'usd',
        customer: customerId,

    })
    res.status(200).send({
        paymentIntent: paymentIntent.client_secret,
        ephemeralKey: ephemeralKey.secret,
        customer: customerId,
        success: true,
    })

} catch (error) {
    functions.logger.info(error.message, { structuredData: true });

    console.log(error);
    res.status(404).send({ success: false, error: error.message })
}

});

#

here is my code, I'm using firebase functions

grave frost
#

Which part is generating the error? I'm guessing this function?

const ephemeralKey = await stripe.ephemeralKeys.create(
    { customer: customerId },
    { apiVersion: '2020-08-27' }
);
craggy tide
#

yeah I think this part is generating error, I think It is not creating ephemeralKey

grave frost
#

And can you share the request ID with the error?

craggy tide
#

Actually I checked my logs in my stripe account, there is not logs of today.

grave frost
craggy tide
#

yeah sure

#

acct_1LrcpVHhVoIRRoFs

#

here you are

neon turret
#

Hi there 👋 I'm jumping in as my teammate needed to step away, please bear with me a moment while I pull up your account.

craggy tide
#

Hi @neon turret I really appreciate your help! I can wait ofcourse

neon turret
#

I'm not readily finding any request logs that align with the error message that you shared. I do see some failed requests that returned an error when trying to create a Payment Intent. Could you try adding some logging between each of the requests in your code to determine exactly which one is surfacing that error?

craggy tide
#

I shared my code above In that code: before creating an intent request, I create ephemeralKey. I thought this code is giving error: const ephemeralKey = await stripe.ephemeralKeys.create(
{ customer: customerId },
{ apiVersion: '2020-08-27' }
);

neon turret
#

I just noticed the timestamp on that request is from several days ago though, and am not seeing any recent (made within the last couple of days) requests logged for your account. Have you tried testing this flow recently?

craggy tide
#

I tried this half hour ago

neon turret
#

Ah, I see, I switched to seeing all requests (rather than just POSTS) and I'm seeing evidence of your GET requests (listing customers).

#

Nothing is readily jumping out at me as being wrong with your code, and when I mimc your request structure in my node shell, I'm not encountering an error.

neon turret
#

Have you confirmed that customerId is getting populated the way you expect?