public async Task <Status> SendChargeRequestPayAtFawry(double amount) { PaidAmount = Math.Round(amount, 2, MidpointRounding.ToEven); using (HttpClient httpClient = new HttpClient()) { try { httpClient.BaseAddress = new Uri("https://atfawry.fawrystaging.com//ECommerceWeb/Fawry/payments/charge"); GetConfiguration(); string jsonContent = JsonConvert.SerializeObject(PayAtFawryChargeRequest); var requestContent = new StringContent(jsonContent, System.Text.Encoding.UTF8, "application/json"); HttpResponseMessage response = await httpClient.PostAsync("https://atfawry.fawrystaging.com//ECommerceWeb/Fawry/payments/charge", requestContent); string responseContent = await response.Content.ReadAsStringAsync(); PayAtFawryChargeResponse res = await GetChargeResponse(responseContent); CalculatePoints(amount); UserStatusResponse = await InsertOrder(PayAtFawryChargeRequest.merchantCode, PayAtFawryChargeRequest.merchantRefNum, PayAtFawryChargeRequest.customerProfileId); } catch { UserStatusResponse.StatusDescription = "Error: Cannot send request to the server please try again"; } return(UserStatusResponse); } }
public async Task <PayAtFawryChargeResponse> GetChargeResponse(string responseContent) { PayAtFawryChargeResponse payAtFawryChargeResponse = new PayAtFawryChargeResponse(); try { // responseContent = "{\"type\":\"ChargeResponse\",\"referenceNumber\":\"928943097\",\"merchantRefNumber\":\"99900642091\",\"expirationTime\":1516,\"statusCode\":200,\"statusDescription\":\"Operation done successfully\"}"; payAtFawryChargeResponse = JsonConvert.DeserializeObject <PayAtFawryChargeResponse> (responseContent); } catch { payAtFawryChargeResponse.statusDescription = "Error Parsing Json"; } return(payAtFawryChargeResponse); }