#sébastien
1 messages · Page 1 of 1 (latest)
👋 Thanks for reaching out
You can create PaymentLinks via Stripe API:
https://stripe.com/docs/api/payment_links/payment_links/create#create_payment_link-metadata
And pass metadata and set your custom attribute/value, You'll receive those key-value in the Checkout Session once the customer do a purchase
Thanks. My problem is that my appliaction is in classic asp. That's why I'm testing payment links without code. Is it possible to create dynamic metadata in javascript on my payment page which contains the payment link? A sample code?
Is it possible to create dynamic metadata in javascript on my payment page which contains the payment link? A sample code?
Not sure I'm understanding you question here.
Meanwhile, you can create Payment Links using APIs, just in case
https://stripe.com/docs/payments/payment-links/api
Hey, taking over here. Let me know if there's any follow-up Qs I can answer!
I want to use this : https://stripe.com/docs/no-code/payment-links. is there a way to pass variables from my page that contains the payment link and get them back in the endpoint? Thanks
What kind of variables?
Ideally, I would like a link like https://buy.stripe.com/test_...?id_client=1234&id_produit=456
And be able to find these variables in my endpoint. These are dynamic variables, which will change depending on my client who has connected to my payment page. Thanks
Ah, the query parameters? We do support some query params like that: https://stripe.com/docs/payments/payment-links#url-parameters
Yes, something like that but with my own variables, I need to retrieve my customer's id and the product he bought to update my database from my endpoint
Unfortunately it's not possible to pass parameters outside of what is supported today
You could use client_reference_id somehow I guess
I try but no way to find this variable, neither in the endpoint, nor in the logs or dashboard events. An idea?
It's set on the checkout.session.completed events
OK great, I found it. One last question. In my endpoint, I use the address https://api.stripe.com/v1/payment_intents in GET . But how to get the contents of checkout.session.completed events?
But how to get the contents of checkout.session.completed events?
What specific details do you need?
In my endpoint, I send myself an email with the content of the Stripe response (Json). And it starts with:
{ "object": "list"
"data": [ { "id": "pi_3..."
"object": "payment_intent"
"amount": 4900
"amount_capturable": 0
etc
but I don't get my client_reference_id variable.
This is in the checkout.session.completed which starts with:
{
"id": "evt_1...",
"object": "event",
"api_version": "2022-08-01",
"created": 1669027200,
"data": {
"object": {
"id": "cs_test_a...",
"object": "checkout.session",
"after_expiration": null,
etc
I would like to receive news from stripe about this event
Is your webhook endpoint configured to handle checkout.session.completed events?
yes
I'm not sure I'm understanding the issue. That event will contain the client_reference_id field from your Payment Link: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-client_reference_id
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 use this source:
<!--#INCLUDE file="aspJSON.asp" -->
<%
Set oJSON = New aspJSON
Set objhttp = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
objHttp.open "GET", "https://api.stripe.com/v1/payment_intents", false '"https://api.stripe.com/v1/charges", false
objHttp.setRequestHeader "Content Type", "application/x-www-form-urlencoded"
objHttp.setRequestHeader "Authorization", "Bearer sk_test_..."
objHttp.Send
jsonstring=objHttp.ResponseText
Set oJSON = New aspJSON
oJSON.loadJSON(jsonstring)
By mail, I send myself jsonstring
and I don't get the response from checkout.session.completed with my client_reference_id variable but a long file with many payment intents and not just the last one. I hope to be clear. I can send you what I receive but it's a bit long
but a long file with many payment intents and not just the last one
that code you shared looks like it is calling GET /v1/payment_intents which is how you list all PaymentIntents on your account(https://stripe.com/docs/api/payment_intents/list?lang=curl), so that would seem expected.
It's exactly that. But what to call to get only the latest payment?
that wouldn't make sense to do since the latest payment is not guaranteed to be the one related to the webhook even you're looking at.
it's GET https://api.stripe.com/v1/payment_intents/pi_xxxx to retrieve a specific PaymentIntent
the ID pi_xxx is in the CheckoutSession object you receive in the event which you quoted earlier, in the payment_intent field of the object. https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-payment_intent
This is why I want to retrieve the variable id_client to compare it to my client's session and validate his payment. So how to make CheckoutSession object with payment link without code? Sorry, it's complicated but it's a shame that Stripe does not offer solutions for classic asp sites which are still very numerous.
I suppose but wasn't classic ASP deprecated 20 years ago?
So how to make CheckoutSession object with payment link without code?
not sure what that means, can you elaborate?
If using .NET and our .NET library you would write code like this to access the webhook information:
var stripeEvent = EventUtility.ConstructEvent(json, header, secret);
switch (stripeEvent.Type)
{
case "checkout.session.completed":
var session = stripeEvent.Data.Object as Stripe.Checkout.Session;
var id = session.ClientReferenceId;
var paymentIntentID = session.PaymentIntentId;
break;
}
....
....
By 'without code', I want to say no-code (I want to use this : https://stripe.com/docs/no-code/payment-links.). Sorry, my english is bad
which specific part are you having difficulty with? It sounds like you visited the link, made the payment and have received a webhook event and are running some code in response to that event?
or are you not that far yet? what have you done so far and where is your current "blocker"(thing that you are actively stuck on)?
Yes, I manage to create the link, a webhook, an endpoint. My only issue is that I get all the payments and I would just like the last one with my customer id knowing that given my business there is an extremely low risk of me receiving two orders exactly at the same time I am not Amazon ;-). So receive the last payment with, in the Json response, the id of my client. But in what I receive (all payments, the client_reference_id variable does not appear. Thank you for your patience
extremely low risk of me receiving two orders exactly at the same time I am not Amazon 😉
I'm ignoring that because sorry, it is just 100% wrong to list the most recent and if you do it that way, your site will just be very brittle. I will help you do this the correct way and retrieve the actual objects related to the event.
is this the exact code of your webhook endpoint right now?
Thank you very much. Yes it is
Ok. Note this code needs to run when your server receives a HTTP POST request(the webhook) from Stripe. Does that code read an incoming HTTP POST body? If not, can you first make it do that?
In .NET that would be done like this , example from code of my own app.
[HttpPost]
public void Index() {
string rawBody = string.Empty;
using (StreamReader reader = new StreamReader(HttpContext.Request.Body, System.Text.Encoding.UTF8, true, 1024, true))
{
rawBody = reader.ReadToEnd();
}
var json = rawBody;
.....
.....
cool. So can you now take that POST body and parse that as a JSON string, into a C# object?
presumably it's this loadJSON function on that aspjson library.
I manage to retrieve and process this, with the infamous client_reference_id :
{
"id": "evt_1...",
"object": "event",
"api_version": "2022-08-01",
"created": 1669032447,
"data": {
"object": {
"id": "cs_test_...I",
"object": "checkout.session",
"after_expiration": null,
"allow_promotion_codes": false,
"amount_subtotal": 4900,
"amount_total": 4900,
"automatic_tax": {
"enabled": false,
"status": null
},
"billing_address_collection": "self",
"cancel_url": "https://stripe.com",
"customer_reference_id": 10888,
etc
No, it's not the aspjson library. I used this code :
If Request.TotalBytes > 0 Then
Dim lngBytesCount
lngBytesCount = Request.TotalBytes
Response.Write BytesToStr(Request.BinaryRead(lngBytesCount))
End If
Function BytesToStr(bytes)
Dim Stream
Set Stream = Server.CreateObject("Adodb.Stream")
Stream.Type = 1 'adTypeBinary
Stream.Open
Stream.Write bytes
Stream.Position = 0
Stream.Type = 2 'adTypeText
Stream.Charset = "iso-8859-1"
BytesToStr = Stream.ReadText
Stream.Close
Set Stream = Nothing
End Function
ok well whatever
so do you know how to retrieve the value of specific fields of that object?
yes
so if I tell you "create a variable clientReferenceID and set the value to the value of the JSON key json[data][object][client_reference_id] " , would you be able to do that?
sorry for the wait. I am unable to retrieve this variable. with :
For Each xinfo In oJSON.data("data")
Set this = oJSON.data("data").item(xinfo)
Response.Write "Id: " & this.item("id") & vbCrLf
Response.Write "Amount: " & this.item("amount") & vbCrLf
Response.Write "Client reference id: " & this.item("client_reference_id") & vbCrLf
Next
ID: OK
Amount: OK
but client_reference_id, no. It should be 10888
so bear in mind I do not "speak" your ASP language so there's only so much I can help
but the ID is inside [data][object][client_reference_id] Does that code you shared only look at [data][client_reference_id] ?
seems that way to me. You need to obtain the value of the object key , in the value of the data key, that's the actual CheckoutSession object. You're one level too high right now I think.
That's right, it's ok, I have it !
I have to go. Thank you for your help, I will continue to dig but I have already made good progress thanks to you. Thanks
happy to help