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> PsRequest(string id)
        {
            LoadData <ConsigmentRequest> lo = await GetConsigmentRequest(id);

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

            var item  = lo.Source;
            var model = new PaymentSwitchRequestModel();

            decimal noGstPrice         = 0;
            decimal internationalPrice = 0;
            decimal gstPrice           = 0;

            foreach (var consignment in item.Consignments)
            {
                if (!consignment.Produk.IsInternational)
                {
                    noGstPrice += consignment.Bill.SubTotal3;
                }
                else
                {
                    internationalPrice += consignment.Bill.SubTotal3;
                }
            }

            gstPrice = CustomConsignmentRequestController.GstCalculation(noGstPrice, 2);
            // pickup charge = RM5.00
            // pickup charge gst = RM0.30
            noGstPrice += 5.00m;
            noGstPrice += internationalPrice;
            gstPrice   += 0.30m;

            // required by payment gateway
            model.TransactionId     = item.ReferenceNo;
            model.TransactionAmount = noGstPrice;
            model.TransactionGST    = gstPrice;
            model.PurchaseDate      = DateTime.Now;
            model.Description       = $"{m_applicationName} purchase by {item.ChangedBy} for RM{item.Payment.TotalPrice}";
            model.CallbackUrl       = $"{m_baseUrl}/ost-payment/ps-response"; //temp for testing

            var rijndaelKey   = new RijndaelEnhanced(m_paymentGatewayEncryptionKey);
            var dataToEncrypt = string.Format("{0}|{1}|{2}|{3}|{4}", model.TransactionId, model.TransactionAmount, model.TransactionGST, model.PurchaseDate.ToString("MM/dd/yyyy hh:mm:ss"), model.Description);

            if (!string.IsNullOrEmpty(model.CallbackUrl))
            {
                dataToEncrypt += "|" + model.CallbackUrl;
            }
            var encryptedData = rijndaelKey.Encrypt(dataToEncrypt);

            Response.StatusCode = (int)HttpStatusCode.OK;
            return(Json(new { success = true, status = "OK", id = m_paymentGatewayApplicationId, data = encryptedData, url = $"{m_paymentGatewayBaseUrl}/pay" }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> PsRequestPrepaid(string id)
        {
            var context          = new SphDataContext();
            LoadData <Wallet> lo = await GetWallet(id);

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

            var generalLedger = new GeneralLedger();

            generalLedger.Id = Guid.NewGuid().ToString();

            var     wallet     = lo.Source;
            decimal noGstPrice = 0;
            decimal gstPrice   = 0;
            decimal totalPrice = 0;

            noGstPrice = Convert.ToDecimal(wallet.TotalValue);
            gstPrice   = noGstPrice * Convert.ToDecimal(0.06);
            totalPrice = noGstPrice + gstPrice;

            // required by payment gateway
            var model = new PaymentSwitchRequestModel();

            model.TransactionId     = GenerateCustomRefNo(generalLedger);
            model.TransactionAmount = noGstPrice;
            model.TransactionGST    = gstPrice;
            model.PurchaseDate      = DateTime.Now;
            model.Description       = $"{m_applicationName} purchase topup by {User.Identity.Name} for RM{totalPrice} with Id: ({wallet.WalletCode})";
            model.CallbackUrl       = $"{m_baseUrl}/ost-payment/ps-response-prepaid";

            //insert empty transaction into GL with reference no and type
            generalLedger.ReferenceNo = model.TransactionId;
            generalLedger.Type        = "Prepaid";
            using (var session = context.OpenSession())
            {
                session.Attach(generalLedger);
                await session.SubmitChanges("Default");
            }

            var rijndaelKey   = new RijndaelEnhanced(m_paymentGatewayEncryptionKey);
            var dataToEncrypt = string.Format("{0}|{1}|{2}|{3}|{4}", model.TransactionId, model.TransactionAmount, model.TransactionGST, model.PurchaseDate.ToString("MM/dd/yyyy hh:mm:ss"), model.Description);

            if (!string.IsNullOrEmpty(model.CallbackUrl))
            {
                dataToEncrypt += "|" + model.CallbackUrl;
            }
            var encryptedData = rijndaelKey.Encrypt(dataToEncrypt);

            Response.StatusCode = (int)HttpStatusCode.OK;
            return(Json(new { success = true, status = "OK", id = m_paymentGatewayApplicationId, data = encryptedData, url = $"{m_paymentGatewayBaseUrl}/pay" }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 4
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"));
        }