#Reitrac

1 messages ยท Page 1 of 1 (latest)

gilded cargoBOT
magic zephyr
#

Hi there
Could you please provide an event Id evt_123 and a webhookId ?

distant tiger
#

Where can i found these information ?

#

Is this helped you :

"id": "evt_1M3zGSC1ozQJGJccexQCGMkZ"

#

And Webhook id : we_1M3z8eC1ozQJGJccmpCNmVNN

twilit urchin
distant tiger
#

I dont understand how i can add my IP to safelist

twilit urchin
#

I guess that would depend on your server/host! Ultimately this is a server configuration issue, not a Stripe issue

distant tiger
#

I'n using local server :/

twilit urchin
#

Yep, but Stripe can't reach your local server without some kind of external address (i.e. DNS/IP)

#

You should use the CLI to forward events to your local endpoint rather than configuring a Dashboard endpoint

distant tiger
#

And if i'm working on my dev server this will solve the problem ?

#

i'm sorry i'm a little lost. I just want to use Webhook to sync payment status with my wordpress back end

twilit urchin
#

Yep! See: https://stripe.com/docs/cli/listen

Receive webhook events from Stripe on your local machine via a direct connection to Stripe's API. The listen command can receive events based on your account's default API version or the latest version, filter by type of event, or forward events to an application running on a given port.

#

The issue you have is you're using a localhost URL in your Stripe Dashboard, which is not reachable from anything external to your machine (i.e. Stripe)

#

You should either:

  • Use the Stripe CLI to listen and forward events.
  • Expose your local dev environment via a 'tunnel' (like ngrok) which is than reachable externally.
distant tiger
#

i can use ngrok for live link, but require login / password to access the website

twilit urchin
#

Your webhook endpoint requires a login?

distant tiger
#

nope, ngrok to access my local website

#

I tried with ngrok and webbook return 401 ERR

twilit urchin
#

Did you try the CLI yet?

distant tiger
#

With stripe listen ?

twilit urchin
#

Yes

#

stripe listen --forward-to=your.local.url

distant tiger
#

in my console, everythin works, but not in my dashboard, always the same error

twilit urchin
#

Ignore the Dashboard, that's the unreachable webhook (in fact you can just delete that)

distant tiger
twilit urchin
#

The CLI will forward the events your account is emitting and log any responses sent from your webhook handler code

#

Yup, so your webhook code has received those events and returned a 200 response (indicating succes)

distant tiger
#

And now whats the next step to sync status with my wordpress ?

twilit urchin
#

Yeah so I'd guess you'd write the logic in your webhook handler to handle whatever post payment actions you want

distant tiger
#

"webhook handler" wich file ?

twilit urchin
#

Whatever file whisy-district.local resolves to

distant tiger
#

i create webhook.php in root stripe folder

#

i installed stripe manually and vendor/autoload.php doesn't exist

#

tried to replace by require_once('./init.php');
But there are lot of errors

twilit urchin
#

Ok, and what errors do you see

distant tiger
#

i added stripe-php folder on root if mu project
I added manually server.php and webhook.php

twilit urchin
#

Which version of PHP are you using and which version of stripe-php did you use?

distant tiger
#

stripe, latest from github

#

php : 7.3.5

twilit urchin
#

How are you including it in your project?

distant tiger
#

by using :
whisky-district.local/stripe-php/public/checkout.html

#

I try to make it work outside of my project before including it

twilit urchin
#

Hmm, you don't add the server.php file(s) into the stripe-php directory

#

They live in your project directory

#

And then in those file(s), you include stripe-php:

require_once('/path/to/stripe-php/init.php');
distant tiger
#

I must therefore put the server.php file at the root of my project?

#

I have read the doc several times, I do not understand ...

#

and where i include server.php ?

#

And whats the difference between webhook.php and server.php ?

#

and how theses 2 files are called ?

twilit urchin
#

There's no real difference, you can name the file whatever you like. This would be the file that the webhook endpoint points to, and that handles any events from your Stripe account

distant tiger
twilit urchin
#

I'm not sure what you mean

distant tiger
carmine birch
#

well checkout.html would be the frontend page. You should have something in that html that contacts the server.php script, like a <form action> or some Javascript making a HTTP request.
webhook.php would get triggered from Stripe sending you a request separately.

distant tiger
#

checkout.html > create-checkout-session.php > and then cancel / success. I installed this from the documentation

carmine birch
#

sounds right enough yes

distant tiger
#

My form action call create-checkout-session.php

carmine birch
#

sounds good

#

and does that work? What happens?

distant tiger
#

It works yes but now, need to use webhooks to sync payment statut with my wordpress and i'm lost. I add server.php to root of my project and webhook.php in strip-php folder and then ? Whats the next step ? as i said, I have read the doc several times, I do not understand ...

#

I stopped working locally and moved to an online dev server. My webhook returns me a 200 response in the "successful" column
Now I need to add SQL queries in my php with the conditions "if ok, if ko" but I have absolutely no idea where to add this data

#

I think what is asking is not complicated but I am so lost and desperate that I lose my mind...

carmine birch
#
  • the customer makes the payment
  • we send you a webhook to the URL you set up
  • your code at that URL runs(like the webhook.php script)
  • that code inspects Event object we send in the webhook request body
  • that code can run your business logic like adding entries to an SQL database
distant tiger
#

So i have to replace this by "succes.php" (for example) and wich code i have to put in ?

carmine birch
#

that is not the webhook

#

that is just the success page. It's separate.

#

there's two things.
The customer pays

  • Checkout redirects them to your success_url where you can show them some generic "thanks for paying" page
  • Separately, Stripe send your backend server a checkout.session.completed webhook. You update your records and databases on the backend
#

they're two separate things

distant tiger
#

For the first point, its OK
For the second where is located the script ?

carmine birch
#

not sure what you mean by "located"

distant tiger
#

ineed to call my script manually to sync my webhook ?

carmine birch
#

I don't know what you mean

distant tiger
carmine birch
#

for testing yes

#

when you go live you won't be using stripe-cli

distant tiger
#

my webhook works

#

But where i have to add my SQL queries to sync webhook with my data base ?

carmine birch
#

somewhere in the script that you wrote that handles the webhook.

#

what does that script look like today, can you share the full code?

distant tiger
#

i have no script

#

except webhook.php

#

I took the code on documentation and replace require 'vendor/autoload.php'; by require_once('./init.php');

#

and how launch this script after customer paid ?

carmine birch
#

cool

#

so that script is fine overall

carmine birch
carmine birch
#

But where i have to add my SQL queries to sync webhook with my data base ?
in that script. For example you have

case 'checkout.session.async_payment_succeeded':
    $session = $event->data->object;

in that case of the switch statement, you now have the knowledge that a payment has succeeded, you can inspect the details of the $session object and rwite code there to update your database or so on.

distant tiger
#

i'll try

#

thanks a lot ๐Ÿ™‚

distant tiger
#

Can i ask another question ?

burnt oak
#

Hi! I'm taking over this thread.

distant tiger
#

Hello ๐Ÿ™‚

burnt oak
#

Sure, what's your question?

distant tiger
#

--forward-to=<mypage/webhook.php> can be launch on local project, but how launch on online server when we dont have access to console ?

burnt oak
distant tiger
#

Ok Thanks.
And why, for each event, after customer paid, i have first status "failed" or "succeeded" and then "expired" ?

burnt oak
#

Can you give me an example of PaymentIntent ID where you saw this?

distant tiger
#

Humm writtent in my data base

#

This is my switch case

#

and after the script, this add 2 lines in my database

#

"Succeeded" and "Expired"

#

is "expired" launched after others statuts ?

burnt oak
#

Can you share a PaymentIntent ID (pi_xxx) so I can check the events it generated?

distant tiger
#

yes i'll find it

#

pi_3M42hjC1ozQJGJcc17faON5g

#

or this :
pi_3M42dKC1ozQJGJcc04crMDb9

burnt oak
distant tiger
#

Yes i tried multiple card to try rejected card

#

but this : pi_3M42dKC1ozQJGJcc04crMDb9
Have only 1 entry

#

but 2 in my database

burnt oak
#

Here we sent 2 events related to PaymentIntent: payment_intent.created and payment_intent.succeeded

distant tiger
#

so why "expired" created for each event ? ๐Ÿ˜ข

burnt oak
#

Can you share the event ID of the expired event you see?

distant tiger
#

I already send you : pi_3M42dKC1ozQJGJcc04crMDb9
I cant explain why ๐Ÿ™‚

#

how i can retrieve name and price via $session?

burnt oak
#

I'm asking for an event ID (evt_xxx). This PaymmentIntent ID didn't send any expired event.

distant tiger
#

ho sorry

carmine birch
#

also your PHP code is missing break statements @distant tiger , that's why you're confused I think and seeing multiple things happen

#

https://www.php.net/manual/en/control-structures.switch.php
you need to put breaks in each case, or the execution will just run through every case so the code for every event type will run regardless of what type it actually was. We have that in our example code, you must have removed them when editing the code.

distant tiger
#

hoooooooooo

#

i'm stupid

#

of course yes !

#

how i can retrieve name and price via $session?

carmine birch
#

you can't unfortuantely, you have to make an extra API call at that point to get that information

#

to summarise

distant tiger
#

In "line_items" is it possible to add "reference" ?

#

or "transaction_id"

#

when declare $checkout_session

carmine birch
#

no in the line items no

distant tiger
#

and where can i add custom field or something like this ?

paper field
#

Add a custom field to the Checkout page? Unfortunately that is not possible at the moment though it is on the roadmap. Right now, the best way to take custom info is to collect if from your user before or after redirecting them to checkout