#tombrd

1 messages ยท Page 1 of 1 (latest)

brisk magnetBOT
midnight tendon
#

Hello ๐Ÿ‘‹

frozen garnet
midnight tendon
#

But when i do that, it says :

#

But it seems i can't download stripe via apt install stripe, and i thought i should use stripe login inside the container while it is running

ionic pulsar
#

Hi ๐Ÿ‘‹

I'm stepping in to offer some assistance.

#

When you are running in a docker container you may not have the ports exposed to trigger the communication between your default browser and the stripe CLI. Have you tried specifying your API key for each request instead?

stripe login --api-key sk_test_xxxxxxx
midnight tendon
#

Do i have to run this command inside a container ? Or on my computer ?

ionic pulsar
#

You are talking about running the CLI inside the Docker container, correct?

midnight tendon
#

Yes (:

ionic pulsar
#

Okay then you need to run this command inside the Docker container

midnight tendon
#

Okay, we agree that the command to run the docker container is this one ?
docker run --rm -it stripe/stripe-cli:latest

ionic pulsar
#

That I am not able to verify

midnight tendon
#

Or do i have to create a Dockerfile to build an image or something like that ?

midnight tendon
ionic pulsar
#

You should be able to pull the Docker image from the docker hub

midnight tendon
#

(i love my dev life haha)

midnight tendon
ionic pulsar
#

You said you installed the CLI with apt. I thought that meant you were using a Debian based image

midnight tendon
#

Yes correct

#

Actually

#

I am running on Debian VPS, on that, i have some containers for my DB, my API, reverse proxy etc... and, with my code, i have an error when creating the event from stripe webhook when intenting a payment, but only when i give to stripe my endpoint, but when i used stripe cli (on my local machine) it works fine

#

So i thought maybe if i'm able to run stripe cli somewhere on my VPS (inside a docker, or anywhere else) and redirecting to my API's route, then it should works fine

ionic pulsar
#

Wait... so is your question actually about how to get your webhook endpoint to work?

#

Because I have my stripe CLI forwarding webhook events to my server (running in Docker) right now

midnight tendon
#

Well, kind of ^^
But i already asked the question some weeks ago, and i was told that it was complicated to integrate stripe with nodejs ^^

midnight tendon
#

but i think i missed something ๐Ÿ‘€

ionic pulsar
#

Okay so I run the CLI on my local machine directly. But I have it forwarding webhook events to my docker-ized dev box on the port I exposed (8000)

#

Like this stripe listen --forward-to http://localhost:8000/webhook-endpoint/

midnight tendon
#

So, you run this on your local machine ?

#

but where is your server ?

#

'cause i do that actually on my local machine to dev, and it works, i just would like to do the exact same on my VPS ^^

ionic pulsar
#

Okay for your server you need to make sure the docker container your server is running in has the port exposed to receive web traffic. I'm guessing you have that squared away

midnight tendon
#

okay, i found something
I ran this command
sudo docker run -d --rm -it stripe/stripe-cli listen --api-key myKey

#

but now, i don't find how to get the webhook key ^^and also how to say where it has to forward

ionic pulsar
#

I would not use CLI forwarding in a hosted server. It is specifically for local testing on your dev box

midnight tendon
#

yes i know... but actually i have this

webHookRouter
    .route('/')
    .post(express.raw({type: 'application/json'}), async (req, res) => {
        const sig = req.headers['stripe-signature'];

        let session, data, eventType, clientId;

        try {
            session = stripe.webhooks.constructEvent(req.body, sig, endpointSecret);
            console.log("Webhook received");

            data = session.data.object;
            eventType = session.type;
            clientId = data.client_reference_id;
            console.log("clientId", clientId);

            if (!clientId) {
                console.log(`Webhook Notice: clientId is undefined`);
                res.status(200).send(`Webhook Notice: clientId is undefined`);
                return;
            }

        } catch (err) {
            console.log(`Webhook Error: ${err.message}`);
            res.status(400).send(`Webhook Error: ${err.message}`);
            return;
        }
.......

But when i go on stripe to add the endoint i got an error, my API can not validate that it comes from stripe

#

And i don't really have the time to find a solution to that
It's not a real project, just school project, so it does not really mater if it's not perfect, or totally secure (even if it is actually ^^)

ionic pulsar
#

Okay so you are failing signature verification

#

session = stripe.webhooks.constructEvent(req.body, sig, endpointSecret);

#

here

#

correct?

midnight tendon
#

Yes when i use the endpoints feature

#

yes

ionic pulsar
#

And this is the exact code you are running locally?

midnight tendon
#

I just manage to do what i wanted to do ๐Ÿฅณ
I succeed to connect with stripe cli on my machine, then running the docker, changing my key on my prod env, and now it's working

midnight tendon
#

But when i run locally, i use stripe cli too

ionic pulsar
#

Okay but let's get this running where the problem is. I don't think running the CLI in your VPS would solve the issue

midnight tendon
#

I tried to made my API public using ngrok, and adding a endpoint, but it didn't work too

ionic pulsar
#

In the code running on the VPS, can you log the value for the endpointSecret and confirm it is the value in your dashboard?

midnight tendon
ionic pulsar
#

I don't think it is a solution

#

at all

midnight tendon
ionic pulsar
#

The 2 biggest potential culprits here are

  1. The endpoint secret isn't actually set properly in the runtime environment
  2. The hosting service is transforming the request somehow
midnight tendon
#

Surely the second one
But we run out of time
I'm very disapointing to not have been able to make that works properly..... But we have yet a lot to do to finish, we have less than 20 hours ^^

If you can / want, i surely will try after to make this work properly ^^

ionic pulsar
#

Well I am having the same issues you were with the stripe CLI in the docker container.

#

I had more luck using a Ubuntu docker container and installing the Stripe CLI.

#

However, there I had to specify the API key directly