Ad

Is The Stripe API Test Key Limited To Certain Features?

I'm building an ecommerce application using Stripe for the first time. I'm making a GET request to the endpoint /v1/products using either Insomnia or the Stripe npm package to get my complete product data which will then populate the catalogue page.

My question is whether there is limited functionality on the test secret key Stripe provides? As when I use it the return data is an empty array, compared with the live api key which returns the array populated with products.

This:

import Stripe from 'stripe';
const stripe = Stripe(process.env.STRIPE_TEST_SECRET_KEY);

stripe.products.list()
  .then(console.log);

Returns this:

{
"object": "list",
"data": [],
"has_more": false,
"url": "/v1/products"
}

Whereas swapping STRIPE_TEST_SECRET_KEY for STRIPE_LIVE_SECRET_KEY returns this:

{
"object": "list",
"data": [
    {
        "id": "tower",
        "object": "product",
        "active": true,
        "attributes": [
            "height",
            "colour",
            "waterproof"
        ],
        "caption": "Tower",
        "created": 1520612842,
        "deactivate_on": [],
        "description": null,
        "images": [],
        "livemode": true,
        "metadata": {},
        "name": "Tower",
        "package_dimensions": {
            "height": 20.0,
            "length": 20.0,
            "weight": 700.0,
            "width": 80.0
        },
        "shippable": true,
        "skus": {
            "object": "list",
            "data": [
                {
                    "id": "t001",
                    "object": "sku",
                    "active": true,
                    "attributes": {
                        "height": "1600",
                        "colour": "White",
                        "waterproof": "False"
                    },
                    "created": 1520612987,
                    "currency": "gbp",
                    "inventory": {
                        "quantity": 10,
                        "type": "finite",
                        "value": null
                    },
                    "livemode": true,
                    "metadata": {},
                    "package_dimensions": {
                        "height": 20.0,
                        "length": 20.0,
                        "weight": 700.0,
                        "width": 80.0
                    },
                    "price": 90000,
                    "product": "tower",
                    "updated": 1520674446
                },
                {
                    "id": "t002",
                    "object": "sku",
                    "active": true,
                    "attributes": {
                        "height": "1600",
                        "colour": "White",
                        "waterproof": "True"
                    },
                    "created": 1520613174,
                    "currency": "gbp",
                    "image": null,
                    "inventory": {
                        "quantity": 10,
                        "type": "finite",
                        "value": null
                    },
                    "livemode": true,
                    "metadata": {},
                    "package_dimensions": {
                        "height": 20.0,
                        "length": 20.0,
                        "weight": 700.0,
                        "width": 80.0
                    },
                    "price": 110000,
                    "product": "tower",
                    "updated": 1520613174
                }
            ],
            "has_more": false,
            "total_count": 8,
            "url": "/v1/skus?product=tower&active=true"
        },
        "type": "good",
        "updated": 1520674071,
        "url": null
    }
],
"has_more": false,
"url": "/v1/products"
}
Ad

Answer

I have since solved this. I had not realised that live and test data were fully partitioned and it was necessary to create products separately in the test portal for the test api key to work.

On the off chance someone else encounters this issue, from the Stripe dashboard click the 'View test data' switch then follow the process to create products again.

Ad
source: stackoverflow.com
Ad