Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
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));
        }