#sébastien

1 messages · Page 1 of 1 (latest)

stiff nebulaBOT
rich burrow
mint gale
#

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?

rich burrow
#

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

plush wedge
#

Hey, taking over here. Let me know if there's any follow-up Qs I can answer!

mint gale
plush wedge
#

What kind of variables?

mint gale
#

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

plush wedge
mint gale
#

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

plush wedge
#

Unfortunately it's not possible to pass parameters outside of what is supported today

#

You could use client_reference_id somehow I guess

mint gale
#

I try but no way to find this variable, neither in the endpoint, nor in the logs or dashboard events. An idea?

plush wedge
#

It's set on the checkout.session.completed events

mint gale
plush wedge
#

But how to get the contents of checkout.session.completed events?
What specific details do you need?

mint gale
#

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

plush wedge
#

Is your webhook endpoint configured to handle checkout.session.completed events?

mint gale
#

yes

plush wedge
mint gale
#

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

urban fox
mint gale
#

It's exactly that. But what to call to get only the latest payment?

urban fox
#

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.

mint gale
#

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.

urban fox
#

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;
}
....
....
mint gale
urban fox
#

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)?

mint gale
#

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

urban fox
#

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.

urban fox
mint gale
#

Thank you very much. Yes it is

urban fox
#

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; 

.....
.....
mint gale
#

I try

#

It's OK, I can read the HHTP POST request on my endpoint

urban fox
#

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.

mint gale
#

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

urban fox
#

ok well whatever

#

so do you know how to retrieve the value of specific fields of that object?

mint gale
#

yes

urban fox
#

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?

mint gale
#

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

urban fox
#

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.

mint gale
#

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

urban fox
#

happy to help