4
votes

I'm implementing stripe payment in a web application using nodejs and reactjs.

If I test my payment on localhostm everything works! But if I push same code on http://beta.mywebsite.com I got this error server side. Client side everithing seems work..

Message:

You did not provide an API key, though you did set your Authorization header to "null". Using Bearer auth, your Authorization header should look something like 'Authorization: Bearer YOUR_SECRET_KEY'. See https://stripe.com/docs/api#authentication for details, or we can help at https://support.stripe.com/


Server side

const stripeClient = stripe('sk_test*************')
stripeClient.setApiVersion('2017-06-05')

const Stripe = {
  pay (payload) {
    return new Promise((resolve, reject) => {
      if (!payload || !isObject(payload)) throw new BadCreateRequest('Stripe: pay. Unexpected parameters.')

      let { user, total, token, cartId } = payload

      stripeClient.customers.create({
        email: token.email,
        source: token.id
      })
      .then(customer => {
        return stripeClient.charges.create({
          amount: total * 100,
          currency: 'eur',
          customer: customer.id,
          description: `Paid from ${user.email} (${user.id})`
        })
      })
      .then(charge => {
        if (!charge) throw new BadCreateRequest()

        let closeCartData = {
          balanceTransaction: charge.balance_transaction,
          stripeId: charge.id,
          refundUrl: charge.refunds.url
        }

        return Cart.setAsPayed(cartId, closeCartData)
      })
      .then(closedCart => resolve(closedCart))
      .catch(reject)
    })
  }
}
3
Why don't you try setting the api key? - Hosar
I have tried to write stripeClient.setApiKey('sk_test*************') but not work - Carmelo Catalfamo

3 Answers

1
votes

Please use const stripeClient = require('stripe')('sk_test*************')

0
votes

I had a similar issue with the same error message.

What I tried to do is to use the key from process.env variables, but it didn't work.

const Stripe = require('stripe');
const stripe = Stripe('sk_test_...');

This worked for me.

-2
votes

Also had the same problem and I just changed my browser and it worked!!! (Do not use google chrome or brave, use firefox or some other browser)