Are you copying this from the PDF? Cos the online version seems fine to me.
I ran into the trailing spaces error as well. It is in line 6-7 of the billing-lib.js code block. If you remove the extra space at the end of line 6 and all of blank line 7 it runs without error. I ran into it earlier with the response-lib.js file as well and had to remove blank lines 4 & 8 with the trailing space at the end of each prior line. It’s weird because I can see that there is the same empty line with a trailing space on lines 4-5 of dynamodb-lib.js but it’s not throwing an error. For what it’s worth, I used the copy button built into the code blocks on the website (plus you can see it just by looking at the code, unless Chrome is doing something funky with the formatting when rendering the page.) Other info: Windows 10 pro, VSC for editing/file creation. Or is this an issue with whole CR/LF discrepancy between Windows and MacOS?
HI, I’m getting a Serverless error “The file you provided does not exist.”
It seems to be having trouble finding the .env file where STRIPE_SECRET_KEY is stored per the tutorial. The .env file is there. I can see it when I run ls -a and it exists in the root directory of this project. I am using a relatively new Mac with Catalina installed. I’m wondering if the DOTENV plugin is having trouble accessing hidden files with Catalina. I have given terminal full disk access but it still says the file doesn’t exist.
I’m not sure how to proceed. I ran SLS_DEBUG=* serverless invoke local --function billing --path mocks/billing-event.json
and got the following output:
Serverless Error ---------------------------------------
ServerlessError: The file you provided does not exist.
at AwsInvokeLocal.validateFile (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:49:13)
at /usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:74:16
at /usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:66:14
From previous event:
at AwsInvokeLocal.extendedValidate (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:61:28)
From previous event:
at Object.before:invoke:local:loadEnvVars [as hook] (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:32:12)
at /usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:490:55
From previous event:
at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:490:22)
at /usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:525:24
From previous event:
at PluginManager.run (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:525:8)
at /usr/local/lib/node_modules/serverless/lib/Serverless.js:133:33
at processImmediate (internal/timers.js:445:21)
at process.topLevelDomainCallback (domain.js:135:15)
From previous event:
at Serverless.run (/usr/local/lib/node_modules/serverless/lib/Serverless.js:120:74)
at /usr/local/lib/node_modules/serverless/bin/serverless.js:75:30
at /usr/local/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:111:16
at /Users/aaronpennington/Development/notes-app-api/node_modules/graceful-fs/graceful-fs.js:57:14
at /usr/local/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:45:10
at FSReqCallback.oncomplete (fs.js:153:23)
From previous event:
at /usr/local/lib/node_modules/serverless/bin/serverless.js:75:8
at processImmediate (internal/timers.js:445:21)
at process.topLevelDomainCallback (domain.js:135:15)
From previous event:
at Object.<anonymous> (/usr/local/lib/node_modules/serverless/bin/serverless.js:64:4)
at Module._compile (internal/modules/cjs/loader.js:1139:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1159:10)
at Module.load (internal/modules/cjs/loader.js:988:32)
at Function.Module._load (internal/modules/cjs/loader.js:896:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information ---------------------------
Operating System: darwin
Node Version: 13.5.0
Framework Version: 1.60.5
Plugin Version: 3.2.7
SDK Version: 2.2.1
Components Core Version: 1.1.2
Components CLI Version: 1.4.0
Can you point me to the exact snippet that is giving you issues?
Hmm that is interesting. Did you figure out this issue?
Here is a screenshot of what I am seeing in chrome for the code block of billing-lib in the “Add a billing API” chapter. I selected the end of the 6th line and into the next line so that you can see there is a space after the semi-colon as well as another one on the next line.
Once the selected portion was removed it wasn’t an issue.
Here is the screenshot from response-lib code block in the “Add a Create Note API” chapter, which also threw the error–again the spaces are selected so that they are highlighted in grey at the end of lines 3-4 & 7-8.
strangely, I noticed that there were also trailing spaces in the dynamodb-lib.js file but it didn’t throw an error for me.
I did! I named my mock billing-events.json instead of billing-event.json.
That’s super weird. Because we don’t have that in the source.
Btw, if you use the Copy button, it works fine right?
No, it still throws an error even if I use the Copy button (that’s how I’ve been copying all of the code throughout the tutorial.) I also tried it in firefox to see if it was chrome and while the trailing spaces don’t show when you select them on the screen like they do in chrome, they still are there when I copy and paste it into Visual Studio Code. Regardless of whether I manually select or use the copy button.
Are you on Windows? I tried it across browsers on macOS and it seems fine.
I am getting a Invalid token id: tok_visa
error when running the command serverless invoke local --function billing --path mocks/billing-event.json
. Is there a particular version of Stripe that i need to use?
{
"statusCode": 500,
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": true
},
"body": "{\"message\":\"Invalid token id: tok_visa\"}"
}
never mind i got it fixed. i was using the live stripe secret key in .env file.
Tip for Indians here.
If you are from India trying out the Stripe API or from any other country that require a customer name and address of someone from outside India. Try the following in billing.js
file:
await stripe.charges.create({
source,
amount,
description,
currency: "usd",
shipping: {
name: "Jenny Rosen",
address: {
line1: "510 Townsend St",
postal_code: "98140",
city: "San Francisco",
state: "CA",
country: "US",
},
},
});
You can give any shipping details. But it should be something related to US/UK etc etc.
For more information check out: https://stripe.com/docs/india-exports
@jayair Please update the docs with this case. I spent considerable amount of time trying to debug the problem.
Hope it helps everyone.
Thanks for this, what was the error you were running into?
The error goes something like this:
Fatal error: Uncaught (Status 400) (Request req_ZyqUtykjUcOqrU) As per Indian regulations, export transactions require a customer name and address. More info here: https://stripe.com/docs/india-exports thrown in /usr/code/.../...path_to_billing.js
Many Indian debit cards and credit cards don’t work for international transactions due to an extra security OTP layer on the transactions. Stripe probably would have kept this in mind and provided a different functionality for Indian customers.
Coming to the problem, one can give any name and address in the shipping field as mentioned in my last comment. It would be OK for anyone to enter the details that I provided. Its a fake profile (Jenny Rosen) given by Stripe.
Got it. Thanks for the additional details.
Added a note to the chapter — https://github.com/AnomalyInnovations/serverless-stack-com/commit/dd986c6310a3435249e789671c4a4ac127d9f22e.
Hi guys I am getting this error when I run the test command
{
"statusCode": 500,
"body": "{\"error\":\"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/.\"}"
}
Do you have the Stripe keys setup correctly from the previous chapter?
Hey now it’s not working !? I have been trying this but every time its throwing an error,
{
"statusCode": 500,
"body": "{\"error\":\"As per Indian regulations, only registered Indian businesses (i.e. sole proprietorships, limited liability partnerships and companies, but not individuals) can accept international payments. More info here: https://stripe.com/docs/india-exports\"}",
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": true
}
}