#flux-subscription-events
1 messages · Page 1 of 1 (latest)
Hi there! This is a common error if your code is editing the raw data we sent. usually this means some framework is trying to parse the data as JSON instead of working with the raw body from Stripe
Can you share your code here? Please omit/redact any API keys
please remove your test secret key above (second line)
can you edit this line: headers["stripe-signature"],
to:
request.headers['stripe-signature'],
and then test it again?
yep!
Same error.
t=1673304404,v1=6726166381809dc9e0d19c200a97911a5aac42cc8970b1f7c62adf600f81f344,v0=c5ba322f9571d114ab16268ec63925f33b8b6c42cf52157620234fb8e9d4a43c
⚠️ Webhook signature verification failed. No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe? https://github.com/stripe/stripe-node#webhook-signing```
How about:
request.body,
request.headers['stripe-signature'],
endpointSecret
minor changes, but let me know if you receive the same error
t=1673304588,v1=2b38663b40d0c2a7d8a53c04daad619c818e0c400f609a5d2784828c5b3f7aef,v0=3b6415d01a5d1bdea928c7b52e9daf89b36ca24505e88dc10c4faef1575f6f7c
⚠️ Webhook signature verification failed. No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe? https://github.com/stripe/stripe-node#webhook-signing```
Okay, it looks like this is a known issue with express.json: https://github.com/stripe/stripe-node/issues/341
I recommend removing app.use(express.json()); at the top (line 8), and only run express.json for requests that are not to your webhook endpoint
yep!
testing
⚠️ Webhook signature verification failed. No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe? https://github.com/stripe/stripe-node#webhook-signing```
Still no
let me get some help from a colleague
👋
Can you log out the raw body you are getting?
So basically can you add a log right before let event = request.body; that logs out request.body
It should be a set of binary
If you see JSON then indeed your raw body is getting manipulated by your framework
This is almost always due to express.json or bodyParser
{
id: 'evt_1MOUNjDUe4nm0mczVi8evqp3',
object: 'event',
api_version: '2022-11-15',
created: 1673305435,
data: {
object: {
id: 'sub_1MOTm6DUe4nm0mczsa15eeCb',
object: 'subscription',
application: null,
application_fee_percent: null,
automatic_tax: [Object],
billing_cycle_anchor: 1673303102,
billing_thresholds: null,
cancel_at: null,
cancel_at_period_end: false,
canceled_at: null,
collection_method: 'charge_automatically',
created: 1673303102,
currency: 'usd',
current_period_end: 1675981502,
current_period_start: 1673303102,
customer: 'cus_N8lIQS0rRvmFpz',
days_until_due: null,
default_payment_method: 'pm_1MOTm5DUe4nm0mcz5Fv3ZhKy',
default_source: null,
default_tax_rates: [],
description: null,
discount: null,
ended_at: null,
items: [Object],
latest_invoice: 'in_1MOTm6DUe4nm0mczD1xfymaj',
livemode: false,
metadata: {},
next_pending_invoice_item_invoice: null,
on_behalf_of: null,
pause_collection: null,
payment_settings: [Object],
pending_invoice_item_interval: null,
pending_setup_intent: null,
pending_update: null,
plan: [Object],
quantity: 1,
schedule: null,
start_date: 1673303102,
status: 'active',
test_clock: null,
transfer_data: null,
trial_end: null,
trial_start: null
},
previous_attributes: {
cancel_at: 1675981502,
cancel_at_period_end: true,
canceled_at: 1673305404
}
},
livemode: false,
pending_webhooks: 4,
request: { id: null, idempotency_key: '88382b7e-05b7-4679-8771-ce484c8fd223' },
type: 'customer.subscription.updated'
}```
Yep okay so the issue is indeed the framework.
Can you post your current code as it stands now?
I know you made some edits above
In app.use((req, res, next) => { if (req.includes === '/webhook') { next(); console.log("ok") } else { express.json()(req, res, next); // ONLY do express.json() if the received request is NOT a WebHook from Stripe. } });
Can you change from req.includes to use req.originalUrl? Can you also add a log into that if and else statement to see which statements you are reaching?
(Whoops you already have a log in the if statement, but add one to the else statement).
Also are you seeing the "ok" log fire at all?
no
Gotcha. Yeah try originalUrl instead of includes and let me know what happens
Works now!
🎉
t=1673305818,v1=5cdc08afc5990652af64ac1bda9d22dc4f03157c5415e26a9911433e609f4e07,v0=60c66de4cd81dc4dc94db9bba03cd20fc5e61616d4fd0d27f7b80840ce03899f
Subscription status is active.```
My question is how is the subscription active if I just cancelled it?
@flint loom
I got to hop, @silver creek will take a look at the Subscription if you can provide the ID
The ID should look like sub_...
Are we still working with the one referenced above, sub_1MOTm6DUe4nm0mczsa15eeCb ?
Yes.
Also does this code provided automatically detect when a user doesnt pay their subscription?
This subscription will remain active until the cancellation date (this is currently set to a month from now). You can take a look at the subscription's cancel_at value for the exact timestamp
Is it in the request body?
it should be in the event details for customer.subscription.updated
cancel_at: null
right, evt_1MOUNjDUe4nm0mczVi8evqp3 updated this subscription (take a look at the previous_attributes value in the event details, towards the bottom)
a few other changes have been made to this subscription since then
Comes back as undefined
the last customer.subscription.updated event sent to your endpoint did in fact have "cancel_at": null,. this means that, before the update action tracked by this event, there was no cancel_at value for this subscription
the update resulted in setting a value for cancel_at
Unix Epoch?
I found it by searching through previous discord messages. 😆
Anyways, I will play around with this to integrate it fully with my systems and If I have any questions I will notify you guys!
Thanks for helping.
have a great day!
yes, easy to google and confirm in seconds 🙂