#Reitrac

1 messages · Page 1 of 1 (latest)

gleaming forgeBOT
simple latch
#

You can retrieve the checkout session

urban frigate
#

i have my checkout session ID and i need to get product name and price to sync information to my wordpress

simple latch
#

Yeah you can use the above api request

urban frigate
#

how ? i dont understand this doc :/

simple latch
#

Are you a developer?

urban frigate
#

A little bit

#

😄

simple latch
#

Oh ok. You can use our stripe php library: https://github.com/stripe/stripe-php. Then make an api call to retrieve the checkout session by id: https://stripe.com/docs/api/checkout/sessions/retrieve?lang=php. Then, on the object that's returned, you can look at price data: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items-data-price

urban frigate
#

i already have this, i created webhook, etc.. everything works. Now, i need to get informations after payments to sync with my database

simple latch
#

What webhook event are you listening to?

urban frigate
#

all from checkout

#

i need more listener ?

simple latch
#

What events specifically?

urban frigate
#

i dont know, as i said, i just need to get product name and amount to sync with my database

simple latch
#

I showed you how. But you told me you wanted to do it from webhooks, so I need to know what events you are listening for to help you. From the checkout session object, it's in the price data: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items-data-price. Only thing to note is you'll have to retrieve the product based on the product id to get more data on the product: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items-data-price-product. You can retrieve with this api call: https://stripe.com/docs/api/products/retrieve

urban frigate
#

i'm lost :/

simple latch
#

Ok let's take a step back

#

Did you write your webhook code?

urban frigate
#

yes

#

i have a webhook.php file and it works cause i wrote in my database after payment

simple latch
#

Ok. What events are you listening to in that code?

urban frigate
#

Here is my file

#

On my dashboard, when i created my wbehook, i add "checkout" and checked all

simple latch
#

These are the events you are handling in your code:

switch ($event->type) {
  case 'checkout.session.async_payment_failed':
    $session = $event->data->object;
    $sql = "INSERT INTO stripe (transaction, prix, statut) VALUES ('123456789', '1000', 'Echoué')";
    $conn->exec($sql);
    break;
  case 'checkout.session.async_payment_succeeded':
    $session = $event->data->object;
    $sql = "INSERT INTO stripe (transaction, prix, statut) VALUES ('123456789', '1000', 'Réussi')";
    $conn->exec($sql);
    break;
  case 'checkout.session.completed':
    $session = $event->data->object;
    $sql = "INSERT INTO stripe (transaction, prix, statut) VALUES ('123456789', '1000', '".$session."')";
    $conn->exec($sql);
    break;
  case 'checkout.session.expired':
    $session = $event->data->object;
    $sql = "INSERT INTO stripe (transaction, prix, statut) VALUES ('123456789', '1000', 'Expiré')";
    $conn->exec($sql);
    break;
  // ... handle other event types
  default:
    echo 'Received unknown event type ' . $event->type;
}```
#

Within checkout.session.completed, you can get the checkout session object (that's the $session variable you created)

urban frigate
#

Yes i have it

#

Now, i need product name

simple latch
#

Right, so you do this step I outlined above:
Only thing to note is you'll have to retrieve the product based on the product id to get more data on the product: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items-data-price-product. You can retrieve with this api call: https://stripe.com/docs/api/products/retrieve

#

So you grab the product id on that object

#

Then you have to make an api call to get the product name

urban frigate
#

i have no product ID

#

StripeCheckoutSession JSON: { "id": "cs_test_a1YG63LWYc4ocr5ooJkq8LWF0WoC5NNYDmeDspQaq4rwAyCJBVcejQXzzM", "object": "checkout.session", "after_expiration": null, "allow_promotion_codes": null, "amount_subtotal": 3500, "amount_total

#

This is wat $session return

simple latch
#

That's only a small part

#

What does the whole object look like

urban frigate
#

but i have no product ID, so how can i get it ?

#

the only thing i have is price and session ID

simple latch
#

What's the checkout session id?

#

Oh I see

#

One sec

#

I see product on the object

#

What does the rest of $session look like?

#

You only shared part

urban frigate
#

no i shared the entire content

#

this is what i have in my database

simple latch
#

No you only shared:

    "id": "cs_test_a1YG63LWYc4ocr5ooJkq8LWF0WoC5NNYDmeDspQaq4rwAyCJBVcejQXzzM",
    "object": "checkout.session",
    "after_expiration": null,
    "allow_promotion_codes": null,
    "amount_subtotal": 3500,
    "amount_total```
#

There's more to the object

#

You can tell it's an incomplete json object because there's no close }

urban frigate
simple latch
#

You stored the incomplete object then

urban frigate
#

yes its incomplete

#

so why ? 😢

simple latch
#

Do you have a character count restriction in that database column?

#

I also don't recommend storing the whole object

#

Just store the values that you need

#

But anyway, we're getting away from the issue here

urban frigate
#

haaa yes

#

hoooo

#

i'm sutpid 😢

simple latch
#

Don't look at what you stored in the database here. Within your code in that case 'checkout.session.completed': $session = $event->data->object; $sql = "INSERT INTO stripe (transaction, prix, statut) VALUES ('123456789', '1000', '".$session."')"; $conn->exec($sql); break; block, you can get the product id from the $session variable

urban frigate
#

ok 'ill try something later i have to go sorry :/

#

thanks a lot

#

i'll try to use product object now