skip to Main Content

I have RN App that use stripe SDK for payment, after long time testing have no problem. But yesterday I got the error when generating token from stripe SDK. I will provide bellow the code and the error message. If someone here have the same problem and know the solution I appreciate so much if you want to help me.

Source code to generate token


//useStripe hooks from stripe SDK
const { createToken } = useStripe();

// function to generate Token 
const generateToken = async () => {
        const token = await createToken({
            type: 'Card',
            currency: 'brl',
            address: {
                city: payload.city,
                postalCode: payload.cep,
                state: payload.state,
            },
            name: payload.nameOnCard
        })
        return token
    }

// generate the token
const token = await generateToken();

And here the error message when execute generateToken()

 {"error": {"code": "Failed", "declineCode": null, "localizedMessage": "There was an unexpected error -- try again in a few seconds", "message": "You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g. 'Authorization: Bearer YOUR_SECRET_KEY'). See https://stripe.com/docs/api#authentication for details, or we can help at https://support.stripe.com/.", "stripeErrorCode": "", "type": "invalid_request_error"}}

If anyone here maybe know this problem caused of stipe membership or something else, please let me know here. Thank you in advance

2

Answers


  1. Chosen as BEST ANSWER

    After checking the stripe dashboard by the account holder there's no change about. Then I try to figure out what is the problem. And what I found is about the StripeProvider component is wrong, and for the previous version that work is because app cache in react-native, and after I run react-native run ios --reset-cache the error appears. So after I fixing the StripeProvider component the app working again.

    Thanks for your help everyone.


  2. The error message says that the API key is missing in the request, so I’d suggest you to check if a valid publishableKey is provided when you initialized the Stripe SDK.

    You can specify a publishableKey via StripeProvider or initStripe.

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