#someone

1 messages · Page 1 of 1 (latest)

spice karmaBOT
tawdry heron
#

hi

sturdy ermine
#

hey there

#

This seems unrelated to the SSL certificate you mentioned

tawdry heron
#

i know

sturdy ermine
#

The error suggests you're not passing in the raw request body from the event delivery

tawdry heron
#

maybe u missunderstood

sturdy ermine
#

Is there any other part of your app configuration which applies body parsing / mutations?

tawdry heron
#

nope

sturdy ermine
#

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

tawdry heron
#
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'));```
sturdy ermine
#

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

tawdry heron
#

i had this problem 2 weeks ago and we fixed it

sturdy ermine
#

It looks like there's more to app than what's shown here, this does not show how app is created

tawdry heron
#
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

sturdy ermine
#

If you log out the parameters above, they all appear as you expect them to?

tawdry heron
#

yes

#

but problem is not with app. problem is with signature payload

sturdy ermine
#

What do you mean?

tawdry heron
#

that there is no problem with my app

sturdy ermine
#

Ok but why do you say there is an issue with the signature specifically?

tawdry heron
#

i sent this screenshot

sturdy ermine
#

Can you share your account ID or webhook endpoint ID so I can look at some logs?

tawdry heron
#

yeah, give me a sec

#

we_1MzM4YDnC20fs5eDt4YWEFEi

spice karmaBOT
sturdy ermine
#

You can confirm the secret you are using for live mode is whsec_tg...NVNe?

tawdry heron
#

im using another

#

whsec_631.....c93

tawdry heron
#

but in app.js i have another one

sturdy ermine
tawdry heron
#

ok

#

okey its working now