Http request - connection lost while waiting for response

Hi, i am working on App, that works as some kind of mobile cash desk - cashier just selects items from the list and these items are added to customers account, or customer pays with cash.
App is sending data to ASP.NET SOAP API, which saves transaction in database. When the transaction is saved, it responds OK, so that apps now, that everything was processed correctly.
The problem is, that the request sometimes takes 2-3s before the response comes back. How can i handle cases, when there is problem with internet connection? What if i for example lost connection when the request was already received, but the response never comes because of bad internet/wifi connection?
I need to be sure, if transaction was processed and saved to database or not.
Any ideas how to solve this problem?

If the internet issue you would like to handle from mobile end is there is a plugin to check network status in ionic native network plugin.
If my guess is correct,only you are worried about the network connection if I see your problem statment.

One thing you could do is to include some redundancy in the protocol:

  1. client sends server an “open transaction” request, gets back a transaction id
  2. client makes actual request, including transaction id
    2a. if transaction id has been used for a step 2 request before, do nothing and return “already done”
    2b. if transaction has not been used for a step 2 request yet, perform action and return “done”

If the network goes down between steps 1 and 2, you have a Schrödinger’s cat situation. The app can display this fact to the user, and retry step 2 (as many times as desired, without fear of double-booking) when the network comes back. Obviously, there isn’t any direct way to inform the app what has happened during the period where there is no network connection.

I thought about this solution, but i was thinking if there is some other way, but probably not. Thx for your answer.

iam trying to solve this in this manner, but there is a lot of issues…
fro example:
how to generate transactionId
where to store it(in web service/database)
how to handle cases when there are more clients than one - avoiding some transactionId collisions

iam struggling a little with this

I use this algorithm for generating ids that could be used in situations like this. I can’t remember exactly where I got it originally, but I think it was in a blog entry from somebody at Instagram. This version works with PostgreSQL; I’m not sure how portable it is:

CREATE SEQUENCE global_id_sequence;

CREATE OR REPLACE FUNCTION id_generator(OUT result BIGINT) AS $$
DECLARE
  our_epoch  BIGINT := 1314220021721;
  seq_id     BIGINT;
  now_millis BIGINT;
  -- the id of this DB shard, must be set for each
  -- schema shard you have - you could pass this as a parameter too
  shard_id   INT := 1;
BEGIN
  SELECT nextval('global_id_sequence') % 1024
  INTO seq_id;

  SELECT FLOOR(EXTRACT(EPOCH FROM clock_timestamp()) * 1000)
  INTO now_millis;
  result := (now_millis - our_epoch) << 23;
  result := result | (shard_id << 10);
  result := result | (seq_id);
END;
$$
LANGUAGE PLPGSQL;

Multiple clients should be no problem at all, and by fiddling with the shard parameter, even multiple servers should not have collision concerns. If you are willing to spend double the space of a BIGINT, you could always use the UUID type.