#gb34-Webhook
1 messages · Page 1 of 1 (latest)
OK, the charge object doesn't carry the product info. But you can save it in the charge's metadata (https://stripe.com/docs/api/charges/update#update_charge-metadata) and get from it later in webhook event handling.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I'm not sure where to go edit that
is that something I have to do on the webhooks UI on stripe
dashboard
You can use Stripe API to update the charge object, see (https://stripe.com/docs/api/charges/update#update_charge-metadata)
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I'm actually doing my integration with Google App Script
this is what I am trying to get at
// current product ID
var productID = '---productID------';
// only want to listen to events concerning specified product.
if (event["data"].object.id !== productID) {
return;
}
How did you create charge in Google App Script? when you create the charge, you can also set the metadata. https://stripe.com/docs/api/charges/create?lang=curl#create_charge-metadata
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Or are you using payment Intent API?
I am not using an API
I create an endpoint on my app script that only listens to the charge.succeeded event
and from there I run some code
I deployed a link then used it as my endpoint in stripe webhook section
I created the product using the stripe UI
do you recommend me using the payment_intent event instead?
will that give me the user name, email, and the productID?
Sorry if this was too much
btw I am a college senior working on a sponsored capstone project
Are you using a 3rd-party plugin?
No
OK, then you need to check your code and see how did you make the charge (i.e., via either PaymentIntent / Charge / Checkout Session API), and then set the price/product info on the charge or payment_intent's metadata.
In this way, when the charge.succeeded or payment_intent.succeeded happens, you can retrieve the price/product info from the metadata of the received charge or payment_intent object
I am not creating the charge programtically
all I'm doing is that I am listening to the charge.succeeded event
I wish I could just show you this on a video call
I'm afraid that I can't join a call. Did you create the charge from Stripe Dashboard?
yeah I did
Got it, you can type in the product info in the description when creating a payment in Dashboard
I am not sure how that will help
Am I making sense? Like do you get what I am trying to do?
The idea here is to add in the product info when the payment is created, whether it's via Dashboard or API.
Based on your description, my understanding is that you are creating payments from Dashboard, and that's why I suggest you to type in the product info in the description field.
Yes I'm creating the product payment link from Dashbaord
would the description field be part of my charge JSON object I receive on my backend from stripe
Ah I see, I though you are creating payments, they are different things.
So my thought was that I can listen for event only for a specific product
you know
why doesn't stripe add that productID in its JSON object
idk
I been try to figure this out for a long time now
Hi! I'm taking over Jack Tan.
Hi
Could you summarise your question while I catchup?
yeah
So I built an endpoint server on google app script, that listens to stripe charge.succeeded event. It runs some code using the data from the charge object
The idea in this project is that a user makes a payment using the stripe payment link that we created on the dashboard. after they submit that payment we get a notification (charge.succeeded) on our backend. Our backend will use the name and email that was entered on the payment link. we will email the user a link to take an assessment. This assessment is what we're pretty much selling (product)
The assessment is the product we created on the stripe dashboard
So at the moment we only have one product on our dashboard which is this assessment. If we add more products it will become a problem for our backend, because it will run everytime a charge.succeeded is made.
Hi @snow surge before I leave, I'll just want to say that you can listen to checkout_session.completed event to get the checkout session object, where you can get the product info (via line_items https://stripe.com/docs/api/checkout/sessions/object?lang=node#checkout_session_object-line_items) and the customer
Yes if you are using Payment Links, you should listen to the checkout_session.completed to get access to all the information about the Payment Link. The charge.succeeded event is a lot more limited.
{
"id": "cs_test_a16AGPuv0UVNuqOGpvHnAbYVNmbPLj1S7e6jPLbSf2bc6iMVUApBlq4vkN",
"object": "checkout.session",
"after_expiration": null,
"allow_promotion_codes": null,
"amount_subtotal": null,
"amount_total": null,
"automatic_tax": {
"enabled": false,
"status": null
},
"billing_address_collection": null,
"cancel_url": "https://example.com/cancel",
"client_reference_id": null,
"consent": null,
"consent_collection": null,
"currency": null,
"customer": null,
"customer_creation": null,
"customer_details": null,
"customer_email": null,
"expires_at": 1650962665,
"livemode": false,
"locale": null,
"metadata": {},
"mode": "payment",
"payment_intent": "pi_1Dr1S92eZvKYlo2CrWdcRnWr",
"payment_link": null,
"payment_method_options": {},
"payment_method_types": [
"card"
],
"payment_status": "unpaid",
"phone_number_collection": {
"enabled": false
},
"recovered_from": null,
"setup_intent": null,
"shipping": null,
"shipping_address_collection": null,
"shipping_options": [],
"shipping_rate": null,
"status": "expired",
"submit_type": null,
"subscription": null,
"success_url": "https://example.com/success",
"total_details": null,
"url": null
}
```
is that what you're talking about?
Yes! However by default the line_items is not included. You would need to retrieve the Checkout Session with expand, as shown here: https://stripe.com/docs/expand#includable-properties
can this be done using the UI on stripe or this is something I have to do on my backend
Just to clarify
checkout_session.completed
Expanding the repsonse has to be done with code in your backend.
checkout_session.completed will give me the name and email of the customer right
Okay I will try this then see how it goes
thanks again for your time and help
checkout_session.completed will give me the name and email of the customer right
Yes, in thecustomer_detailsobject or by looking at thecustomerID.