skip to Main Content

I’m trying to test metered billing via an AWS Lambda function written in NodeJS. I get the following error message from Stripe:

Error processing metered billing event: StripeAuthenticationError: Livemode of key does not match mode of account (hint: legacy testmode keys are not supported. Please use a sandbox.)

I’m absolutely baffled as to why I’m getting this error because I’m using my test mode key for this. I’ve also been testing stuff via Stripe all day and everything has been working fine.

I thought for sure it had to do with the livemode: BOOLEAN attribute that the Meter Event Object has, so I explicitly set that as false for testing purposes:

        // Create the metered billing event with the v2 API (Custom Event Billing)
        const meterEvent = await stripe.v2.billing.meterEvents.create({
            event_name: 'product_creation', // You can use your custom event name
            payload: {
                value: 1,  // Increment by 1 product creation
                stripe_customer_id: stripeCustomerID  // Stripe customer ID
            },
            livemode: false  // IMPORTANT!!! --> make sure to set this to TRUE in the live mode.
            // this parameter must overtly be specified for TEST vs LIVE mode, for the meter event object.
        });

Nope, still getting this error.

Any ideas as why this may be happening and what the fix could be?

Thanks!…

2

Answers


  1. Chosen as BEST ANSWER

    I was able to miraculously solve this problem using the "try a bunch of random stuff" approach. The fix turned out to be this... even though the Stripe documentation said:

    const meterEvent = await stripe.v2.billing.meterEvents.create({
    

    I ended up trying it like this:

    const meterEvent = await stripe.billing.meterEvents.create({
    

    and THAT was the fix.


  2. Stripe has two types of testing environments – legacy test mode and Sandboxes.

    v2 endpoints only support in Sandboxes whereas v1 endpoints support both legacy test mode and Sandboxes.

    To work on v2 endpoints, you should ensure the Sandbox is being set up and use its corresponding API keys.

    Here are the differences between v1 and v2 namespaces: https://docs.stripe.com/api-v2-overview#key-differences-between-the-v1-and-v2-namespace

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search