#keshav_error
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/1377269125432213504
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi there ๐ is your connection token endpoint fetching a fresh connection token each time it's hit, or is it trying to cache the token it used and keep resending that same token?
i am using same code in a test project and it is returning different
//MARK: ConnectionTokenProvider
func fetchConnectionToken(_ completion: @escaping ConnectionTokenCompletionBlock) {
let url = self.baseURL.appendingPathComponent("connection_token")
AF.request(url, method: .post, parameters: [:])
.validate(statusCode: 200..<300)
.stripeResponseJSON { (result, afDataResponse) in
switch result {
case .success(let json):
if let secret = json["secret"] as? String {
print(secret, "this is secret code")
completion(secret, nil)
} else {
fallthrough // fallthrough and report failed to decode
}
case .failure where afDataResponse.response?.statusCode == 402:
let description =
afDataResponse.data.flatMap({ String(data: $0, encoding: .utf8) })
?? "Failed to decode connection token"
let error = NSError(
domain: "example",
code: 1,
userInfo: [
NSLocalizedDescriptionKey: description
]
)
completion(nil, error)
case .failure(let error):
completion(nil, error)
}
}
}
"https://example-terminal-backend-q2qf.onrender.com/connection_token"
it is returning different
but same api is not working in my real project it is returning failure
Can you elaborate on what you mean by "it is returning different"?
I hit that endpoint a couple times, and see that it appears to be generating a new connection token each time.
api is working fine but when i hit the same api with the code i provided you above in my real project it is returning failure.
Oh, okay. So it sounds like your app is trying to fetch a new connection token from your server, then your server calls our API, and that API request is failing?
yes, in my real project , but it is working in my demo project
Are you getting any sort of error back from our API when you try to create a new connection token in livemode?
Or do those generate a request ID that you can share?
discoverReaders failed: Error Domain=com.stripe-terminal Code=9050 "Connecting to the reader failed because the app completed fetchConnectionToken with an error." UserInfo={NSLocalizedDescription=Connecting to the reader failed because the app completed fetchConnectionToken with an error., com.stripe-terminal:Message=Connecting to the reader failed because the app co
That's the error within your app, I'm referring to the API request that your server (not your app) is making to fetch a connection token that isn't completing successfully.
okay i get your point but when i simply hit this api in postman it is working fine
Yup, I saw that too, but you said it wasn't working in prod which is why I started asking about it ๐
Are you able to monitor network traffic to your production server that is generating connection tokens? Are you able to see the incoming requests from your app, and how your server responded?
currently i am using "Render " server and it is failing in simulated environment as well. I saw a thread about same issue in github but that bug was about andoid kotlin
Are you able to review the logs for your server and check incoming requests and how you responded to them?
What it seems like is happening is:
- Your app tries to take an action with our SDK
- Our SDK flags that it needs a new Connection Token
- Our SDK uses the
fetchConnectionTokenfunction you provide in your app - That makes a request to your backend server to get a Connection Token
- Your backend server makes a request to the Stripe API to get a new Connection Token
- The Connection Token is returned to your app and our SDK
Something is going wrong in that flow, and right now we need to focus on trying to pinpoint where things stop behaving as expected, so we know what part of the flow to investigate further. That's why I'm asking for insight into your backend server logs, to see if we can tell whether the flow is getting to step 3/4. If not, we'll look before that point, if so, we'll look for issues after that.
I am sharing the logs with you also here is the android bug look like same as me
https://github.com/stripe/stripe-terminal-android/issues/355
here is the backend logs
38.183.10.41, 172.68.175.59, 10.220.28.3 - - [28/May/2025:13:07:15 +0000] "POST /connection_token HTTP/1.1" 200 104 0.1373
35.196.132.85, 172.68.175.45, 10.220.220.174 - - [28/May/2025:13:07:36 +0000] "GET /connection_token%22 HTTP/1.1" 404 18 0.0007
98.26.133.11, 172.68.174.139, 10.220.130.135 - - [28/May/2025:13:09:18 +0000] "POST /connection_token HTTP/1.1" 200 104 0.1398
98.26.133.11, 172.68.175.62, 10.220.145.4 - - [28/May/2025:13:09:56 +0000] "POST /connection_token HTTP/1.1" 200 104 0.1439
38.183.10.41, 172.68.174.108, 10.220.177.148 - - [28/May/2025:13:16:08 +0000] "POST /connection_token HTTP/1.1" 200 104 0.1435
38.183.10.41, 172.68.175.76, 10.220.220.174 - - [28/May/2025:13:16:24 +0000] "POST /connection_token HTTP/1.1" 200 104 0.1268
38.183.10.41, 172.68.175.76, 10.220.220.174 - - [28/May/2025:13:30:33 +0000] "POST /connection_token HTTP/1.1" 200 104 0.1467
Hm, that GET request looks a little out of place, but all of those POST requests responding with a 200 seems good. And just double checking, those log entries align with a time when you saw the error in your app?
Hm, then I'm curious to know if your code is getting to and executing this print line that you have:
switch result {
case .success(let json):
if let secret = json["secret"] as? String {
print(secret, "this is secret code")
completion(secret, nil)
} else {
fallthrough // fallthrough and report failed to decode
}```
and if so, whether that log line in your app's logs contain an expected value for a Connection Token. Don't share the full token here if it's a livemode one, but please share the prefix of the returned ID.
sure
In case of sucess
Printing description of json:
โฟ 1 element
โฟ 0 : 2 elements
- key : "secret"
- value : pst_test_YWNjdF8xUlRLSmlScjBEYUxHZGVKLFJUNUgxVTlINllyUVlxVFFLaW5tazlWUDNEM0U1bHg_00dBxSudas
in case of failure - it is going inside of failure case
func fetchConnectionToken(_ completion: @escaping ConnectionTokenCompletionBlock) {
let url = self.baseURL.appendingPathComponent("connection_token")
AF.request(url, method: .post, parameters: [:])
.validate(statusCode: 200..<300)
.stripeResponseJSON { (result, afDataResponse) in
switch result {
case .success(let json):
if let secret = json["secret"] as? String {
print(secret, "this is secret code")
completion(secret, nil)
} else {
fallthrough // fallthrough and report failed to decode
}
case .failure where afDataResponse.response?.statusCode == 402:
let description =
afDataResponse.data.flatMap({ String(data: $0, encoding: .utf8) })
?? "Failed to decode connection token"
let error = NSError(
domain: "example",
code: 1,
userInfo: [
NSLocalizedDescriptionKey: description
]
)
completion(nil, error)
case .failure(let error):
completion(nil, error)--------------------------------- here
}
}
}
(error: Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={_kCFStreamErrorCodeKey=-4, NSUnderlyingError=0x600000c4e970 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={NSErrorPeerAddressKey=<CFData 0x600002113200 [0x1e6ebb4f0]>{length = 16, capacity = 16, bytes = 0x100201bbd81839fc0000000000000000}, _kCFStreamErrorCodeKey=-4, _kCFStreamErrorDomainKey=4}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <DE7B85A2-5839-460B-9A9E-D4EE7D13DA8B>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(\n "LocalDataTask <DE7B85A2-5839-460B-9A9E-D4EE7D13DA8B>.<1>"\n), NSLocalizedDescription=The network connection was lost., NSErrorFailingURLStringKey=https://example-terminal-backend-q2qf.onrender.com/connection_token, NSErrorFailingURLKey=https://example-terminal-backend-q2qf.onrender.com/connection_token, _kCFStreamErrorDomainKey=4})
in case of fail
Huh, so it looks to me like your app lost connection to your server.
yes as per the description is it saying network connection lost but once this issue came i have switched to multiple wifi and mobile data still same issue
Are you still seeing the requests make it to your server once that error starts being thrown? If this is a network issue, I'm going to be pretty limited in how much I can help, since I don't have insight into your network.