Hello everyone, I hope you all are doing fine. I’m working on Stripe terminal SDK and trying to implement it in ionic v3. I’ve followed the documentation but facing error plus I’ve no idea what i’m doing wrong that error is occuring.
Problem:
After loading Stripe terminal, when I initialize Stripe SDK by creating stripe terminal I’m calling a function(named as fetchConnectionToken) and return it’s security token but race condition is happening and error pops up.
Error
Code
async initiateStripeTerminal() {
loadStripeTerminal().then((res) => {
this.StripeTerminal = res;
this.initiateStripeTerminalSDK();
}, (error) => {
console.log('stripe terminal not loaded', error);
});
}
async initiateStripeTerminalSDK() {
var terminal = this.StripeTerminal.create({
onFetchConnectionToken: this.fetchConnectionToken(), // this line has issue
onUnexpectedReaderDisconnect: this.unexpectedDisconnect()
});
}
async fetchConnectionToken() {
// Your backend should call /v1/terminal/connection_tokens and return the JSON response from Stripe
var req_data = JSON.stringify({ business_id: this.globals.new_id, location_id: "tml_EGeRNABnXI7yVq" });
const response = await fetch(this.globals.BaseUrl + 'stripe_payment/get_connection_token', {
method: "POST",
body: req_data
});
const data = await response.json();
console.log('res token', data.data)
return await data.data.secret_token;
}
Note
I’m also getting response from get_connection_token but after error. Means I believe that function fetchConnectionToken is not returning value properly.
1 post - 1 participant