#TomS - terminal samples
1 messages · Page 1 of 1 (latest)
Hello, what kind of sample are you looking for? A .NET sample for connecting to a terminal?
Hi Pompey! I found some samples using MVC, but our current site is web forms so it uses web services. I've built the methods but no matter what I do, the fetchConnection just doesn't like what is being returned. I just can't figure out what the problem is.
So you are looking for a web service based sample specifically? I am not sure if we have one of those but can look
Can you send me an example of an error that you are getting when you try to call fetchConnection?
I know it's not likely since it's older technology, but I figured I'd give it a shot
I receive this JS error no matter what I do: Uncaught (in promise) Error: onFetchConnectionToken failure. Please make sure your function creates a new connection token via your backend.
The token is being returned from my web service though
Thanks for the error message. Looking in to what specifically triggers it
Thank you very much for the help. I really appreciate it
I have not found any web service samples either at the moment. Will resume looking for that in a bit
the token object being returned from the web method looks correct. I'm not sure why it's generating an error
We currently use Stripe for payments on the web site so if I can just get this reader to work, I think I should be good to go with the rest.
That is great to hear that you are that close. Can you send me the snippet of code that is throwing that error?
function fetchConnectionToken() {
return fetch('Services/Stripe-Terminal.asmx/GetToken', { method: "POST" })
.then(function (response) {
var t = response.json();
debugger;
return response.json();
})
.then(function (data) {
return data.secret;
});
}
This is my web method:
[WebMethod]
public string GetToken()
{
StripeConfiguration.ApiKey = BO.Config.StripeSecretKey();
var options = new ConnectionTokenCreateOptions { };
var service = new ConnectionTokenService();
var connectionToken = service.Create(options);
return Newtonsoft.Json.JsonConvert.SerializeObject(new { secret = connectionToken.Secret });
}
Thank you
Okay I may have misread/misspoke. That is the server side code that is working as far as you can tell, correct?
And the "Error: onFetchConnectionToken failure" message is being thrown by some client side code?
Yes. The web method seems to be returning the token object but the fetchConnectionToken function isn't returning correctly. At least that seems to be what is happening
I got the GetToken method logic from the .NET sample code, however, that sample code is in MVC
Can you send me your fetchConnectionToken function? I am sure it is pretty much the one from our samples, I just want to check
function fetchConnectionToken() {
return fetch('Services/Stripe-Terminal.asmx/GetToken', { method: "POST" })
.then(function (response) {
return response.json();
})
.then(function (data) {
return data.secret;
});
}
Still trying to figure this out, this is almost exactly what what we have in our docs so I am trying to figure out what can be deviating here.
Yeah, that's what has been driving me crazy 🙂
And what does data.secret look like on the client side ? Exactly the json you'd expect, some json like?
secret: "pst_1234..."
}```
That is what is being returned from my web method
This is really weird. The only check in our code that I can see that throws that error just checks that the token is a string and that it starts with pst_
Which, obviously that does both.
Hm. I'm really stumped. Do you happen to know what the StripeTerminal.create() method needs for the onFetchConnectionToken property? I can try writing my own version of the fetchConnectionToken() function
Oh good point. Like try hard coding the response?
It looks like it is just expecting the string "pst_test_123..."
If you hard code that in does it work?
@tribal radish, your example was {secret: xxxx}; @random glade your response was {secret = xxx} - are y'all saying the same thing or not?
Oh that is the raw json that your application is sending?
I assumed that that the = was some debugger representation
(I'm just a third party who notices small things like that)
I appreciate the second set of eyes. The raw json being returned should look something like this:
"secret": "pst_xxxx"
}```
If I try tp hardcode a value for the SripeTerminal.create() function, I get this error:
Uncaught Error: Invalid argument: Invalid onFetchConnectionToken handler given.
You must pass a function that will retreive an connection token via your backend
what do you mean "try to hardcode". Can you share your exact code?
@random glade => @tribal radish was recommending hard-coding the RESPONSE of the call, not the call itself...
yeah that's why I wanted the real code
This is my web method:
[WebMethod]
public string GetToken()
{
StripeConfiguration.ApiKey = BO.Config.StripeSecretKey();
var options = new ConnectionTokenCreateOptions { };
var service = new ConnectionTokenService();
var connectionToken = service.Create(options);
return Newtonsoft.Json.JsonConvert.SerializeObject(new { secret = connectionToken.Secret });
}
This is the javascript function that calls it:
function fetchConnectionToken() {
return fetch('Services/Stripe-Terminal.asmx/GetToken', { method: "POST" })
.then(function (response) {
return response.json();
})
.then(function (data) {
return data.secret;
});
}
var terminal = StripeTerminal.create({
onFetchConnectionToken: fetchConnectionToken,
onUnexpectedReaderDisconnect: unexpectedDisconnect,
});
okay so hardcode the connection token inside fetchConnectionToken
I tried to hard code the token but it wasn't working either
sure but what did you try? The one thing you shared an hour ago is that you tried to put a connection token hardcoded instead of the callback
In the fetchConnection function, I'm returning:
return { secret : "pst_test_YWNjdF8xQVRjeTBGOElqZUpnYVlNLFdER0ZNYnhaUnFFR0pxRUw1Z0s0UWlHaXZqT29yYUE_00kEPYNXIC" };
and I get the same error:
Uncaught (in promise) Error: onFetchConnectionToken failure. Please make sure your function creates a new connection token via your backend.
Can you share the exact code? You only give partial info so it's hard to follow what you are doing
I think I have it now. I'm stripping out the string instead pf the whole object and now it is giving me a different error, but I think I can figure it out from here. I really appreciate the help from all of you