【问题标题】:Is the Stripe API test key limited to certain features?Stripe API 测试密钥是否仅限于某些功能?
【发布时间】:2018-03-10 09:57:56
【问题描述】:

我是第一次使用 Stripe 构建电子商务应用程序。我正在使用 Insomnia 或 Stripe npm 包向端点 /v1/products 发出 GET 请求,以获取我的完整产品数据,然后这些数据将填充目录页面。

我的问题是 Stripe 提供的测试密钥是否功能有限?当我使用它时,返回数据是一个空数组,与返回填充有产品的数组的实时 api 键相比。

这个:

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

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

返回这个:

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

而将STRIPE_TEST_SECRET_KEY 换成STRIPE_LIVE_SECRET_KEY 会返回:

{
"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"
}

【问题讨论】:

  • 我投票结束这个问题,因为we are not Stripe customer support.
  • 嗨 Jörg,您在客户支持问题上链接的帖子说询问使用公司的 API 是可以接受的。无论如何,尽管我现在已经发现了我的错误并解决了问题。我无法接受自己的答案,否则我会将其标记为已解决。

标签: javascript node.js stripe-payments api-key


【解决方案1】:

我已经解决了这个问题。我没有意识到实时数据和测试数据是完全分区的,需要在测试门户中单独创建产品才能使测试 api 密钥正常工作。

万一其他人遇到此问题,请从 Stripe 仪表板单击“查看测试数据”开关,然后按照流程再次创建产品。

【讨论】:

    【解决方案2】:

    虽然没有解决 OP 的具体问题,但我遇到了相同的症状并记录了解决方案,希望它对其他人有所帮助。

    在开发者仪表板中,当我们从一个系统迁移到新系统时,我被设置为使用旧的 API 版本。我需要更新以使用最新的 API 版本来解决问题并获得完全填充的 /v1/products 调用。

    【讨论】:

      猜你喜欢
      • 2016-09-27
      • 1970-01-01
      • 1970-01-01
      • 2021-11-14
      • 1970-01-01
      • 2022-07-11
      • 2014-08-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多