Exemplo n.º 1
0
        public async Task <ActionResult> PsResponse()
        {
            var encryptedData = Request.Form["data"];

            if (string.IsNullOrEmpty(encryptedData))
            {
                return(Redirect($"{m_baseUrl}/ost"));
            }

            var rijndaelKey   = new RijndaelEnhanced(m_paymentGatewayEncryptionKey);
            var decryptedData = rijndaelKey.Decrypt(encryptedData);

            var decryptedDataArr = decryptedData.Split(new char[] { '|' });
            var model            = new PaymentSwitchResponseModel();

            model.TransactionId     = decryptedDataArr[0];
            model.TransactionAmount = decryptedDataArr[1];
            model.TransactionGST    = decryptedDataArr[2];
            model.ServiceFee        = decryptedDataArr[3];
            model.ServiceGST        = decryptedDataArr[4];
            model.TotalAmount       = decryptedDataArr[5];
            model.Status            = decryptedDataArr[6];
            model.ErrorMessage      = decryptedDataArr[7];

            LoadData <ConsigmentRequest> lo = await GetConsigmentRequest(model.TransactionId);

            if (null == lo.Source)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(Json(new { success = false, status = "ERROR", message = $"Cannot find ConsigmentRequest with Id/ReferenceNo: {model.TransactionId}." }, JsonRequestBehavior.AllowGet));
            }
            var item = lo.Source;

            if (model.Status.Equals("1"))
            {
                item.Payment.IsPaid = true;
                item.Payment.Status = model.Status;
                item.Payment.Date   = DateTime.Now;
                await SaveConsigmentRequest(item);

                // wait until the worker process it
                await Task.Delay(1500);

                return(Redirect($"{m_baseUrl}/ost#consignment-request-paid-summary/{item.Id}"));
            }
            else
            {
                item.Payment.IsPaid = false;
                item.Payment.Status = model.Status;
                item.Payment.Date   = DateTime.Now;
                await SaveConsigmentRequest(item);

                // wait until the worker process it
                await Task.Delay(1500);

                return(Redirect($"{m_baseUrl}/ost#consignment-request-summary/{item.Id}"));
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult> PsResponsePrepaid()
        {
            var context = new SphDataContext();
            //TODO: Clean-up unused GLs
            //1. get all GLs owned by current user with (Type == "Prepaid") AND (UserId == null)
            //2. delete all found GLs

            var encryptedData = Request.Form["data"];

            if (string.IsNullOrEmpty(encryptedData))
            {
                return(Redirect($"{m_baseUrl}/ost#wallet-list-all"));
            }

            var rijndaelKey   = new RijndaelEnhanced(m_paymentGatewayEncryptionKey);
            var decryptedData = rijndaelKey.Decrypt(encryptedData);

            var decryptedDataArr = decryptedData.Split(new char[] { '|' });

            var model = new PaymentSwitchResponseModel();

            model.TransactionId     = decryptedDataArr[0];
            model.TransactionAmount = decryptedDataArr[1];
            model.TransactionGST    = decryptedDataArr[2];
            model.ServiceFee        = decryptedDataArr[3];
            model.ServiceGST        = decryptedDataArr[4];
            model.TotalAmount       = decryptedDataArr[5];
            model.Status            = decryptedDataArr[6];
            model.ErrorMessage      = decryptedDataArr[7];
            Console.WriteLine(model.ErrorMessage);

            //get wallet to determine wallet Id as GL correspondingId
            LoadData <Wallet> loWallet = await GetWalletByTotalValue(model.TransactionAmount);

            if (null == loWallet.Source)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(Json(new { success = false, status = "ERROR", message = $"Cannot find TransactionAmount with Id: {model.TransactionAmount}." }, JsonRequestBehavior.AllowGet));
            }
            var wallet = loWallet.Source;

            //get userdetail to update AccountBalance
            LoadData <UserDetail> loUserDetail = await GetUserDetail(User.Identity.Name);

            if (null == loUserDetail.Source)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(Json(new { success = false, status = "ERROR", message = $"Cannot find UserId with Id: {User.Identity.Name}." }, JsonRequestBehavior.AllowGet));
            }
            var userDetail = loUserDetail.Source;

            //verify reference no from GL (get by reference no)
            LoadData <GeneralLedger> loGeneralLedger = await GetGeneralLedger(model.TransactionId);

            if (null == loGeneralLedger.Source)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(Json(new { success = false, status = "ERROR", message = $"Cannot find ReferenceNo with Id: {model.TransactionId}." }, JsonRequestBehavior.AllowGet));
            }
            var generalLedger = loGeneralLedger.Source;

            if (model.Status.Equals("1"))
            {
                //update GeneralLedger
                generalLedger.ReferenceNo     = model.TransactionId;
                generalLedger.UserId          = User.Identity.Name;
                generalLedger.Type            = "Prepaid";
                generalLedger.CorrespondingId = wallet.Id;
                generalLedger.Description     = $"{m_applicationName} purchase topup by {User.Identity.Name} for RM{model.TransactionAmount}";
                generalLedger.Amount          = Convert.ToDecimal(model.TransactionAmount);
                generalLedger.ExistingAmount  = Convert.ToDecimal(userDetail.AccountBalance);
                generalLedger.NewAmount       = Convert.ToDecimal(model.TransactionAmount) + Convert.ToDecimal(userDetail.AccountBalance);

                //update UserDetail
                userDetail.AccountBalance = generalLedger.NewAmount;

                using (var session = context.OpenSession())
                {
                    session.Attach(generalLedger);
                    session.Attach(userDetail);
                    await session.SubmitChanges("Default");
                }
                await Task.Delay(1500);

                return(Redirect($"{m_baseUrl}/ost#wallet-history"));
            }
            else
            {
                //fall through
            }

            await Task.Delay(1500);

            return(Redirect($"{m_baseUrl}/ost#wallet-list-all"));
        }