web purchase strategies RRS feed

  • Question

  • User-1104215994 posted

    Hello guys,

    I have a web API, that calls 3rd party web APIs in order to get online game codes that work on a market chain. Now, I would like to integrate my web API to this local website which sells lots of stuff including online game codes. In the market chain, my web API is being called from cashiers by using payment terminals. But on the other hand, I have to query the online website web API in order to get the online game code orders that are paid. I am planning to write a job that queries this online website web API for every 10 minutes in order to check if there are paid orders. What are your suggestions/solutions?

    Best Regards.

    Monday, July 13, 2020 7:04 AM

All replies

  • User1686398519 posted

    Hi cenk1536,

    I am planning to write a job that queries this online website web API for every 10 minutes in order to check if there are paid orders.

    You can use Hangfire if you want to create a job for querying.Hangfire allows you to initiate method calls outside the request processing pipeline in a very simple but reliable way. These method calls are executed in background threads and are called background jobs.For more information, please refer to this link.

    Best Regards,


    Tuesday, July 14, 2020 2:33 AM
  • User-1104215994 posted

    Let's assume I get game orders by calling web site's API. I will do this with a .net core console app which will check the web site's API every 10 minutes. Now assume I get 5 game orders from the web site's API. Inside of this .net core console app, I will call my API in order to complete the purchase of these 5 game orders as follows.

    Can you please check my code and give me some feedback\suggestions? Is there any place to cause a problem?

    static async Task Main(string[] args)
    //getting game orders logic here - assume I get these 5 game orders here

    .... const int numberOfProducts = 5; try { for (var i = 0; i < numberOfProducts; i++) { var product = productFromWebSiteAPI; //DEV var request = (HttpWebRequest)WebRequest.Create("http://test//api/purchase"); var svcCredentials = Convert.ToBase64String( Encoding.ASCII.GetBytes("username" + ":" + "password")); request.Headers.Add("Authorization", "Basic " + svcCredentials); request.Method = "POST"; request.KeepAlive = false; request.ContentType = "application/x-www-form-urlencoded"; var content = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("productCode", product), new KeyValuePair<string, string>("quantity", "1"), new KeyValuePair<string, string>("shopNo", "1"), new KeyValuePair<string, string>("safeNo", "1"), new KeyValuePair<string, string>("cashierNo", "1") }); var formUrlEncodedContent = content; var urlEncodedString = await formUrlEncodedContent.ReadAsStringAsync(); using (var streamWriter = new StreamWriter(await request.GetRequestStreamAsync())) { streamWriter.Write(urlEncodedString); } var httpResponse = (HttpWebResponse)(await request.GetResponseAsync()); var response = new HttpResponseMessage { StatusCode = httpResponse.StatusCode, Content = new StreamContent(httpResponse.GetResponseStream()), }; //Read response var htmlResponse = await response.Content.ReadAsStringAsync(); var deserializedResult = JObject.Parse(htmlResponse); Console.WriteLine((string)deserializedResult["coupons"]?[0]?["Serial"] + ":" + (string)deserializedResult["coupons"]?[0]?["Pin"]); } } catch (Exception e) { Console.WriteLine(e.Message); throw; } }

    Sunday, August 23, 2020 9:01 AM