# Test the Billing API

**URL:** <https://discourse.sst.dev/t/test-the-billing-api/172>\
**Category:** Chapter Comments\
**Created:** [May 9, 2018, 11:18pm UTC](https://discourse.sst.dev/t/test-the-billing-api/172 "2018-05-09T23:18:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [May 9, 2018, 11:18pm UTC](https://discourse.sst.dev/t/test-the-billing-api/172/1 "2018-05-09T23:18:25Z")

</div>

Link to chapter - [https://serverless-stack.com/chapters/test-the-billing-api.html](https://serverless-stack.com/chapters/test-the-billing-api.html)

---

<div class="post-metadata">

**Author:** ![prathamjain](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/prathamjain/32/432_2.png) [@prathamjain](https://discourse.sst.dev/u/prathamjain)\
**Post date:** [February 15, 2019, 6:34am UTC](https://discourse.sst.dev/t/test-the-billing-api/172/2 "2019-02-15T06:34:47Z")

</div>

Hi, i get the following when i run serverless invoke on the billing function:

```auto
Serverless Warning --------------------------------------
 
  A valid file to satisfy the declaration 'file(resources/api-gateway-errors.yml)' could not be found.
 
Serverless: Bundling with Webpack...
Time: 787ms
Built at: 2/14/2019 10:29:11 PM
         Asset Size Chunks Chunk Names
    billing.js 8.72 KiB billing [emitted] billing
billing.js.map 6.12 KiB billing [emitted] billing
Entrypoint billing = billing.js billing.js.map
[./billing.js] 2.17 KiB {billing} [built]
[./libs/billing-lib.js] 285 bytes {billing} [built]
[./libs/response-lib.js] 762 bytes {billing} [built]
[babel-runtime/core-js/json/stringify] external "babel-runtime/core-js/json/stringify" 42 bytes {billing} [built]
[babel-runtime/helpers/asyncToGenerator] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {billing} [built]
[babel-runtime/regenerator] external "babel-runtime/regenerator" 42 bytes {billing} [built]
[source-map-support/register] external "source-map-support/register" 42 bytes {billing} [built]
[stripe] external "stripe" 42 bytes {billing} [built]

```

I dont know why it isnt returning success code 200 or any failure code after function execution. Do you have any idea what i could be doing wrong?

Thank you

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [February 18, 2019, 6:41pm UTC](https://discourse.sst.dev/t/test-the-billing-api/172/3 "2019-02-18T18:41:04Z")

</div>

Not sure what is going on here. To debug this add a `SLS_DEBUG=* server less invoke`… before your command.

---

<div class="post-metadata">

**Author:** ![mathewgries](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/mathewgries/32/419_2.png) [@mathewgries](https://discourse.sst.dev/u/mathewgries)\
**Post date:** [March 1, 2019, 8:14pm UTC](https://discourse.sst.dev/t/test-the-billing-api/172/4 "2019-03-01T20:14:41Z")

</div>

I had the same issue. When I cloned the repository for the project from git, it did not include the resource folder with the project. Therefore, that file did not exist. You can go to the git repo and copy the file contents, and create the file manually.

Also, the serverless.yml file did not include this section when the project was cloned:

resources:

- ${file(resources/api-gateway-errors.yml)}

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [March 3, 2019, 4:23pm UTC](https://discourse.sst.dev/t/test-the-billing-api/172/5 "2019-03-03T16:23:48Z")

</div>

Yeah we missed that in one of our previous updates. It should be there now.

---

<div class="post-metadata">

**Author:** ![3DG3](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/3dg3/32/609_2.png) [@3DG3](https://discourse.sst.dev/u/3DG3)\
**Post date:** [October 27, 2019, 2:06pm UTC](https://discourse.sst.dev/t/test-the-billing-api/172/6 "2019-10-27T14:06:20Z")

</div>

Watch out when you copy and paste when adding to billing-event, billing-lib and billing …trailing spaces will cause Errors… you may need to look at the formatting…

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [November 3, 2019, 1:26am UTC](https://discourse.sst.dev/t/test-the-billing-api/172/7 "2019-11-03T01:26:35Z")

</div>

Are you copying this from the PDF? Cos the online version seems fine to me.

---

<div class="post-metadata">

**Author:** ![Meaix88](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@Meaix88](https://discourse.sst.dev/u/Meaix88)\
**Post date:** [January 4, 2020, 4:55pm UTC](https://discourse.sst.dev/t/test-the-billing-api/172/8 "2020-01-04T16:55:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Aaron](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/aaron/32/885_2.png) [@Aaron](https://discourse.sst.dev/u/Aaron)\
**Post date:** [January 9, 2020, 9:08pm UTC](https://discourse.sst.dev/t/test-the-billing-api/172/9 "2020-01-09T21:08:31Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [January 12, 2020, 3:55am UTC](https://discourse.sst.dev/t/test-the-billing-api/172/10 "2020-01-12T03:55:25Z")

</div>

Can you point me to the exact snippet that is giving you issues?

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [January 12, 2020, 3:56am UTC](https://discourse.sst.dev/t/test-the-billing-api/172/11 "2020-01-12T03:56:24Z")

</div>

Hmm that is interesting. Did you figure out this issue?

---

<div class="post-metadata">

**Author:** ![Meaix88](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@Meaix88](https://discourse.sst.dev/u/Meaix88)\
**Post date:** [January 12, 2020, 6:34pm UTC](https://discourse.sst.dev/t/test-the-billing-api/172/12 "2020-01-12T18:34:00Z")

</div>

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. ![image](https://canada1.discourse-cdn.com/flex032/uploads/serverless_stack/original/1X/612ead4758f4d194ffb6ef7f483f156a30494679.png)

Once the selected portion was removed it wasn’t an issue.

---

<div class="post-metadata">

**Author:** ![Meaix88](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@Meaix88](https://discourse.sst.dev/u/Meaix88)\
**Post date:** [January 12, 2020, 6:36pm UTC](https://discourse.sst.dev/t/test-the-billing-api/172/13 "2020-01-12T18:36:55Z")

</div>

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.

![image](https://canada1.discourse-cdn.com/flex032/uploads/serverless_stack/original/1X/81675d91903fedd0287b22cc3ea2a67d1d0cf04c.png)

strangely, I noticed that there were also trailing spaces in the dynamodb-lib.js file but it didn’t throw an error for me.

---

<div class="post-metadata">

**Author:** ![Aaron](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/aaron/32/885_2.png) [@Aaron](https://discourse.sst.dev/u/Aaron)\
**Post date:** [January 12, 2020, 7:48pm UTC](https://discourse.sst.dev/t/test-the-billing-api/172/14 "2020-01-12T19:48:13Z")

</div>

I did! I named my mock billing-events.json instead of billing-event.json.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [January 26, 2020, 6:09pm UTC](https://discourse.sst.dev/t/test-the-billing-api/172/15 "2020-01-26T18:09:13Z")

</div>

That’s super weird. Because we don’t have that in the source.

Btw, if you use the _Copy_ button, it works fine right?

---

<div class="post-metadata">

**Author:** ![Meaix88](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@Meaix88](https://discourse.sst.dev/u/Meaix88)\
**Post date:** [January 27, 2020, 4:40pm UTC](https://discourse.sst.dev/t/test-the-billing-api/172/16 "2020-01-27T16:40:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [February 10, 2020, 6:54pm UTC](https://discourse.sst.dev/t/test-the-billing-api/172/17 "2020-02-10T18:54:47Z")

</div>

Are you on Windows? I tried it across browsers on macOS and it seems fine.

---

<div class="post-metadata">

**Author:** ![ajitgoel](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/ajitgoel/32/777_2.png) [@ajitgoel](https://discourse.sst.dev/u/ajitgoel)\
**Post date:** [March 1, 2020, 4:03pm UTC](https://discourse.sst.dev/t/test-the-billing-api/172/18 "2020-03-01T16:03:18Z")

</div>

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\"}"
}
```

---

<div class="post-metadata">

**Author:** ![ajitgoel](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/ajitgoel/32/777_2.png) [@ajitgoel](https://discourse.sst.dev/u/ajitgoel)\
**Post date:** [March 1, 2020, 4:06pm UTC](https://discourse.sst.dev/t/test-the-billing-api/172/19 "2020-03-01T16:06:19Z")

</div>

never mind i got it fixed. i was using the live stripe secret key in .env file.

---

<div class="post-metadata">

**Author:** ![Himujjal](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/himujjal/32/1002_2.png) [@Himujjal](https://discourse.sst.dev/u/Himujjal)\
**Post date:** [May 11, 2020, 10:36am UTC](https://discourse.sst.dev/t/test-the-billing-api/172/20 "2020-05-11T10:36:36Z")

</div>

### 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:

```auto
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](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.

[Next page](https://discourse.sst.dev/t/test-the-billing-api/172.md?page=2)
