Go 中的 Stripe Webhooks 测试
Stripe Webhooks Testing in Go
如何使用 Stripe 的 Go 库模拟从 Stripe 到我的 webhook 的请求?
Node 库具有允许模拟此类请求的 stripe.webhooks.generateTestHeaderString
方法:
const payload = {
id: 'evt_test_webhook',
object: 'event',
};
const payloadString = JSON.stringify(payload, null, 2);
const secret = 'whsec_test_secret';
const header = stripe.webhooks.generateTestHeaderString({
payload: payloadString,
secret,
});
const event = stripe.webhooks.constructEvent(payloadString, header, secret);
// Do something with mocked signed event
expect(event.id).to.equal(payload.id);
但是,我在 webhook
包中没有看到这样的方法。
有什么方法可以用 Go 库实现同样的效果吗?
Stripe Go SDK 似乎不支持模拟 Webhook。您可以自己实现一个支持 webhook 模拟的 the Node implementation, or use a separated mock server (stripe-ruby-mock)。
上下文来自此 stripe-mock issue。
如何使用 Stripe 的 Go 库模拟从 Stripe 到我的 webhook 的请求?
Node 库具有允许模拟此类请求的 stripe.webhooks.generateTestHeaderString
方法:
const payload = {
id: 'evt_test_webhook',
object: 'event',
};
const payloadString = JSON.stringify(payload, null, 2);
const secret = 'whsec_test_secret';
const header = stripe.webhooks.generateTestHeaderString({
payload: payloadString,
secret,
});
const event = stripe.webhooks.constructEvent(payloadString, header, secret);
// Do something with mocked signed event
expect(event.id).to.equal(payload.id);
但是,我在 webhook
包中没有看到这样的方法。
有什么方法可以用 Go 库实现同样的效果吗?
Stripe Go SDK 似乎不支持模拟 Webhook。您可以自己实现一个支持 webhook 模拟的 the Node implementation, or use a separated mock server (stripe-ruby-mock)。
上下文来自此 stripe-mock issue。