Add a Billing API

Link to chapter - https://serverless-stack.com/chapters/add-a-billing-api.html

So… if I understand the instructions correctly, we’re supposed to run sudo npm install --save stripe in serverless-stack-2-api then create a billing.js inside serverless-stack-2-api?

Because I ran sudo npm install --save stripe in both serverless-stack-2-api as well as the folder before it (the second run understandably failing due to lacking a package.json), but I couldn’t find an existing billing.js

Yup this chapter deals with the backend API.

Yes, you need the package for your backend API

1 Like

Hi, found an issue with the stripe env variable. Stripe shows that API_KEY was missing when using

const stripe = stripePackage(process.env.stripeSecretKey);

However, using the same name as in .env variable, it worked:

const stripe = stripePackage(process.env.STRIPE_SECRET_KEY);

Maybe is an issue on my system, but I think this should be reviewed and chnaged if procedes.

Regards!

Hmm that’s weird because in the next chapter (https://serverless-stack.com/chapters/load-secrets-from-env.html) we do this:

environment:
    tableName: notes
    stripeSecretKey: ${env:STRIPE_SECRET_KEY}

And that sets it as stripeSecretKey for your code to use.

Yeah, the thing is I have added that to the environment but it didn´t work. I don’t know the reason, although the capital letters version works. Just for anyone having a the same issue.

1 Like

Can the Stripe option be “optional?”

Meaning is it possible to deploy the application as written without the billing portion?

Yeah totally. You can ignore the Stripe call here and just pretend that the call was successful.