如何在 CLI 中使用条带触发器测试 charge.refund.updated(status=failed)?

How to test charge.refund.updated(status=failed) with stripe trigger in CLI?

我试过了

stripe trigger charge.refund.updated \
  --skip charge \
  --remove refund:charge \
  --add refund:payment_intent=pi_xxx \
  --override refund:status='failed'

但是没用

您的命令将在幕后调用 /v1/refunds,并且 the API's parameters 不允许指定状态。

没有简单的方法可以成功发送创建退款 API 并立即获得状态 = 失败的退款。但是,您可以从 guaranteed result in a failed refund.

的 Card 创建 PaymentIntent

The charge succeeds. If you initiate a refund, its status begins as succeeded. Some time later, its status transitions to failed and sends a charge.refund.updated webhook event.

Stripe CLI 有一个 feature,您可以在其中编写自己的装置并 运行 它们。 我在这种情况下所做的是从他的回答中提到的 github and modified it so it uses the card that @orakaro 复制 charge.refund 的夹具。

{
  "_meta": {
    "template_version": 0
  },
  "fixtures": [
    {
      "name": "charge",
      "path": "/v1/charges",
      "method": "post",
      "params": {
        "source": "tok_refundFail",
        "amount": 100,
        "currency": "usd",
        "description": "(created by Stripe CLI)"
      }
    },
    {
      "name": "refund",
      "path": "/v1/refunds",
      "method": "post",
      "params": {
        "charge": "${charge:id}"
      }
    }
  ]
}

我会在本地保存 json 并使用 stripe-cli 调用 stripe fixtures <path-to-your-json-file>,这将触发状态为失败的 charge.refund.updated 事件。