public OpertionResult UpdateWithBalance(RechargeCollection rechargeCollection) { try { #region Parameters var parameters = new List <OracleParameter> { new OracleParameter { ParameterName = "retVal", OracleDbType = OracleDbType.Int32, Direction = ParameterDirection.ReturnValue }, new OracleParameter { ParameterName = "v_cl_id", OracleDbType = OracleDbType.Int32, Value = rechargeCollection.Id }, new OracleParameter { ParameterName = "v_status", OracleDbType = OracleDbType.Int32, Value = rechargeCollection.Status.Id }, new OracleParameter { ParameterName = "v_ref_no", OracleDbType = OracleDbType.Varchar2, Value = rechargeCollection.RefNo }, new OracleParameter { ParameterName = "v_ref_message", OracleDbType = OracleDbType.Varchar2, Value = rechargeCollection.RefMessage }, new OracleParameter { ParameterName = "v_ref_time", OracleDbType = OracleDbType.Date, Value = rechargeCollection.RefTime }, new OracleParameter { ParameterName = "v_ref_trans_no", OracleDbType = OracleDbType.Varchar2, Value = rechargeCollection.RefTransNo }, new OracleParameter { ParameterName = "v_debug_info", OracleDbType = OracleDbType.Varchar2, Value = rechargeCollection.DebugInfo }, new OracleParameter { ParameterName = "v_update_bal", OracleDbType = OracleDbType.Int32, Value = 1 } }; #endregion db.ExecuteStoredProc("pk_financial.fn_update_collection", parameters); var result = int.Parse(parameters.Find(x => x.ParameterName == "retVal").Value.ToString()); if (result > 0) { return(new OpertionResult { AffectedCount = result, Success = true, Error = string.Empty }); } else { return(new OpertionResult { AffectedCount = result, Success = false, Error = string.Empty }); } } catch (Exception ex) { return(new OpertionResult { AffectedCount = -1, Success = false, Error = ex.Message }); } }
public async Task <List <RechargeCollection> > GetCollectionsAsync(string whereClause, List <OracleParameter> parameters) { string strSql = $"select * from V_COLLECTION {whereClause} order by cl_id"; DataTable masterDataTable; masterDataTable = await db.GetDataAsync(strSql, parameters); if (masterDataTable == null) { return(null); } if (masterDataTable.Rows.Count == 0) { return(null); } var results = new List <RechargeCollection>(); foreach (DataRow row in masterDataTable.Rows) { var obj = new RechargeCollection(); obj.Id = row["cl_id"] == DBNull.Value ? 0 : int.Parse(row["cl_id"].ToString()); obj.CreatedOn = row["createdon"] == DBNull.Value ? DateTime.MinValue : DateTime.Parse(row["createdon"].ToString()); obj.SubscriberNo = row["subs_no"] == DBNull.Value ? string.Empty : row["subs_no"].ToString(); obj.Amount = row["amount"] == DBNull.Value ? 0 : double.Parse(row["amount"].ToString()); obj.PointOfSale.Id = row["pos_id"] == DBNull.Value ? string.Empty : row["pos_id"].ToString(); obj.PointOfSale.Account = row["pos_acc"] == DBNull.Value ? 0 :int.Parse(row["pos_acc"].ToString()); obj.PointOfSale.Balance = row["pos_bal"] == DBNull.Value ? 0 : double.Parse(row["pos_bal"].ToString()); obj.PointOfSale.Name = row["pos_name"] == DBNull.Value ? string.Empty : row["pos_name"].ToString(); obj.PointOfSale.Role.Id = row["pos_role_id"] == DBNull.Value ? 0 : int.Parse(row["pos_role_id"].ToString()); obj.PointOfSale.Role.Name = row["pos_role_name"] == DBNull.Value ? string.Empty : row["pos_role_name"].ToString(); obj.AccessChannel.Id = row["access_channel"] == DBNull.Value ? string.Empty : row["access_channel"].ToString(); obj.AccessChannel.Name = row["access_channel_name"] == DBNull.Value ? string.Empty : row["access_channel_name"].ToString(); obj.Status.Id = row["status"] == DBNull.Value ? 0 : int.Parse(row["status"].ToString()); obj.Status.Name = row["status_name"] == DBNull.Value ? string.Empty : row["status_name"].ToString(); obj.StatusTime = row["status_time"] == DBNull.Value ? DateTime.MinValue : DateTime.Parse(row["status_time"].ToString()); obj.QueueNo = row["queue_no"] == DBNull.Value ? 0 : int.Parse(row["queue_no"].ToString()); obj.RefNo = row["ref_no"] == DBNull.Value ? string.Empty : row["ref_no"].ToString(); obj.RefMessage = row["ref_message"] == DBNull.Value ? string.Empty : row["ref_message"].ToString(); obj.RefTime = row["ref_time"] == DBNull.Value ? DateTime.MinValue : DateTime.Parse(row["ref_time"].ToString()); obj.RefTransNo = row["ref_trans_no"] == DBNull.Value ? string.Empty : row["ref_trans_no"].ToString(); obj.DebugInfo = row["debug_info"] == DBNull.Value ? string.Empty : row["debug_info"].ToString(); obj.ApiTransaction = row["api_trans"] == DBNull.Value ? 0 : int.Parse(row["api_trans"].ToString()); results.Add(obj); } return(results); }
public async Task <RechargeResponseDto> DoRecharge(GrappedRecharge recharge) { //Thread.Sleep(2000); #region Local test var result = new RechargeResponseDto(); var watch = System.Diagnostics.Stopwatch.StartNew(); BasicHttpBinding httpBinding = new BasicHttpBinding(); EndpointAddress p = new EndpointAddress(SharedParams.OCSEndpoint); //Start Send Request------------------------------ - var payService = new CBSService.CBSInterfaceAccountMgrClient(httpBinding, p); { /// payService = SharedParams.OCSEndpoint; CBSService.PaymentRequestMsg msg = new CBSService.PaymentRequestMsg(); CBSService.RequestHeader reqheader = new CBSService.RequestHeader(); reqheader.SessionEntity = new CBSService.SessionEntityType(); reqheader.SessionEntity.Name = SharedParams.OCSApiUser; reqheader.SessionEntity.Password = SharedParams.OCSApiPassword; reqheader.TransactionId = ""; reqheader.SequenceId = "1"; reqheader.CommandId = "Payment"; reqheader.Version = "1"; reqheader.SerialNo = ""; reqheader.RequestType = CBSService.RequestHeaderRequestType.Event; reqheader.SessionEntity.RemoteAddress = SharedParams.PaymentRemoteAddress; msg.RequestHeader = reqheader; msg.PaymentRequest = new CBSService.PaymentRequest(); msg.PaymentRequest.SubscriberNo = recharge.SubscriberNo; msg.PaymentRequest.PaymentAmt = Convert.ToInt64(recharge.Amount) * 100; msg.PaymentRequest.PaymentMode = "1000"; msg.PaymentRequest.TransactionCode = $"VTU{recharge.Id}"; msg.PaymentRequest.RefillProfileID = recharge.Amount.ToString(); try { var requestResult = await payService.PaymentAsync(msg); if (requestResult != null) { result.ResultCode = requestResult.PaymentResultMsg.ResultHeader.ResultCode; result.ResultDesc = requestResult.PaymentResultMsg.ResultHeader.ResultDesc; result.TransNo = requestResult.PaymentResultMsg.PaymentResult.InternalSerialNo; } else { result.ResultCode = "-1001"; result.ResultDesc = "OCS return null"; } } catch (Exception ex) { result.ResultCode = "-1000"; result.ResultDesc = ex.GetType().Name + "-" + ex.Message; } } //} // End Send Request ------------------------------- //await HTTPClientWrapper<RechargeResponseDto>.Get(""); watch.Stop(); double elapsedMs = watch.ElapsedMilliseconds; var collection = new RechargeCollection(); collection.Id = recharge.MasterId; collection.Status.Id = result.ResultCode == SharedParams.SuccessPaymentCode ? 1 : 2; collection.RefNo = result.ResultCode.ToString(); collection.RefMessage = result.ResultDesc; collection.RefTransNo = result.TransNo; collection.RefTime = DateTime.Now; collection.DebugInfo = result.ResultDesc + " OCS(" + elapsedMs + ")"; resultDisplayMsg = collection.DebugInfo; elapsedMs = 0; watch = System.Diagnostics.Stopwatch.StartNew(); var dbResult = new RechargeRepo(db, null).UpdateWithBalance(collection); watch.Stop(); elapsedMs = watch.ElapsedMilliseconds; resultDisplayMsg += " DB(" + elapsedMs + ")"; return(result); #endregion }
public OpertionResult Create(RechargeCollection rechargeCollection) { try { #region Parameters var parameters = new List <OracleParameter> { new OracleParameter { ParameterName = "retVal", OracleDbType = OracleDbType.Int32, Direction = ParameterDirection.ReturnValue }, new OracleParameter { ParameterName = "v_subs_no", OracleDbType = OracleDbType.Varchar2, Value = rechargeCollection.SubscriberNo }, new OracleParameter { ParameterName = "v_amount", OracleDbType = OracleDbType.Decimal, Value = rechargeCollection.Amount }, new OracleParameter { ParameterName = "v_pos_id", OracleDbType = OracleDbType.Varchar2, Value = rechargeCollection.PointOfSale.Id }, new OracleParameter { ParameterName = "v_access_channel", OracleDbType = OracleDbType.Varchar2, Value = rechargeCollection.AccessChannel.Id }, new OracleParameter { ParameterName = "v_queue_no", OracleDbType = OracleDbType.Int32, Value = rechargeCollection.QueueNo }, new OracleParameter { ParameterName = "v_ref_no", OracleDbType = OracleDbType.Int32, Value = rechargeCollection.RefNo }, new OracleParameter { ParameterName = "v_ref_message", OracleDbType = OracleDbType.Varchar2, Value = rechargeCollection.RefMessage }, new OracleParameter { ParameterName = "v_ref_time", OracleDbType = OracleDbType.Date, Value = rechargeCollection.RefTime }, new OracleParameter { ParameterName = "v_ref_trans_no", OracleDbType = OracleDbType.Varchar2, Value = rechargeCollection.RefTransNo }, new OracleParameter { ParameterName = "v_debug_info", OracleDbType = OracleDbType.Varchar2, Value = rechargeCollection.DebugInfo }, new OracleParameter { ParameterName = "v_status", OracleDbType = OracleDbType.Int32, Value = rechargeCollection.Status.Id }, new OracleParameter { ParameterName = "v_api_trans", OracleDbType = OracleDbType.Int64, Value = rechargeCollection.ApiTransaction } }; #endregion db.ExecuteStoredProc("pk_financial.fn_create_collection", parameters); var result = int.Parse(parameters.Find(x => x.ParameterName == "retVal").Value.ToString()); if (result > 0) { return(new OpertionResult { AffectedCount = result, Success = true, Error = string.Empty }); } else { return(new OpertionResult { AffectedCount = result, Success = false, Error = string.Empty }); } } catch (Exception ex) { return(new OpertionResult { AffectedCount = -1, Success = false, Error = ex.Message }); } }
public async Task <IActionResult> Pay(TopupDto topup) { if (!Utility.ValidYMobileNo(topup.subsNo)) { return(BadRequest(new ApiResponse(-3000, "Sorry, the target mobile was wrong"))); } var currentUser = _partnerManager.GetPartnerById(this.HttpContext.User.Identity.Name); var recharge = new RechargeCollection(); recharge.SubscriberNo = topup.subsNo; recharge.Amount = topup.amt; recharge.PointOfSale = currentUser; recharge.QueueNo = 0; recharge.AccessChannel.Id = "api"; recharge.ApiTransaction = topup.seq; var result = new RechargeRepo(_db, _partnerManager).Create(recharge); if (!result.Success) { if (result.AffectedCount == -513) { return(Unauthorized(new ApiResponse(-3003, "Sorry, undefined rule"))); } if (result.AffectedCount == -501) { return(BadRequest(new ApiResponse(-3004, $"Sorry, your balance was not enough {(currentUser.Balance - currentUser.Reserved).ToString("N0")}"))); } if (result.AffectedCount == -502) { return(BadRequest(new ApiResponse(-3005, $"Sorry, amount less than min limit"))); } if (result.AffectedCount == -503) { return(BadRequest(new ApiResponse(-3006, "Sorry, amount more than max limit"))); } if (result.AffectedCount == -511) { return(BadRequest(new ApiResponse(-3007, "Sorry, your account was invalid"))); } if (result.AffectedCount == -512) { return(BadRequest(new ApiResponse(-3008, "Sorry, inconsistent data"))); } if (result.AffectedCount == -514) { return(BadRequest(new ApiResponse(-3009, $"Sorry, duplicated sequence {topup.seq}"))); } if (result.AffectedCount == -515) { return(BadRequest(new ApiResponse(-3010, $"Sorry, amount not allowed"))); } return(BadRequest(new ApiResponse(500, $"Sorry, {result.Error}"))); } recharge.Id = result.AffectedCount; // call web service var endpoint = _config["OCS:Endpoint"]; var apiUser = _config["OCS:User"]; var apiPassword = _config["OCS:Password"]; var remoteAddress = _config["OCS:RemoteAddress"]; var successCode = _config["OCS:SuccessCode"]; var watch = System.Diagnostics.Stopwatch.StartNew(); var payResult = await new TopupService(_db, _partnerManager).DoRecharge(recharge, endpoint, apiUser, apiPassword, remoteAddress, successCode); watch.Stop(); double elapsedMs = watch.ElapsedMilliseconds; payResult.DebugInfo = payResult.RefMessage + " OCS(" + elapsedMs + ")"; var dbResult = new RechargeRepo(_db, null).UpdateWithBalance(payResult); if (!dbResult.Success) { _logger.LogError($"EMERGENCY-CHECk PayId={payResult.Id} {dbResult.Error}"); } if (payResult.Status.Id == 1) { new NotificationRepo(_db, _partnerManager).SendNotification("Recharge.Create", payResult.Id, payResult, 1); } var finalResult = JsonSerializer.Serialize(new { resultCode = payResult.Status.Id == 1 ? 0 : payResult.Status.Id, resultDesc = payResult.RefMessage, sequence = payResult.ApiTransaction, payId = recharge.Id, duration = elapsedMs }); return(Ok(finalResult)); }
public async Task <RechargeCollection> DoRecharge(RechargeCollection recharge, string endpoint, string apiUser, string apiPassword, string remoteAddress, string successCode) { //Thread.Sleep(2000); int resultCode; string transNo = recharge.ApiTransaction.ToString(); string resultDesc; #region Local test //resultCode = int.Parse(successCode); //resultDesc = "success"; //System.Threading.Thread.Sleep(2000); #endregion Local test var paymentValue = new PaymentValuesRepo(_db, _partnerManager).GetSingleOrDefault(recharge.Amount); double profileId = 0; if (paymentValue != null) { profileId = paymentValue.ProfileId; } else { profileId = Convert.ToInt64(recharge.Amount) * 100; } BasicHttpBinding httpBinding = new BasicHttpBinding(); EndpointAddress p = new EndpointAddress(endpoint); //Start Send Request------------------------------ - var payService = new OCSService.CBSInterfaceAccountMgrClient(httpBinding, p); /// payService = SharedParams.OCSEndpoint; OCSService.PaymentRequestMsg msg = new OCSService.PaymentRequestMsg(); OCSService.RequestHeader reqheader = new OCSService.RequestHeader(); reqheader.SessionEntity = new OCSService.SessionEntityType(); reqheader.SessionEntity.Name = apiUser; reqheader.SessionEntity.Password = apiPassword; reqheader.TransactionId = $"VTU{recharge.Id}"; reqheader.SequenceId = "1"; reqheader.CommandId = "Payment"; reqheader.Version = "1"; reqheader.SerialNo = $"VTU{recharge.Id}"; reqheader.RequestType = OCSService.RequestHeaderRequestType.Event; reqheader.SessionEntity.RemoteAddress = remoteAddress; msg.RequestHeader = reqheader; msg.PaymentRequest = new OCSService.PaymentRequest(); msg.PaymentRequest.SubscriberNo = recharge.SubscriberNo; msg.PaymentRequest.PaymentAmt = Convert.ToInt64(recharge.Amount) * 100; msg.PaymentRequest.PaymentMode = "1000"; msg.PaymentRequest.TransactionCode = $"VTU{recharge.Id}"; msg.PaymentRequest.RefillProfileID = profileId.ToString(); try { var requestResult = await payService.PaymentAsync(msg); if (requestResult != null) { resultCode = int.Parse(requestResult.PaymentResultMsg.ResultHeader.ResultCode); resultDesc = requestResult.PaymentResultMsg.ResultHeader.ResultDesc; transNo = requestResult.PaymentResultMsg.PaymentResult.InternalSerialNo; } else { resultCode = -1001; resultDesc = "OCS return null"; transNo = "0"; } } catch (Exception ex) { resultCode = -1000; resultDesc = ex.GetType().Name + "-" + ex.Message; transNo = "0"; } // End Send Request ------------------------------- recharge.Status.Id = resultCode == int.Parse(successCode) ? 1 : 2; recharge.RefNo = resultCode.ToString(); recharge.RefMessage = resultDesc; recharge.RefTransNo = transNo; recharge.RefTime = DateTime.Now; //watch = System.Diagnostics.Stopwatch.StartNew(); return(recharge); //watch.Stop(); //elapsedMs = watch.ElapsedMilliseconds; //return JsonSerializer.Serialize( new { // resultCode = resultCode == int.Parse(successCode) ? 0 : resultCode, // resultDesc = resultDesc, // sequence = transNo, // payId = recharge.Id, // duration = elapsedMs }); }