stripe / stripe-cli

A command-line tool for Stripe
https://stripe.com/docs/stripe-cli
Apache License 2.0
1.57k stars 362 forks source link

stripe fixtures command does not read .env file #1179

Open sovetski opened 1 month ago

sovetski commented 1 month ago

Issue

I am running stripe fixtures ./fixtures.json, and it returns:

Setting up fixture for: customer
Running fixture for: customer
Setting up fixture for: subscription
Running fixture for: subscription
Request failed, status=400, body={
  "error": {
    "code": "resource_missing",
    "doc_url": "https://stripe.com/docs/error-codes/resource-missing",
    "message": "No such price: '${.env:PRICE_ID}'",
    "param": "items[0][price]",
    "request_log_url": "https://dashboard.stripe.com/test/logs/xxx",
    "type": "invalid_request_error"
  }
}

I have PRICE_ID set in my .env and .env.local file. My fixtures.json is:

{
  "_meta":{
    "template_version":0
  },
  "fixtures":[
    {
      "name":"customer",
      "path":"/v1/customers",
      "method":"post",
      "params":{
        "name":"John Doe",
        "email":"johndoe@test.com",
        "source":"tok_visa",
        "address":{
          "line1":"1 Main Street",
          "city":"New York"
        }
      }
    },
    {
      "name":"subscription",
      "path":"/v1/subscriptions",
      "method":"post",
      "params":{
        "customer":"${customer:id}",
        "items":[
          {
            "price":"${.env:PRICE_ID}"
          }
        ]
      }
    }
  ]
}

I followed the explanation from official documentation: https://docs.stripe.com/cli/fixtures

It says:

Use ${.env:PHONE} to access environment variables (supports .env files).

How stripe knows which .env file to read? Generally we commit .env file with some examples with empty values, and the real values are set in .env.local, .env.test etc.

Expected Behavior

It should read the PRICE_ID from my .envor .env.local, .env.test etc.

Environment

Windows