gpt4 book ai didi

express - 将 Stripe webhooks 与 graphql-yoga 和 Prisma 结合使用

转载 作者:行者123 更新时间:2023-12-02 00:29:47 24 4
gpt4 key购买 nike

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

我必须监听来自 Stripe 的支付失败电话,以便我可以编辑相应的用户资料。

感谢您的帮助!

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

最佳答案

由于 Stripe Webhook 返回带有 JSON 负载的通用 http POST,它不会根据 Graphql< 格式化 event 数据 语言查询。

现在,您可以做的是使用 Graphql-Yogaexpress[0]

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

const { GraphQLServer } = require('graphql-yoga')
const typeDefs = `
type Query {
hello(name: String): String!
}
`
const resolvers = {
Query: {
hello: (_, { name }) => `Hello ${name || 'World'}`,
},
}

const server = new GraphQLServer({ typeDefs, resolvers, skipValidation: true })
server.express.use('/api/stripe/webhooks', (req, res) => {
// Handle your callback here !!!!
res.status(200).send();
})

server.start(() => console.log('Server is running on localhost:4000'))

如果以上内容有帮助,请告诉我。

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

关于express - 将 Stripe webhooks 与 graphql-yoga 和 Prisma 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52360385/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com