#tombrd
1 messages ยท Page 1 of 1 (latest)
Hello ๐
Hi! I haven't used the CLI with Docker but it should be possible to do so. https://hub.docker.com/r/stripe/stripe-cli
Are you running into any specific errors?
Yes ^^
Actually, i'm on the official doc : https://stripe.com/docs/stripe-cli
I ran the command line given : docker run --rm -it stripe/stripe-cli:latest
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
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
Do i have to run this command inside a container ? Or on my computer ?
You are talking about running the CLI inside the Docker container, correct?
Yes (:
Okay then you need to run this command inside the Docker container
Okay, we agree that the command to run the docker container is this one ?
docker run --rm -it stripe/stripe-cli:latest
That I am not able to verify
Or do i have to create a Dockerfile to build an image or something like that ?
because, this command is the one on the doc ^^
But i got an error when running it
You should be able to pull the Docker image from the docker hub
(i love my dev life haha)
yes that is done already
You said you installed the CLI with apt. I thought that meant you were using a Debian based image
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
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
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 ^^
I think that's exactly what i would like to do yes
but i think i missed something ๐
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/
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 ^^
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
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
I would not use CLI forwarding in a hosted server. It is specifically for local testing on your dev box
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 ^^)
Okay so you are failing signature verification
session = stripe.webhooks.constructEvent(req.body, sig, endpointSecret);
here
correct?
And this is the exact code you are running locally?
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
this is the exact same one yes...
But when i run locally, i use stripe cli too
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
I tried to made my API public using ngrok, and adding a endpoint, but it didn't work too
In the code running on the VPS, can you log the value for the endpointSecret and confirm it is the value in your dashboard?
well, i know it's absolutely not the best solution, maybe even the worst, but i'm running out of time actually to finish my project ^^
yes i already did that, it was the same key, i think the problem might comes from the fact that i use express.json for all my routes, i change that so the route for the webhook does not use this library but the one Stripe use, but even with all of this, it has never worked
The 2 biggest potential culprits here are
- The endpoint secret isn't actually set properly in the runtime environment
- The hosting service is transforming the request somehow
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 ^^