public ExecutionResult GetMpesaC2B(NeedDataSourceEventArgs args) { var res = new ExecutionResult(true, "Error"); try { using (var entity = new IVENDEntities()) { entity.Configuration.LazyLoadingEnabled = false; entity.Configuration.ProxyCreationEnabled = false; var datafind = entity.MPESA_C2B .ToList(); var filtered = new FilterSupporter <MPESA_C2B>(datafind, args); var result = filtered.FilterData(r => r.ID); res.Result = filtered.itemsResult; res.Message = "Mpesa Data found"; res.IsOkay = true; } } catch (Exception ex) { res.Message = ex.Message; } return(res); }
public ExecutionResult AddMpesaC2B(mpesaObj data) { var res = new ExecutionResult(true, "Error"); try { using (var entity = new IVENDEntities()) { entity.Configuration.LazyLoadingEnabled = false; entity.Configuration.ProxyCreationEnabled = false; //mpesa api intergration String a = "https://sandbox.safaricom.co.ke/mpesa/transactionstatus/v1/query"; string baseUrl = a; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(baseUrl); String token = "ACCESS_TOKEN"; request.Headers.Add("authorization", "Bearer " + token); request.ContentType = "application/json"; request.Headers.Add("cache-control", "no-cache"); request.Method = "POST"; //end of mpesa api var new_client = new MPESA_C2B() { TransactionType = data.transactiontype, TransID = data.transid, TransTime = data.transtime, TransAmount = data.transamount, BillRefNumber = data.BillRefNumber, MSISDN = data.MSISDN, FirstName = data.FirstName, MSG = data.MSG, }; entity.MPESA_C2B.Add(new_client); entity.SaveChanges(); res.Result = new_client; res.Message = "Mpesa Data Saved successfuly"; res.IsOkay = true; } } catch (Exception ex) { res.Message = ex.Message; } return(res); }