#someone
1 messages · Page 1 of 1 (latest)
hi
i know
The error suggests you're not passing in the raw request body from the event delivery
maybe u missunderstood
Is there any other part of your app configuration which applies body parsing / mutations?
nope
Can you share more of your app initialization code?
I'd also suggest logging payload, sig, endpointSecret for yourself to inspect and ensure all values make sense
const YOUR_DOMAIN = 'https://some-development.pl/';
app.get('/', (req, res) => {
res.redirect('https://some-development.pl/index.html')
})
app.post('/buy/some_banks', async (req, res) => {
const session = await stripe.checkout.sessions.create({
line_items: [
{
// Provide the exact Price ID (for example, pr_1234) of the product you want to sell
price: 'price_1MzMFwDnC20fs5eDlQ4scBEY',
quantity: 1,
},
],
mode: 'payment',
success_url: `${YOUR_DOMAIN}/success.html`,
cancel_url: `${YOUR_DOMAIN}/cancel.html`,
});
res.redirect(303, session.url);
});
app.post('/webhook', express.raw({ type: 'application/json' }), async (request, response) => {
const payload = request.body;
let event;
try {
const sig = request.headers['stripe-signature'];
event = stripe.webhooks.constructEvent(payload, sig, endpointSecret);
} catch (err) {
console.log(`Webhook Error: ${err.message}`)
return response.status(400).send(`Webhook Error: ${err.message}`);
}
console.log(event)
switch (event.type) {
case 'checkout.session.completed': {
const session = event.data.object;
// createOrder(session);
if (session.payment_status === 'paid') {
fulfillOrder(session);
}
break;
}
case 'checkout.session.async_payment_succeeded': {
const session = event.data.object;
fulfillOrder(session);
break;
}
// case 'checkout.session.async_payment_failed': {
// const session = event.data.object;
// emailCustomerAboutFailedPayment(session);
// break;
// }
default: {
break
}
}
response.status(200).end();
});
const SCOPES = ['https://www.googleapis.com/auth/gmail.readonly'];
const TOKEN_PATH = path.join(process.cwd(), 'token.json');
const CREDENTIALS_PATH = path.join(process.cwd(), 'credentials.json');
async function loadSavedCredentialsIfExist() {
try {
const content = await fs.readFile(TOKEN_PATH);
const credentials = JSON.parse(content);
return google.auth.fromJSON(credentials);
} catch (err) {
return null;
}
}
async function saveCredentials(client) {
const content = await fs.readFile(CREDENTIALS_PATH);
const keys = JSON.parse(content);
const key = keys.installed || keys.web;
const payload = JSON.stringify({
type: 'authorized_user',
client_id: key.client_id,
client_secret: key.client_secret,
refresh_token: client.credentials.refresh_token,
});
await fs.writeFile(TOKEN_PATH, payload);
}
async function authorize() {
let client = await loadSavedCredentialsIfExist();
if (client) {
return client;
}
client = await authenticate({
scopes: SCOPES,
keyfilePath: CREDENTIALS_PATH,
});
if (client.credentials) {
await saveCredentials(client);
}
return client;
}
async function listLabels(auth) {
const gmail = google.gmail({ version: 'v1', auth });
const res = await gmail.users.labels.list({
userId: 'me',
});
const labels = res.data.labels;
if (!labels || labels.length === 0) {
console.log('No labels found.');
return;
}
}
authorize().then(listLabels).catch(console.error);
app.listen(80, () => console.log('Listening for incoming questions at port 80'));```
Note that your live endpoint will require a different endpointSecret than the test mode endpoint, but the error you showed really suggests you've got some request body mutation happening that you don't expect
ik
i had this problem 2 weeks ago and we fixed it
It looks like there's more to app than what's shown here, this does not show how app is created
const express = require('express');
const app = express();
const mysql = require('mysql');
const endpointSecret = ' also removed this ';
var nodemailer = require('nodemailer');
const fs = require('fs').promises;
const path = require('path');
const process = require('process');
const { authenticate } = require('@google-cloud/local-auth');
const { google } = require('googleapis');
const sendMail = require('./gmail');
app.use(express.static('public'));```
there is no more
If you log out the parameters above, they all appear as you expect them to?
What do you mean?
that there is no problem with my app
Ok but why do you say there is an issue with the signature specifically?
Can you share your account ID or webhook endpoint ID so I can look at some logs?
You can confirm the secret you are using for live mode is whsec_tg...NVNe?
no
im using another
whsec_631.....c93
or yes
but in app.js i have another one
Your live mode endpoint must be using the secret I mentioned, that's the one you see in your dashboard for it:
https://dashboard.stripe.com/webhooks/we_1MzM4YDnC20fs5eDt4YWEFEi