Stripe Webhooks Testing in Go

How can I mock the requests from Stripe to my webhooks with Stripe's Go library?

The Node library has the stripe.webhooks.generateTestHeaderString method that allows to mock such requests:

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);

However, I do not see such method on the webhook package.

Is there any way we can achieve the same with the Go library?


Solution 1:

It looks like Stripe Go SDK doesn't support mocking Webhook. You can either implement one yourself referencing the Node implementation, or use a separated mock server (stripe-ruby-mock) that supports webhook mocking.

Context from this stripe-mock issue.