使用带有graphql-yoga和Prisma的Stripe webhooks

时间:2018-09-17 03:29:42

标签: express stripe-payments graphql webhooks prisma

我在查找如何拦截应用程序中的Stripe Webhook调用时遇到了一些麻烦。我使用graphql-yoga(express)和prisma。

我必须聆听Stripe的付款失败呼叫,以便编辑相应的用户个人资料。

感谢您的帮助!

条纹webhook调用看起来像这样:

{
  "created": 1326853478,
  "id": "charge.expired_00000000000000",
  "type": "charge.expired",
  "object": "event",
  "request": null,
  "pending_webhooks": 1,
  "data": {
    "object": {
      "id": "ch_00000000000000",
      "object": "charge",
      "amount": 100,
      "captured": false,
      "created": 1537153592,
      "currency": "usd",
      "customer": null,
      "description": "My First Test Charge (created for API docs)",
      "invoice": null,
      "livemode": false,
      "on_behalf_of": null,
      "order": null,
      "outcome": null,
      "paid": true,
      "receipt_email": null,
      "receipt_number": null,
      "refunded": false,
      "review": null,
      "shipping": null,
      "source": {
        "id": "card_00000000000000",
        "object": "card",
        "address_city": null,
        "address_country": null,
        "address_line1": null,
        "address_line1_check": null,
        "address_line2": null,
        "address_state": null,
        "address_zip": "12919",
        "address_zip_check": "pass",
        "brand": "Visa",
        "country": "US",
        "customer": "cus_00000000000000",
        "cvc_check": null,
        "name": null,
        "tokenization_method": null
      },
      "statement_descriptor": null,
      "status": "succeeded",
    }
  }
}

1 个答案:

答案 0 :(得分:2)

由于Stripe Webhook返回带有有效载荷POST的通用http JSON,因此不会根据event语言查询来格式化Graphql数据。

目前,您可以使用REST的{​​{1}} [0]

公开普通的Graphql-Yoga API端点

我编写了一个有效的示例代码,您可以尝试一下

express

让我知道以上方法是否有帮助。

[0] https://github.com/prisma/graphql-yoga#how-to-eject-from-the-standard-express-setup