/// <summary> /// This Async service For Reversing a Transaction. /// </summary> /// <exception cref="GameballException">Thrown if the request fails..</exception> public async Task <TransactionResponse> ReverseTransactionAsync(ReverseTransactionRequest reverse) { reverse.Validate(); reverse.TransactionTime = DateTime.UtcNow; string hash = GameballUtils.GetSHA1(reverse.PlayerUniqueId, TransactionKey, GameballUtils.ToUtcTime(reverse.TransactionTime), GameballUtils.ToValidAmount(reverse.Amount)); reverse.Hash = hash; var response = await this.Client.PostAsync(ApiBase + GameballConstants.Cancel, new StringContent(reverse.Serialize(), Encoding.UTF8, "application/json")); if (!response.IsSuccessStatusCode) { throw (BuildGameballException(response)); } else { return(JsonConvert.DeserializeObject <TransactionResponse>(await response.Content.ReadAsStringAsync())); } }
public async Task <Object> ProcessTransaction1(ReverseTransactionRequest mpesaRequest, string token) { HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Clear(); client.BaseAddress = new Uri("https://sandbox.safaricom.co.ke"); client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}"); var json = JsonConvert.SerializeObject(mpesaRequest); var httpContent = new StringContent(json, Encoding.UTF8, "application/json"); var resWithToken = client.PostAsync("/mpesa/reversal/v1/request", httpContent).Result; stringData = resWithToken.Content.ReadAsStringAsync().Result; var response = JsonConvert.DeserializeObject <ReverseTransactionResponse>(stringData); return(response); }