示例#1
0
        public ActionResult Return(FormCollection form)
        {
            var processor = _paymentService.LoadPaymentMethodBySystemName("Payments.Payu") as PayuPaymentProcessor;

            if (processor == null ||
                !processor.IsPaymentMethodActive(_paymentSettings) || !processor.PluginDescriptor.Installed)
            {
                throw new NopException("Payu module cannot be loaded");
            }


            var    myUtility = new PayuHelper();
            string orderId, merchantId, Amount, productinfo, firstname, email, hash, status, checksum;

            //Assign following values to send it to verifychecksum function.
            if (String.IsNullOrWhiteSpace(_PayuPaymentSettings.Key))
            {
                throw new NopException("Payu key is not set");
            }


            merchantId  = _PayuPaymentSettings.MerchantId.ToString();
            orderId     = form["txnid"];
            Amount      = form["amount"];
            productinfo = form["productinfo"];
            firstname   = form["firstname"];
            email       = form["email"];
            hash        = form["hash"];
            status      = form["status"];

            checksum = myUtility.verifychecksum(merchantId, orderId, Amount, productinfo, firstname, email, status, _PayuPaymentSettings.Key);

            if (checksum == hash)
            {
                if (status == "success")
                {
                    /*
                     *  Here you need to put in the routines for a successful
                     *   transaction such as sending an email to customer,
                     *   setting database status, informing logistics etc etc
                     */

                    var order = _orderService.GetOrderById(Convert.ToInt32(orderId));
                    if (_orderProcessingService.CanMarkOrderAsPaid(order))
                    {
                        _orderProcessingService.MarkOrderAsPaid(order);
                    }

                    //Thank you for shopping with us. Your credit card has been charged and your transaction is successful
                    return(RedirectToRoute("CheckoutCompleted", new { orderId = order.Id }));
                }

                else
                {
                    /*
                     * Here you need to put in the routines for a failed
                     * transaction such as sending an email to customer
                     * setting database status etc etc
                     */

                    return(RedirectToAction("Index", "Home", new { area = "" }));
                }
            }


            else
            {
                /*
                 *  Here you need to simply ignore this and dont need
                 *  to perform any operation in this condition
                 */

                return(Content("Security Error. Illegal access detected"));
            }
        }
        /*
         *
         * [NonAction]
         * public override IList<string> ValidatePaymentForm(FormCollection form)
         * {
         *  var warnings = new List<string>();
         *  return warnings;
         * }
         *
         * [NonAction]
         * public override ProcessPaymentRequest Ge                                                                                                                                                                                         tPaymentInfo(FormCollection form)
         * {
         *  var paymentInfo = new ProcessPaymentRequest();
         *  return paymentInfo;
         * }
         */

        //[ValidateInput(false)]
        public async Task <IActionResult> Return(IpnModel model)
        {
            try
            {
                /*
                 * var processor = _paymentService.LoadPaymentMethodBySystemName("Payments.Payu") as PayuPaymentProcessor;
                 * if (processor == null ||
                 *  !processor.IsPaymentMethodActive(_paymentSettings) || !processor.PluginDescriptor.Installed)
                 *  throw new NopException("Payu module cannot be loaded");
                 *
                 */
                var    myUtility = new PayuHelper();
                string orderId, merchantId, amount, productinfo, firstname, email, hash, status, checksum;

                //Assign following values to send it to verifychecksum function.
                if (String.IsNullOrWhiteSpace(_payuPaymentSettings.Key))
                {
                    throw new NopException("Payu key is not set");
                }


                merchantId  = _payuPaymentSettings.MerchantId.ToString();
                orderId     = model.Form["txnid"];
                amount      = model.Form["amount"];
                productinfo = model.Form["productinfo"];
                firstname   = model.Form["firstname"];
                email       = model.Form["email"];
                hash        = model.Form["hash"];
                status      = model.Form["status"];

                checksum = myUtility.verifychecksum(merchantId, orderId, amount, productinfo, firstname, email, status, _payuPaymentSettings.Key);

                if (checksum == hash)
                {
                    if (status == "success")
                    {
                        /*
                         *  Here you need to put in the routines for a successful
                         *   transaction such as sending an email to customer,
                         *   setting database status, informing logistics etc etc
                         */

                        var order = await _orderService.GetOrderByIdAsync(Convert.ToInt32(orderId));

                        if (_orderProcessingService.CanMarkOrderAsPaid(order))
                        {
                            await _orderProcessingService.MarkOrderAsPaidAsync(order);

                            var sb = new StringBuilder();
                            sb.AppendLine("PayU IPN:");
                            foreach (var v in model.Form)
                            {
                                sb.AppendLine(v.Key + ": " + v.Value);
                            }
                            //order note
                            //OrderNoteAdd
                            await _orderService.InsertOrderNoteAsync(new OrderNote
                            {
                                OrderId           = order.Id,
                                Note              = sb.ToString(),
                                DisplayToCustomer = false,
                                CreatedOnUtc      = DateTime.UtcNow
                            });

                            await _orderService.UpdateOrderAsync(order);
                        }

                        //Thank you for shopping with us. Your credit card has been charged and your transaction is successful
                        return(RedirectToRoute("CheckoutCompleted", new { orderId = order.Id }));
                    }

                    else
                    {
                        /*
                         *  Here you need to put in the routines for a failed
                         *  transaction such as sending an email to customer
                         *  setting database status etc etc
                         */

                        return(RedirectToAction("Index", "Home", new { area = "" }));
                    }
                }


                else
                {
                    /*
                     *  Here you need to simply ignore this and dont need
                     *  to perform any operation in this condition
                     */

                    return(Content("Security Error. Illegal access detected"));
                }
            }
            catch (Exception ex)
            {
                return(Content("Error Occured :" + ex.Message));
            }
        }
示例#3
0
        public ActionResult ReturnDistributedOrder(FormCollection form)
        {
            this.form = form;
            var processor = _paymentService.LoadPaymentMethodBySystemName("Payments.Payu") as PayuPaymentProcessor;

            if (processor == null ||
                !processor.IsPaymentMethodActive(_paymentSettings) || !processor.PluginDescriptor.Installed)
            {
                throw new NopException("Payu module cannot be loaded");
            }


            var    myUtility = new PayuHelper();
            string orderId, merchantId, Amount, productinfo, firstname, email, hash, status, checksum;

            //Assign following values to send it to verifychecksum function.
            if (String.IsNullOrWhiteSpace(_PayuPaymentSettings.Key))
            {
                throw new NopException("Payu key is not set");
            }


            merchantId  = _PayuPaymentSettings.MerchantId.ToString();
            orderId     = form["txnid"];
            Amount      = form["amount"];
            productinfo = form["productinfo"];
            firstname   = form["firstname"];
            email       = form["email"];
            hash        = form["hash"];
            status      = form["status"];



            checksum = myUtility.verifychecksum(merchantId, orderId, Amount, productinfo, firstname, email, status, _PayuPaymentSettings.Key);
            if (checksum == hash)
            {
                if (status == "success")
                {
                    /*
                     *  Here you need to put in the routines for a successful
                     *   transaction such as sending an email to customer,
                     *   setting database status, informing logistics etc etc
                     */

                    var orderTransactinDetail = _orderService.GetOrderByTxnId(new Guid(orderId));
                    var order = _orderService.GetOrderById(orderTransactinDetail.OrderId);
                    orderTransactinDetail.PaymentStatusId = (int)PaymentStatus.Paid;
                    decimal amountpaid = 0;
                    foreach (var paymentInfo in order.OrderTransactionDetailItems)
                    {
                        if (paymentInfo.PaymentStatusId == (int)PaymentStatus.Paid)
                        {
                            amountpaid = amountpaid + paymentInfo.TransactionAmount;
                        }
                    }
                    order.TotalTransactionAmount = amountpaid;

                    if (order.OrderStatus == Core.Domain.Orders.OrderStatus.Booked)
                    {
                        order.OrderStatus = Core.Domain.Orders.OrderStatus.Confirmed;
                    }
                    else if (order.OrderStatus == Core.Domain.Orders.OrderStatus.Confirmed)
                    {
                        order.OrderStatus = Core.Domain.Orders.OrderStatus.OrderPaymentComplete;
                    }

                    _orderService.UpdateOrder(order);
                    _orderService.UpdateOrderTransactionDetail(orderTransactinDetail);

                    //Thank you for shopping with us. Your credit card has been charged and your transaction is successful
                    return(RedirectToRoute("CheckoutCompleted", new { orderId = order.Id }));
                }

                else
                {
                    /*
                     *  Here you need to put in the routines for a failed
                     *  transaction such as sending an email to customer
                     *  setting database status etc etc
                     */

                    return(RedirectToAction("Index", "Home", new { area = "" }));
                }
            }


            else
            {
                /*
                 *  Here you need to simply ignore this and dont need
                 *  to perform any operation in this condition
                 */

                return(Content("Security Error. Illegal Access Detected"));
            }
        }
        public ActionResult ReturnDistributedOrder(FormCollection form)
        {
            this.form = form;
            var processor = _paymentService.LoadPaymentMethodBySystemName("Payments.Payu") as PayuPaymentProcessor;
            if (processor == null ||
                !processor.IsPaymentMethodActive(_paymentSettings) || !processor.PluginDescriptor.Installed)
                throw new NopException("Payu module cannot be loaded");


            var myUtility = new PayuHelper();
            string orderId, merchantId, Amount, productinfo, firstname, email, hash, status, checksum;

            //Assign following values to send it to verifychecksum function.
            if (String.IsNullOrWhiteSpace(_PayuPaymentSettings.Key))
                throw new NopException("Payu key is not set");


            merchantId = _PayuPaymentSettings.MerchantId.ToString();
            orderId = form["txnid"];
            Amount = form["amount"];
            productinfo = form["productinfo"];
            firstname = form["firstname"];
            email = form["email"];
            hash = form["hash"];
            status = form["status"];



            checksum = myUtility.verifychecksum(merchantId, orderId, Amount, productinfo, firstname, email, status, _PayuPaymentSettings.Key);
            if (checksum == hash)
            {

                if (status == "success")
                {
                    /* 
                        Here you need to put in the routines for a successful 
                         transaction such as sending an email to customer,
                         setting database status, informing logistics etc etc
                    */

                    var orderTransactinDetail = _orderService.GetOrderByTxnId(new Guid(orderId));
                    var order = _orderService.GetOrderById(orderTransactinDetail.OrderId);
                    orderTransactinDetail.PaymentStatusId = (int)PaymentStatus.Paid;
                    decimal amountpaid = 0;
                    foreach (var paymentInfo in order.OrderTransactionDetailItems)
                    {
                        if (paymentInfo.PaymentStatusId == (int)PaymentStatus.Paid)
                        amountpaid = amountpaid + paymentInfo.TransactionAmount;
                    }
                    order.TotalTransactionAmount = amountpaid;

                    if (order.OrderStatus == Core.Domain.Orders.OrderStatus.Booked)
                    {
                        order.OrderStatus = Core.Domain.Orders.OrderStatus.Confirmed;
                    }
                    else if (order.OrderStatus == Core.Domain.Orders.OrderStatus.Confirmed)
                    {
                        order.OrderStatus = Core.Domain.Orders.OrderStatus.OrderPaymentComplete;
                    }

                    _orderService.UpdateOrder(order);
                    _orderService.UpdateOrderTransactionDetail(orderTransactinDetail);

                    //Thank you for shopping with us. Your credit card has been charged and your transaction is successful
                    return RedirectToRoute("CheckoutCompleted", new { orderId = order.Id });
                }

                else
                {
                    /*
                        Here you need to put in the routines for a failed
                        transaction such as sending an email to customer
                        setting database status etc etc
                    */

                    return RedirectToAction("Index", "Home", new { area = "" });

                }

            }


            else
            {
                /*
                    Here you need to simply ignore this and dont need
                    to perform any operation in this condition
                */

                return Content("Security Error. Illegal Access Detected");
            }
        }