#littlestbrother_

1 messages · Page 1 of 1 (latest)

sleek sunBOT
#

Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

zinc sleet
#

Hi, how can I help?

#

This channel is for live conversations, and if the conversation is stale we archive the thread.

knotty olive
#

I update to the latest Stripe version (14.13.0) and unfortunately that didn’t resolve the issue. So, here’s my code:

#

These are my stripe-node helpers.

stripe.js

const { STRIPE_API_KEY } = require('../constants');
const stripe = require('stripe')(STRIPE_API_KEY);

module.exports = {

    constructEvent: ({ payload, header, secret }) => stripe.webhooks.constructEvent(payload, header, secret),

    generateTestHeaderString: ({ payload, secret }) => stripe.webhooks.generateTestHeaderString({ payload, secret }),
};
#

This is where I am mock the headers / events.

webhook_event.js

const { STRIPE_WEBHOOK_SIGNATURE } = require('../src/constants');
const helpers = require('../src/helpers');

const constructPayload = (obj) => JSON.stringify(obj, null, 2)
const constructHeader = (obj) => helpers.stripe.generateTestHeaderString({ payload: constructPayload(obj), secret: STRIPE_WEBHOOK_SIGNATURE });
const constructEvent = (obj) => helpers.stripe.constructEvent({ payload: constructPayload(obj), header: constructHeader(obj), secret: STRIPE_WEBHOOK_SIGNATURE });

module.exports = {
    constructHeader,
    constructEvent
}
#

This is my unit test.

index.test.js

const chai = require('chai');
const request = require('supertest');

const server = request(require('../../server'));
const { constructHeader, constructEvent } = require('../../../test/webhook_event');
const { STRIPE_SIGNATURE_HEADER } = require('../../constants');

const { expect } = chai;
const base = '/api/webhook';

describe('# POST /', async () => {

    it('should receive customer.subscription.created webhook', async () => {
        // const payload = require('../../../test/mock/customer.subscription.created.json');
        const payload = {
            id: 'evt_test_webhook',
            object: 'event',
        };
        const header = constructHeader(payload);
                const event = constructEvent(payload);
                // 👆 i've tried sending this "event" constant instead of the "payload" constant and it's the same result :/

        const res = await server.post(`${base}`).set({ [STRIPE_SIGNATURE_HEADER]: header }).send(payload);

        expect(res.status).to.equal(200);
    });

});
#

If I understand correctly, I’m supposed to generate the stripe-header and then send the payload to my webhook. I’m not sure if I should send the result of constructEvent() as my payload or just the JSON object. Regardless, I’ve tried both and there hasn’t been a difference in results 😕

Thanks 🙂

zinc sleet
#

What is the issue here? Are you seeing a specific errod code? Sorry, I do not have the context from your previous ask. Are you able to summary what the issue is here?

knotty olive
#

for context ^ I'm trying to mock a webhook event that is sent from stripe for unit testing

zinc sleet
#

And while trying, what issues are you running into?

#

What is the result you're seeing?

#

Are you seeing an error?

#

Can you share more?

knotty olive
#

I'm trying to mock a webhook sent from Stripe for unit testing on a project. I've read about generating a header using the sentry-node sdk but I can’t get my API to accept the payload / header I’ve sent. My API can receive a webhook from Stripe without any issues but If I send my mock webhook I get the following error:

{
  statusCode: 500,
  code: 'Unhandled',
  message: 'No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe? \n' +
    '\n' +
    'Learn more about webhook signing and explore webhook integration examples for various frameworks at https://github.com/stripe/stripe-node#webhook-signing\n',
  details: []
}

I've checked my secrets / creds and they seem fine.

GitHub

Node.js library for the Stripe API. . Contribute to stripe/stripe-node development by creating an account on GitHub.

zinc sleet
#

Can you manually pass the webhook secret to see if that solves the issue? Is there anything that is tampering and not sending the raw signature?