#jamie-aitken_code
1 messages · Page 1 of 1 (latest)
👋 Welcome to your new thread!
⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1395715371528355900
📝 Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- jamie-aitken_code, 20 hours ago, 4 messages
With the changes to the Stripe client within the Go SDK, how can I access the LastResponse for each of the objects?
Could you please share a concrete example of this to better understand you ?
Sure, here's an example using Dispute's List
Prior to migrating to the new Client, we had code such as
p := &stripe.DisputeListParams{
PaymentIntent: stripe.String(params.PaymentIntentID),
}
p.Context = ctx
iter := c.disputeClient.List(p)
disputeList, ok := iter.List().(*stripe.DisputeList)
if !ok {
return nil, errFailedToCastToDisputeList
}
disputeListLastResponse, err := getDisputeListLastResponse(disputeList.LastResponse)
if err != nil {
return nil, err
}
for iter.Next() {
// Logic associated with a Dispute
}
After migrating to this client, we have something like this
p := &stripe.DisputeListParams{
PaymentIntent: stripe.String(params.PaymentIntentID),
}
for dispute, err := range c.disputeClient.List(ctx, p) {
if err != nil {
return nil, err
}
// This is nil
lastResponse := dispute.LastResponse
// Logic associated with a Dispute
}
The LastResponse on each Dispute within that List is nil which is problematic because we no longer have access to the DisputeList which we did prior to migrating to the new client. Is it expected that when using the new client, each Dispute should have a value for LastResponse?
Ah I see what you mean, thanks for the additional context
Checking...
You need to update the line:
lastResponse := dispute.LastResponse
To
lastResponse := dispute
After the Seq2 is consumed, you should have the lastResponse object
lastResponse := &..{}
for dispute, err := range c.disputeClient.List(ctx, p) {
if err != nil {
return nil, err
}
// This is nil
lastResponse := dispute
// Logic associated with a Dispute
}
Could you elaborate on this example a little more please, to show how I'd get the RawJSON value associated with the Dispute's LastResponse?
Ah wait, I though you want to get the latest item in the list
What field you want to get exactly ?
https://docs.stripe.com/api/disputes
We are interested in preview field that is not represented in your SDK and are following this advice here https://github.com/stripe/stripe-go?tab=readme-ov-file#properties
For preview field, you should use the beta version of the GO SDK, is it the case for you ?
How would using a beta version help? We've never had to use betas in the past this value is 100% in the RawJSON value, we just need to be able to access it and follow the advice Stripe has given to access undocumented proerties
IN order to use a preview feature, you need to use the corresponding preview field
Do you have the guide you are following for that preview field ?
I'm not able to find it internally ?
Unless something has changed, I'm not sure that's true. We are able to access this field using V79 (non-beta) by following the advice I've linked above.
I've attached a screenshot of the property we're interested in
You code is trying to access the field LastResponse and not NetworkDetails.Visa... 🤔
Yes because LastResponse contains the RawJSON. The RawJSON contains NetworkDetails.Visa. The SDK takes the RawJSON and unmarshals it into a Go struct. However, because this field is not represented in the SDK, we have to follow the advice that I've linked above in order to access it
Oké, that's why I suggested using the preview feature of the SDK, so that you can simply do dispute.NetworkDetails.Visa and not accessing the rawJson of the item
I don't think this has representation in any SDK release though, even the betas!
Did you tried last beta ?
The reason why LastResponse is nil in your case is that the Customer object isn't the root API resource of the List API call:
https://github.com/stripe/stripe-go?tab=readme-ov-file#accessing-the-last-response:~:text=Note that where API resources are nested in other API resources%2C only LastResponse on the top-level resource is set.
Note that where API resources are nested in other API resources, only LastResponse on the top-level resource is set.
The only option here, is to use the corresponding beta version of the SDK that exposes that field.
Can you explain the rationale why you think the last beta would fix my issue here?
I just did a test, and it seems like the NetworkDetails isn't exposed in the latest beta (I don't even see it in the changelog yet)
This all seems like an oversight with the new client to be honest and the fact that we no longer have access to the List's LastResponse
I just did a test, and it seems like the NetworkDetails isn't exposed in the latest beta (I don't even see it in the changelog yet)
yeah, this isn't a new feature, we've been using it for months
Yeah agreed, and as there is no exposure of the field using the SDK, then it becomes impossible to get that field value
Would you be able to raise an issue with the SDK repository ?
https://github.com/stripe/stripe-go
Yeah, can do! Would I be able to reference this thread in the issue?
Yeah sure.
Please share it with me here, so that I can flag it internally too with the owning team
Thanks for your time mate, will do
Np! Always happy to help!