Ejemplo n.º 1
0
        public async Task <ActionResult <CancelOrderResponse> > Cancel([FromRoute] CancelOrderRequest request)
        {
            _logger.LogInformation($"Cancel order service call for {request.OrderNumber}...");
            var response = new CancelOrderResponse();

            try
            {
                var order = await _orderProcessingService.GetOrderAsync(request.OrderNumber);

                await _orderProcessingService.CancelOrderAsync(order);

                response.OperationSucceded = true;
            }
            catch (OrderNotFoundException ex)
            {
                _logger.LogWarning($"{ex.Message}");
                return(NotFound(ex.Message));
            }
            catch (ValidationException ex)
            {
                _logger.LogWarning($"Validations failures: {ex.Message}");
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Exception occured while canceling order: {ex.Message} {ex.StackTrace}");
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
            return(Ok(response));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CancelOrder(int id)
        {
            var order = await _orderService.GetOrderByIdAsync(id);

            if (order == null)
            {
                return(Ok(new { success = false, message = await _localizationService.GetResourceAsync("Order.Cancelled.Failed") }));
            }

            //try to get an customer with the order id
            var customer = await _customerService.GetCustomerByIdAsync(order.CustomerId);

            if (customer == null)
            {
                return(Ok(new { success = false, message = await _localizationService.GetResourceAsync("customer.NotFound") }));
            }

            await _orderProcessingService.CancelOrderAsync(order, true);

            await LogEditOrderAsync(order.Id);

            if (customer.OrderStatusNotification)
            {
                var expoSDKClient = new PushApiClient();
                var pushTicketReq = new PushTicketRequest()
                {
                    PushTo = new List <string>()
                    {
                        customer.PushToken
                    },
                    PushTitle = await _localizationService.GetResourceAsync("PushNotification.OrderCancelTitle"),
                    PushBody  = await _localizationService.GetResourceAsync("PushNotification.OrderCancelBody")
                };
                var result = await expoSDKClient.PushSendAsync(pushTicketReq);
            }

            return(Ok(new { success = true, message = await _localizationService.GetResourceAsync("Order.Cancelled.Successfully") }));
        }
Ejemplo n.º 3
0
        public ActionResult Return()
        {
            var processor = _paymentPluginManager.LoadPluginBySystemNameAsync("Payments.Paytm").Result as PaytmPaymentProcessor;

            if (processor == null || !_paymentPluginManager.IsPluginActive(processor) || !processor.PluginDescriptor.Installed)
            {
                throw new NopException("Paytm module cannot be loaded");
            }


            var    myUtility = new PaytmHelper();
            string orderId, amount, authDesc, resCode;
            bool   checkSumMatch = false;

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

            string workingKey    = _paytmPaymentSettings.MerchantKey;
            string paytmChecksum = null;

            Dictionary <string, string> parameters = new Dictionary <string, string>();

            if (Request.Form.Keys.Count > 0)
            {
                foreach (string key in Request.Form.Keys)
                {
                    if (Request.Form[key].Contains("|"))
                    {
                        parameters.Add(key.Trim(), "");
                    }
                    else
                    {
                        parameters.Add(key.Trim(), Request.Form[key]);
                    }
                }

                if (parameters.ContainsKey("CHECKSUMHASH"))
                {
                    paytmChecksum = parameters["CHECKSUMHASH"];
                    parameters.Remove("CHECKSUMHASH");
                }


                if (!string.IsNullOrEmpty(paytmChecksum) && Checksum.verifySignature(parameters, workingKey, paytmChecksum))
                {
                    checkSumMatch = true;
                }
            }

            orderId  = parameters["ORDERID"];
            amount   = parameters["TXNAMOUNT"];
            resCode  = parameters["RESPCODE"];
            authDesc = parameters["STATUS"];



            var order = _orderService.GetOrderByCustomOrderNumberAsync(orderId).Result;

            if (checkSumMatch == true)
            {
                if (resCode == "01" && authDesc == "TXN_SUCCESS")
                {
                    if (TxnStatus(orderId, order.OrderTotal.ToString("0.00")))
                    {
                        if (_orderProcessingService.CanMarkOrderAsPaid(order))
                        {
                            _orderProcessingService.MarkOrderAsPaidAsync(order);
                        }
                        return(RedirectToRoute("CheckoutCompleted", new { orderId = order.Id }));
                    }
                    else
                    {
                        return(Content("Amount Mismatch"));
                    }
                }
                else if (authDesc == "TXN_FAILURE")
                {
                    _orderProcessingService.CancelOrderAsync(order, false);
                    order.OrderStatus = OrderStatus.Cancelled;
                    _orderService.UpdateOrderAsync(order);
                    return(RedirectToRoute("OrderDetails", new { orderId = order.Id }));
                }
                else
                {
                    return(Content("Security Error. Illegal access detected"));
                }
            }
            else if (string.IsNullOrEmpty(paytmChecksum))
            {
                return(Content("Please Contact Customer Care"));
            }
            else
            {
                return(Content("Security Error. Illegal access detected, Checksum failed"));
            }
        }
        //public IActionResult PayGateNotifyHandler(IFormCollection form)
        public async void PayGateNotifyHandler(IFormCollection form)
        {
            /**
             * Enable IPN if it is set
             */
            await Response.WriteAsync("OK");

            var  reference = Request.Query["pgnopcommerce"];
            bool isPaid;

            await _logger.InformationAsync("PayGateNotifyHandler start. Order no.: " + reference);

            //Order order = _orderService.GetOrderById(Int32.Parse(Request.Query["pgnopcommerce"]));
            Order order = await _orderService.GetOrderByIdAsync(Int32.Parse(reference));

            int orderId = 0;

            if (order != null)
            {
                orderId = order.Id;
            }
            await _logger.InformationAsync("PayGateNotifyHandler: Order Payment Status: " + order.PaymentStatus);

            isPaid = order.PaymentStatus == PaymentStatus.Paid ? true : false;

            if (!isPaid)
            {
                var sBuilder          = new StringBuilder();
                var query_status      = PaymentStatus.Pending;
                var payrequestId      = "";
                var transactionStatus = "";

                var testMode      = _payGatePaymentSettings.TestMode;
                var paygateId     = "10011072130";
                var encryptionKey = "secret";
                if (!testMode)
                {
                    paygateId     = _payGatePaymentSettings.PayGateID;
                    encryptionKey = _payGatePaymentSettings.EncryptionKey;
                }

                //Validate checksum for the posted form fields
                var formData    = new NameValueCollection();
                var formDataJS  = "";
                var checkstring = "";

                foreach (var entry in form)
                {
                    var key = entry.Key;
                    var val = entry.Value;
                    formData[key] = val;
                    if (key != "CHECKSUM")
                    {
                        checkstring += val;
                        formDataJS  += key + "=" + val + "&";
                    }
                }

                await _logger.InformationAsync("PayGateNotifyHandler: POST: " + formDataJS);

                var checksum = formData["CHECKSUM"];
                checkstring += encryptionKey;

                var ourChecksum = new PayGateHelper().CalculateMD5Hash(checkstring);
                if (ourChecksum.Equals(checksum, StringComparison.OrdinalIgnoreCase))
                {
                    var trans_status = formData["TRANSACTION_STATUS"];
                    transactionStatus = trans_status;
                    var query_status_desc = "";
                    payrequestId = formData["PAY_REQUEST_ID"];
                    switch (trans_status)
                    {
                    case "1":
                        query_status      = PaymentStatus.Paid;
                        query_status_desc = "Approved";
                        break;

                    case "2":
                        query_status      = PaymentStatus.Voided;
                        query_status_desc = "Declined";
                        break;

                    case "4":
                        query_status      = PaymentStatus.Voided;
                        query_status_desc = "Cancelled By Customer with back button on payment page";
                        break;

                    case "0":
                        query_status      = PaymentStatus.Voided;
                        query_status_desc = "Not Done";
                        break;

                    default:
                        break;
                    }

                    sBuilder.AppendLine("PayGate Notify Handler");
                    sBuilder.AppendLine("PayGate Query Data");
                    sBuilder.AppendLine("=======================");
                    sBuilder.AppendLine("PayGate Transaction_Id: " + formData["TRANSACTION_ID"]);
                    sBuilder.AppendLine("PayGate Status Desc: " + query_status_desc);
                    sBuilder.AppendLine("");

                    //order note
                    await _orderService.InsertOrderNoteAsync(new OrderNote
                    {
                        OrderId           = orderId,
                        Note              = sBuilder.ToString(),//sbbustring.Format("Order status has been changed to {0}", PaymentStatus.Paid),
                        DisplayToCustomer = false,
                        CreatedOnUtc      = DateTime.UtcNow
                    });

                    await _orderService.UpdateOrderAsync(order);

                    //load settings for a chosen store scope
                    var storeScope             = this.GetActiveStoreScopeConfiguration(_storeService, _workContext);
                    var payGatePaymentSettings = _settingService.LoadSettingAsync <PayGatePaymentSettings>(storeScope);

                    //mark order as paid
                    if (query_status == PaymentStatus.Paid)
                    {
                        if (_orderProcessingService.CanMarkOrderAsPaid(order))
                        {
                            order.AuthorizationTransactionId = payrequestId;
                            await _orderService.UpdateOrderAsync(order);

                            await _orderProcessingService.MarkOrderAsPaidAsync(order);
                        }
                        await _orderService.UpdateOrderAsync(order);

                        RedirectToRoute("CheckoutCompleted", new { orderId = order.Id });
                    }
                    else
                    {
                        order.AuthorizationTransactionId = payrequestId;
                        OrderNote note = new OrderNote();
                        note.OrderId           = orderId;
                        note.CreatedOnUtc      = DateTime.Now;
                        note.DisplayToCustomer = true;
                        note.Note = "Payment failed with the following description: " + transactionStatus;
                        if (_orderProcessingService.CanCancelOrder(order))
                        {
                            await _orderProcessingService.CancelOrderAsync(order, false);
                        }
                        await _orderService.InsertOrderNoteAsync(note);

                        await _orderService.UpdateOrderAsync(order);

                        RedirectToRoute("OrderDetails", new { orderId = order.Id.ToString().Trim() });
                    }
                }
                else
                {
                    await _logger.ErrorAsync("PayGateNotifyHandler: Checksum mismatch: " + ourChecksum + " : " + checksum);
                }
            }
        }