Example #1
0
        public async Task <ActionResult> CompletePayment()
        {
            string responseContent = Request.Params.ToString();
            Dictionary <string, string> results = _payment.ToDictionary(responseContent);

            Transaction transaction = _payment.GetTransaction(results["PAY_REQUEST_ID"]);

            if (transaction == null)
            {
                return(RedirectToAction("BadRequest", "Home"));
            }
            Dictionary <string, string> validationSet = new Dictionary <string, string>();

            validationSet.Add("PAYGATE_ID", PayGateID);
            validationSet.Add("PAY_REQUEST_ID", results["PAY_REQUEST_ID"]);
            validationSet.Add("TRANSACTION_STATUS", results["TRANSACTION_STATUS"]);
            validationSet.Add("REFERENCE", transaction.REFERENCE);

            if (!_payment.VerifyMd5Hash(validationSet, PayGateKey, results["CHECKSUM"]))
            {
                return(RedirectToAction("BadRequest", "Home"));
            }

            int paymentStatus = int.Parse(results["TRANSACTION_STATUS"]);

            if (paymentStatus == 1)
            {
                await VerifyTransaction(responseContent, transaction.REFERENCE);

                return(RedirectToAction("Index", "Payments"));
            }
            return(RedirectToAction("BadRequest", "Home"));
        }
        public async Task <ActionResult> CompletePayment()
        {
            string responseContent = Request.Params.ToString();
            Dictionary <string, string> results = _payment.ToDictionary(responseContent);

            Transaction transaction = _payment.GetTransaction(results["PAY_REQUEST_ID"]);

            if (transaction == null)
            {
                // Unable to reconsile transaction
                return(RedirectToAction("Failed"));
            }

            // Reorder attributes for MD5 check
            Dictionary <string, string> validationSet = new Dictionary <string, string>();

            validationSet.Add("PAYGATE_ID", PayGateID);
            validationSet.Add("PAY_REQUEST_ID", results["PAY_REQUEST_ID"]);
            validationSet.Add("TRANSACTION_STATUS", results["TRANSACTION_STATUS"]);
            validationSet.Add("REFERENCE", transaction.REFERENCE);

            if (!_payment.VerifyMd5Hash(validationSet, PayGateKey, results["CHECKSUM"]))
            {
                // checksum error
                return(RedirectToAction("Failed"));
            }

            /** Payment Status
             * -2 = Unable to reconsile transaction
             * -1 = Checksum Error
             * 0 = Pending
             * 1 = Approved
             * 2 = Declined
             * 3 = Cancelled
             * 4 = User Cancelled
             */
            int paymentStatus = int.Parse(results["TRANSACTION_STATUS"]);

            if (paymentStatus == 1)
            {
                // Yey, payment approved
                // Do something useful
            }
            // Query paygate transaction details
            // And update user transaction on your database
            await VerifyTransaction(responseContent, transaction.REFERENCE);

            return(RedirectToAction("Complete", new { id = results["TRANSACTION_STATUS"] }));
        }