|
|
using Common; using Common.Language; using Common.Model.AutoRefund; using Common.Model.Enum; using Common.Model.KwangjuBank; using log4net; using Newtonsoft.Json; using PushNotification; using Repository.AutoRefund; using System; using System.Runtime.Remoting.Messaging; using System.Threading.Tasks;
namespace Business.AutoRefund { public class AutoRefundBusiness : IAutoRefundBusiness { private readonly IAutoRefundRepository _repo; private static readonly ILog Log = LogManager.GetLogger(typeof(AutoRefundBusiness));
public AutoRefundBusiness(IAutoRefundRepository repo) { _repo = repo; }
public JsonRxResponse UpdateAutoRefund(KwangjuAutoRefundModel model) { return _repo.SendAutoRefund(model); }
public CustomerInfo GetCustomerInfoForKwangju(string customerId) { return _repo.GetCustomerInfoForKwangju(customerId); }
public JsonRxResponse GetRefundRequirement(string userName) { var jsonRx = new JsonRxResponse() { ErrorCode = "1", Msg = "Cannot find the requirements." }; var res = _repo.GetRefundRequirement(userName);
if (res == null) { return jsonRx; }
var minAmt = Convert.ToDouble(res.MinimumAmount) + Convert.ToDouble(res.RefundCharge); var curAmt = Convert.ToDouble(res.CurrentBalance); if (curAmt < minAmt) { jsonRx.SetResponse("1", "You donot have sufficient amount."); return jsonRx; }
jsonRx.SetResponse("0", "Success"); jsonRx.Data = res; return jsonRx; }
public JsonRxResponse ProcessAutoRefund(AutoRefundRequestModel model) { JsonRxResponse JsonRx = new JsonRxResponse { ErrorCode = "1", Msg = "Refund Request cannot proceed further. Please contact GME head office." }; KwangjuAutoRefundModel kjModel = new KwangjuAutoRefundModel { Flag = "REQ", CustomerId = model.UserId, CustomerSummary = "", Amount = model.Amount, Action = "REQ", ActionDate = "", ActionBy = model.Username };
//Laster remove this for demo purpose only now
// INSERT REQUEST INTO DB AND GENERATE VOUCHER / DIDUCT BALANCE
var res = _repo.SendAutoRefund(kjModel); if (res.ErrorCode != "0") { JsonRx.ErrorCode = res.ErrorCode; JsonRx.Msg = res.Msg; return JsonRx; }
/* * KJ_AUTO_REFUND의 RowId를 이용해서 Update한다. * */ kjModel.RowId = res.Id;
//GET CUSTOMER INFORMATION FOR KJ BANK API TO REFUND BALANCE IN CUSTOMER PRIMARY ACCOUNT
var custDetail = _repo.GetCustomerInfoForKwangju(model.UserId); //kjModel.Amount = (Convert.ToDecimal(model.Amount) - Convert.ToDecimal(model.ChargeAmount)).ToString();
AmountTransferToBank req = new AmountTransferToBank { obpId = "", // "001-90010001-000001-6000001", //GME OBPID
accountNo = "KJ",// "1107020345626", //GME 계좌코드
accountPassword = "", // "1212", //GME 패스워드
receiveInstitution = custDetail.BankCode.ToString(), receiveAccountNo = custDetail.BankAccountNo.ToString(), amount = (Convert.ToDecimal(model.Amount) - 1000).ToString(), bankBookSummary = String.Format("REFUND{0}", custDetail.BankAccountNo.ToString()), transactionSummary = "GME Refund" }; //FOR TEST
//req.receiveInstitution = "034";
//req.receiveAccountNo = "145121636083";
var body = JsonConvert.SerializeObject(req); var resp = KwangjuBankApi.TransferAmount(body); var dbApiRes = JsonConvert.DeserializeObject<JsonRxResponse>(resp); if (!dbApiRes.ErrorCode.Equals("0")) { if (dbApiRes.ErrorCode.Equals(ErrorCode.One)) { var kjMsg = JsonConvert.DeserializeObject<KwangjuResult>(dbApiRes.Msg); var eCode = kjMsg.error.code.ToString(); var eMessage = kjMsg.error.message.ToString();
dbApiRes.Msg = "Something is wrong. " + eCode + " " + eMessage; }
kjModel.Flag = "FAIL"; kjModel.Action = "FAIL"; } else { kjModel.Flag = "SUCCESS"; kjModel.Action = "SUCCESS"; }
var rs = _repo.SendAutoRefund(kjModel);
if (rs.ErrorCode.Equals("0")) { var fcmId = Convert.ToString(CallContext.GetData(Constants.FcmId)); var lang = Convert.ToString(CallContext.GetData(Constants.Language));
Task.Run(() => FcmNotifier.Notify(fcmId, Languages.GetMessage("autorefund_success", lang), Languages.GetTitle("autorefund", lang))); } rs.Data = new { Message = rs.Msg, Extra = rs.Extra }; return rs; }
public JsonRxResponse AutoDebitGiveBackDeposit(AutoDebitRefund refundInfo, AmountTransferToBank transferToBank) { var jsonRx = new JsonRxResponse { ErrorCode = "1", Msg = "Failed!" }; _repo.LogFailTransactionForAutoDebit(refundInfo.RowId, refundInfo.ErrorCode, refundInfo.ErrorMsg); try { KwangjuAutoRefundModel kj = new KwangjuAutoRefundModel() { Flag = "Autodebit_REQ", CustomerId = refundInfo.CustomerId, CustomerSummary = "", Amount = transferToBank.amount, Action = "REQ", ActionDate = "", ActionBy = refundInfo.Username, BankCode = transferToBank.receiveInstitution, BankAccountNo = transferToBank.receiveAccountNo };
var res = _repo.SendAutoRefund(kj); kj.RowId = res.Id;
var json = JsonConvert.SerializeObject(transferToBank); var resp = KwangjuBankApi.TransferAmount(json); jsonRx = JsonConvert.DeserializeObject<JsonRxResponse>(resp);
if (!jsonRx.ErrorCode.Equals("0")) { if (jsonRx.ErrorCode.Equals(ErrorCode.One)) { var kjMsg = JsonConvert.DeserializeObject<KwangjuResult>(jsonRx.Msg); var eCode = kjMsg.error.code.ToString(); var eMessage = kjMsg.error.message.ToString();
jsonRx.Msg = "Something is wrong. " + eCode + " " + eMessage; }
kj.Flag = "Autodebit_FAIL"; kj.Action = "FAIL"; } else { kj.Flag = "SUCCESS"; kj.Action = "SUCCESS"; }
jsonRx = _repo.SendAutoRefund(kj); if (jsonRx.ErrorCode.Equals("0")) { jsonRx.Data = new { Message = jsonRx.Msg }; } return jsonRx; } catch (Exception ex) { return jsonRx; } } } }
|