public IActionResult PDTHandler()
 {
     if (_webHelper.QueryString <string>("FawryRefNo") != null)
     {
         var MerchantRefNo = Convert.ToInt16(_webHelper.QueryString <string>("MerchantRefNo"));
         var order         = _orderService.GetOrderById(MerchantRefNo);
         var OrderStatus   = _webHelper.QueryString <string>("OrderStatus");
         var FawryRefNo    = _webHelper.QueryString <string>("FawryRefNo");
         if (order != null && OrderStatus != null && FawryRefNo != null)
         {
             if (OrderStatus == "NEW")
             {
                 return(RedirectToRoute("CheckoutCompleted", new { orderId = order.Id }));
             }
             else if (OrderStatus == "EXPIRED")
             {
                 _orderProcessingService.CancelOrder(order, false);
             }
             else if (OrderStatus == "PAID")
             {
                 _orderProcessingService.MarkOrderAsPaid(order);
             }
         }
     }
     else
     {
         var MerchantRefNo = Convert.ToInt16(_webHelper.QueryString <string>("merchantRefNum"));
         var order         = _orderService.GetOrderById(MerchantRefNo);
         _orderProcessingService.CancelOrder(order, false);
     }
     return(RedirectToAction("Index", "Home", new { area = "" }));
 }
Esempio n. 2
0
        private void UpdateOrderStatus(Order order, string status)
        {
            status = status.ToLower();

            switch (status)
            {
            case "failed":
            case "revoked":
            {
                //mark order as canceled
                if ((order.PaymentStatus == PaymentStatus.Paid || order.PaymentStatus == PaymentStatus.Authorized) &&
                    _orderProcessingService.CanCancelOrder(order))
                {
                    _orderProcessingService.CancelOrder(order, true);
                }
            }
            break;

            case "ok":
            {
                //mark order as paid
                if (_orderProcessingService.CanMarkOrderAsPaid(order) && status.ToUpper() == "PAID")
                {
                    _orderProcessingService.MarkOrderAsPaid(order);
                }
            }
            break;
            }
        }
        public IActionResult CallbackHandler()
        {
            var reference = _webHelper.QueryString <string>("trxref");

            if (!(_paymentPluginManager.LoadPluginBySystemName("Payments.PaystackStandard") is PaystackStandardPaymentProcessor processor) || !_paymentPluginManager.IsPluginActive(processor))
            {
                throw new NopException("Paystack Standard module cannot be loaded");
            }

            var verificationResponse = processor.VerifyTransaction(reference);
            var order = _orderService.GetOrderByGuid(new Guid(reference));

            if (order == null)
            {
                return(RedirectToAction("Index", "Home", new { area = string.Empty }));
            }
            //else if (order.OrderTotal != verificationResponse.Amount)
            //{
            //    var errorStr = $"Paystack returned an order total { verificationResponse.Amount} that doesn't equal order total {order.OrderTotal}. Order# {order.Id}.";
            //    //log
            //    _logger.Error(errorStr);
            //    //order note
            //    order.OrderNotes.Add(new OrderNote
            //    {
            //        Note = errorStr,
            //        DisplayToCustomer = false,
            //        CreatedOnUtc = DateTime.UtcNow
            //    });
            //    _orderService.UpdateOrder(order);

            //    return RedirectToAction("Index", "Home", new { area = string.Empty });
            //}

            order.OrderNotes.Add(new OrderNote
            {
                Note = verificationResponse.Message,
                DisplayToCustomer = false,
                CreatedOnUtc      = DateTime.UtcNow
            });

            order.AuthorizationTransactionId   = reference;
            order.AuthorizationTransactionCode = verificationResponse.AuthCode;
            _orderService.UpdateOrder(order);

            if (verificationResponse.IsVerified)
            {
                _orderProcessingService.MarkOrderAsPaid(order);
            }
            else
            {
                _logger.Error($"Paystack payment order {reference} failed.", new NopException(verificationResponse.Message));
            }


            return(RedirectToRoute("CheckoutCompleted", new { orderId = order.Id }));
        }
Esempio n. 4
0
        public ActionResult Return(FormCollection form)
        {
            string reference = Request.QueryString["reference"];
            string urlPath   = "https://api.paystack.co/transaction/verify/" + reference;

            HttpClient verify = new HttpClient();

            verify.DefaultRequestHeaders.Clear();
            verify.DefaultRequestHeaders.Add("authorization", "Bearer " + "sk_test_61ebaf98bcc9f047c79f5dfe242dfae8ea43e861");
            verify.DefaultRequestHeaders.Add("accept", "application/json");
            verify.DefaultRequestHeaders.Add("cache-control", "no-cache");
            HttpResponseMessage resp = Task.Run(() => verify.GetAsync(urlPath)).Result;
            string stream            = Task.Run(() => resp.Content.ReadAsStringAsync()).Result;

            dynamic data   = JObject.Parse(stream);
            string  status = data.data.status;
            //string reference_number = data.data.reference;

            var order = _orderService.GetOrderByAuthorizationTransactionIdAndPaymentMethod(reference, "Payment.Paystack");

            if (status == "success")
            {
                _orderProcessingService.MarkOrderAsPaid(order);
                return(RedirectToRoute("CheckoutCompleted", new { orderId = order.Id }));
            }
            else
            {
                return(RedirectToAction("Index", "Home", new { area = "" }));
            }
        }
Esempio n. 5
0
        public ActionResult Return(FormCollection form)
        {
            var processor = _paymentService.LoadPaymentMethodBySystemName("Payments.Assist") as AssistPaymentProcessor;

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

            var order = _orderService.GetOrderById(_webHelper.QueryString <int>("ordernumber"));

            if (order == null || order.Deleted || _workContext.CurrentCustomer.Id != order.CustomerId)
            {
                return(new HttpUnauthorizedResult());
            }

            if (_assistPaymentSettings.AuthorizeOnly)
            {
                if (_orderProcessingService.CanMarkOrderAsAuthorized(order))
                {
                    _orderProcessingService.MarkAsAuthorized(order);
                }
            }
            else
            {
                if (_orderProcessingService.CanMarkOrderAsPaid(order))
                {
                    _orderProcessingService.MarkOrderAsPaid(order);
                }
            }

            return(RedirectToRoute("CheckoutCompleted", new { orderId = order.Id }));
        }
Esempio n. 6
0
        public bool MarkOrderAsPaid(int id)
        {
            //try to get an order with the specified id
            var order = _orderService.GetOrderById(id);

            if (order == null)
            {
                return(false);
            }

            //a vendor does not have access to this functionality
            //if (_workContext.CurrentVendor != null)
            //    return RedirectToAction("Edit", "Order", new { id });

            try
            {
                _orderProcessingService.MarkOrderAsPaid(order);
                //LogEditOrder(order.Id);

                //prepare model
                //var model = _orderModelFactory.PrepareOrderModel(null, order);

                return(true);
            }
            catch (Exception exc)
            {
                return(false);
            }
        }
        private void UpdateOrderPaymentStatus(BaseTransactionResult result, Order order)
        {
            switch (result.TransactionStatus.Value)
            {
            case Enumerations.TransactionStatusCode.Sale:
            case Enumerations.TransactionStatusCode.Capture:     // Capture should not happen here
                order.CaptureTransactionId = result.TransactionNumber;
                _orderService.UpdateOrder(order);
                // Mark order as paid
                if (result.TransactionStatus == Enumerations.TransactionStatusCode.Sale &&
                    _orderProcessingService.CanMarkOrderAsPaid(order))
                {
                    _orderProcessingService.MarkOrderAsPaid(order);
                }
                break;

            case Enumerations.TransactionStatusCode.Authorize:
                order.AuthorizationTransactionId = result.TransactionNumber;
                _orderService.UpdateOrder(order);
                if (_orderProcessingService.CanMarkOrderAsAuthorized(order))
                {
                    _orderProcessingService.MarkAsAuthorized(order);
                }
                break;
            }
        }
Esempio n. 8
0
 public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
 {
     if (_orderProcessingService.CanMarkOrderAsPaid(postProcessPaymentRequest.Order))
     {
         _orderProcessingService.MarkOrderAsPaid(postProcessPaymentRequest.Order);
     }
 }
        /// <summary>
        /// Post process payment (used by payment gateways that require redirecting to a third-party URL)
        /// </summary>
        /// <param name="postProcessPaymentRequest">Payment info required for an order processing</param>
        public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
        {
            switch (_serviceManager.GetPaymentFlowType())
            {
            case PaymentFlowType.Redirection:
                var redirectUrl = _serviceManager.PrepareCheckoutUrl(postProcessPaymentRequest);
                if (string.IsNullOrEmpty(redirectUrl))
                {
                    redirectUrl = _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext)
                                  .RouteUrl(Defaults.OrderDetailsRouteName, new { orderId = postProcessPaymentRequest.Order.Id });
                    _notificationService.ErrorNotification("Something went wrong, contact the store manager");
                }
                _actionContextAccessor.ActionContext.HttpContext.Response.Redirect(redirectUrl);
                return;

            case PaymentFlowType.Inline:
                var customer = _customerService.GetCustomerById(postProcessPaymentRequest.Order.CustomerId);
                if (customer != null)
                {
                    var order         = postProcessPaymentRequest.Order;
                    var transactionId = _genericAttributeService.GetAttribute <string>(customer, Defaults.PaymentTransactionIdAttribute);
                    if (!string.IsNullOrEmpty(transactionId) && _orderProcessingService.CanMarkOrderAsPaid(order))
                    {
                        order.CaptureTransactionId = transactionId;
                        _orderService.UpdateOrder(order);
                        _orderProcessingService.MarkOrderAsPaid(order);

                        _genericAttributeService.SaveAttribute <string>(customer, Defaults.PaymentTransactionIdAttribute, null);
                    }
                }
                return;
            }
        }
        public IActionResult CompletePaymentHandler(AuthorizationResponseModel model)
        {
            // Hard coded orderId, should be taken from response
            // TODO: take parameters from payment response
            int    orderId           = 14563;
            string gateway_reference = "31293";
            string gateway_message   = "Success";

            var order = _orderService.GetOrderById(orderId);

            if (order != null)
            {
                //order note
                order.OrderNotes.Add(new OrderNote
                {
                    Note = "PayBright payment process: " + gateway_message,
                    DisplayToCustomer = false,
                    CreatedOnUtc      = DateTime.UtcNow
                });
                _orderService.UpdateOrder(order);
            }

            //valid
            if (_orderProcessingService.CanMarkOrderAsPaid(order))
            {
                order.AuthorizationTransactionId = gateway_reference;
                _orderService.UpdateOrder(order);

                _orderProcessingService.MarkOrderAsPaid(order);
            }

            // redirect to checkout complete page
            return(RedirectToRoute("CheckoutCompleted", new { orderId = orderId }));
        }
        private bool HandleOrderStatus(Order order, OmniKassa.Model.Enums.PaymentStatus?status)
        {
            if (order != null)
            {
                switch (status)
                {
                case OmniKassa.Model.Enums.PaymentStatus.COMPLETED:
                {
                    if (_orderProcessingService.CanMarkOrderAsPaid(order))
                    {
                        order.CaptureTransactionResult = status.ToString();
                        _orderService.UpdateOrder(order);
                        _orderProcessingService.MarkOrderAsPaid(order);
                    }

                    break;
                }

                // TODO: handle other states as required
                default:
                {
                    break;
                }
                }
                return(true);
            }
            return(false);
        }
        public IActionResult Success()
        {
            var   orderId          = _webHelper.QueryString <string>("x_reference");
            var   oxipayStatus     = _webHelper.QueryString <string>("x_result");
            var   oxipayOrderId    = _webHelper.QueryString <string>("x_gateway_reference");
            var   newPaymentStatus = OxipayHelper.GetPaymentStatus(oxipayStatus, null);
            Order order            = null;

            if (Guid.TryParse(orderId, out Guid orderGuid))
            {
                order = _orderService.GetOrderByGuid(orderGuid);
            }
            if (order != null)
            {
                order.OrderNotes.Add(new OrderNote
                {
                    Note = "Oxipay order ID: " + oxipayOrderId,
                    DisplayToCustomer = false,
                    CreatedOnUtc      = DateTime.UtcNow
                });
                _orderService.UpdateOrder(order);
            }
            switch (newPaymentStatus)
            {
            case PaymentStatus.Pending:
            {}
            break;

            case PaymentStatus.Paid:
            {
                //valid
                if (_orderProcessingService.CanMarkOrderAsPaid(order))
                {
                    _orderProcessingService.MarkOrderAsPaid(order);
                }
                break;
            }

            case PaymentStatus.Voided:
            {
                if (_orderProcessingService.CanVoidOffline(order))
                {
                    _orderProcessingService.VoidOffline(order);
                }
            }
            break;

            default:
                break;
            }
            if (order == null)
            {
                return(RedirectToAction("Index", "Home", new { area = string.Empty }));
            }

            return(RedirectToRoute("CheckoutCompleted", new { orderId = order.Id }));
        }
Esempio n. 13
0
        public void SetOrderPaymentPaid(int orderId, string usernameOrEmail, string userPassword)
        {
            CheckAccess(usernameOrEmail, userPassword);
            if (!_permissionSettings.Authorize(StandardPermissionProvider.ManageOrders))
            {
                throw new ApplicationException("Not allowed to manage orders");
            }

            try
            {
                var order = _orderService.GetOrderById(orderId);
                _orderProcessingService.MarkOrderAsPaid(order);
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message);
            }
        }
Esempio n. 14
0
        public ActionResult IPNHandler(FormCollection form)
        {
            var processor = GetPaymentProcessor();
            TransactionStatus txnStatus;

            if (processor.VerifyIpn(form, out txnStatus))
            {
                var val = GetValue(Constants.OK_INVOICE_KEY, form);
                int orderId;
                if (!String.IsNullOrEmpty(val) && Int32.TryParse(val, out orderId))
                {
                    var order = _orderService.GetOrderById(orderId);

                    if (_orderProcessingService.CanMarkOrderAsPaid(order) && txnStatus == TransactionStatus.Completed)
                    {
                        _orderProcessingService.MarkOrderAsPaid(order);
                    }
                    else if ((order.PaymentStatus == PaymentStatus.Paid ||
                              order.PaymentStatus == PaymentStatus.Authorized) &&
                             _orderProcessingService.CanCancelOrder(order) && txnStatus != TransactionStatus.Completed)
                    {
                        _orderProcessingService.CancelOrder(order, true);
                    }

                    var sb = new StringBuilder();
                    sb.AppendLine("OkPay IPN:");
                    sb.Append(PreparationOrderNote(form));
                    sb.AppendLine("New transaction status: " + txnStatus);

                    order.OrderNotes.Add(new OrderNote
                    {
                        Note = sb.ToString(),
                        DisplayToCustomer = false,
                        CreatedOnUtc      = DateTime.UtcNow
                    });
                    _orderService.UpdateOrder(order);
                }
                else
                {
                    var sb = new StringBuilder();
                    sb.AppendLine("OkPay error: failed order identifier");
                    sb.AppendLine("Transaction status: " + txnStatus);
                    sb.Append(PreparationOrderNote(form));
                    _logger.Error("OkPay IPN failed.", new NopException(sb.ToString()));
                }
            }
            else
            {
                var sb = new StringBuilder();
                sb.AppendLine("Transaction status: " + txnStatus);
                sb.Append(PreparationOrderNote(form));
                _logger.Error("OkPay IPN failed.", new NopException(sb.ToString()));
            }

            return(Content(""));
        }
        private void ApplyApcCallback(string requestMessage)
        {
            var apcMessage = ParseApcMessage(requestMessage);

            if (apcMessage == null)
            {
                _logger.InsertLog(LogLevel.Warning, "Nochex APC Message is invalid", requestMessage);
                return;
            }

            var orderGuid     = apcMessage["custom"];
            var transactionId = apcMessage["transaction_id"];
            var status        = apcMessage["status"];

            if (orderGuid == null || transactionId == null || status == null)
            {
                _logger.InsertLog(LogLevel.Warning, "Nochex APC: Missing required data", requestMessage);
                return;
            }

            var order = _orderService.GetOrderByGuid(new Guid(orderGuid));

            if (order == null)
            {
                _logger.InsertLog(LogLevel.Warning, "Nochex APC: Order not found: " + orderGuid, requestMessage);
                return;
            }

            var orderNote = new OrderNote {
                Note = "Nochex APC Message Received: \r\n\r\n" + BuildFriendlyApcMessage(apcMessage),
                DisplayToCustomer = false,
                CreatedOnUtc      = DateTime.UtcNow
            };

            order.OrderNotes.Add(orderNote);
            _orderService.UpdateOrder(order);

            var currentStatus = _settings.UseTestMode ? "test" : "live";

            if (!string.Equals(status, currentStatus, StringComparison.InvariantCultureIgnoreCase))
            {
                _logger.InsertLog(LogLevel.Warning, "Nochex APC: Received wrong status " + status, requestMessage);
                return;
            }
            if (!_orderProcessingService.CanMarkOrderAsPaid(order))
            {
                _logger.InsertLog(LogLevel.Warning, "Nochex APC: Cannot mark order as paid: " + orderGuid, requestMessage);
                return;
            }

            order.AuthorizationTransactionId = transactionId;
            _orderService.UpdateOrder(order);
            _orderProcessingService.MarkOrderAsPaid(order);
        }
Esempio n. 16
0
        public void ProcessOrderPaid(Order order)
        {
            if (order == null)
            {
                throw new ArgumentNullException(nameof(order));
            }

            if (_orderProcessingService.CanMarkOrderAsPaid(order))
            {
                _orderProcessingService.MarkOrderAsPaid(order);
            }
        }
        public void CheckPayments()
        {
            AccountCredentials credentials = new AccountCredentials(@_pagSeguroPaymentSetting.PagSeguroEmail, @_pagSeguroPaymentSetting.PagSeguroToken);

            foreach (var order in GetPendingOrders())
            {
                if (TransactionIsPaid(GetTransaction(credentials, order.Id.ToString())))
                {
                    _orderProcessingService.MarkOrderAsPaid(order);
                }
            }
        }
Esempio n. 18
0
        public ActionResult Return(string orderId)
        {
            PGResponse     oPgResp = new PGResponse();
            EncryptionUtil lEncUtil = new EncryptionUtil();
            string         respcd = null;
            string         respmsg = null;
            string         astrResponseData = null;
            string         strMerchantId, astrFileName = null;
            string         strKey        = null;
            string         strDigest     = null;
            string         astrsfaDigest = null;

            strMerchantId = "96084546";
            astrFileName  = "c://key//96084546.key";

            if (Request.ServerVariables["REQUEST_METHOD"] == "POST")
            {
                astrResponseData = Request.Form["DATA"];
                strDigest        = Request.Form["EncryptedData"];
                astrsfaDigest    = lEncUtil.getHMAC(astrResponseData, astrFileName, strMerchantId);

                if (strDigest.Equals(astrsfaDigest))
                {
                    oPgResp.getResponse(astrResponseData);
                    respcd  = oPgResp.RespCode;
                    respmsg = oPgResp.RespMessage;
                    if (Int32.Parse(respcd) == 0)
                    {
                        var order = _orderService.GetOrderById(Int32.Parse(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 }));
                    }

                    return(Content("Transaction Decline"));
                }

                else
                {
                    return(RedirectToAction("Index", "Home", new { area = "" }));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Home", new { area = "" }));
            }
        }
        public ActionResult IPN()
        {
            var processor = _paymentService.LoadPaymentMethodBySystemName("Payments.WayForPay") as WayForPayPaymentPlugin;

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

            var data = JsonConvert.DeserializeObject <Payment>(Request.Form[0]);

            if (data == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var orderIdStr = data.OrderReference.Replace(WayForPayConstants.InvoicePrefix, "");
            int orderId;

            if (!int.TryParse(orderIdStr, out orderId))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var order = _orderService.GetOrderById(orderId);

            if (order == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            WriteOrderNote(order, FormatContent(Request.Form[0]));

            var collection = JsonConvert.DeserializeObject <IDictionary <string, object> >(Request.Form[0]);

            if (!_wayForPayService.IsValidSignature(collection, data.MerchantSignature))
            {
                WriteOrderNote(order, "Not valid signature");
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (IsOrderPaid(data.ReasonCode, data.TransactionStatus) && _orderProcessingService.CanMarkOrderAsPaid(order))
            {
                WriteOrderNote(order, $"New payment status: {PaymentStatus.Paid}");
                _orderProcessingService.MarkOrderAsPaid(order);
            }

            WriteAck(data.OrderReference);
            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
Esempio n. 20
0
        public ActionResult IPNHandler()
        {
            var stream  = new StreamReader(_httpContext.Request.InputStream);
            var invoice = JsonConvert.DeserializeObject <Invoice>(stream.ReadToEnd());

            if (invoice == null)
            {
                return(Content(""));
            }

            var id = invoice.Id;

            var bitpay = new BitPayAPI.BitPay(envUrl: BitpayHelper.GetEnvironmentUrl(_bitpaySettings));

            invoice = bitpay.getInvoice(id);

            var order = _orderService.GetOrderById(int.Parse(invoice.PosData));

            if (order == null)
            {
                return(Content(""));
            }

            order.OrderNotes.Add(new OrderNote
            {
                CreatedOnUtc      = DateTime.UtcNow,
                DisplayToCustomer = false,
                Note = $"Bitpay IPN handler. Incoming status is: {invoice.Status}"
            });
            _orderService.UpdateOrder(order);

            switch (invoice.Status)
            {
            case "new":
                break;

            case "paid":
            case "confirmed":
            case "complete":
                if (_orderProcessingService.CanMarkOrderAsPaid(order))
                {
                    _orderProcessingService.MarkOrderAsPaid(order);
                }
                break;

            default:
                break;
            }

            return(Content(""));
        }
Esempio n. 21
0
        //[HttpPost]
        public ActionResult Verify(int ResCod, string Message, int MrchID, string TrmnlID, int InvoiceNo, string ExtraInf, string Token)
        {
            if (ResCod == 0)
            {
                var order = _orderService.GetOrderById(InvoiceNo);
                if (order.AuthorizationTransactionCode == Token)
                {
                    ServicePointManager.ServerCertificateValidationCallback =
                        delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return(true); };

                    var kimial = new KimialPG.KimiaIPGRouteServiceSoapClient(KimialPG.KimiaIPGRouteServiceSoapClient.EndpointConfiguration.KimiaIPGRouteServiceSoap);
                    var result = kimial.ConfirmAsync(new KimialPG.PaymentRequest()
                    {
                        MerchantID = _payPaymentSettings.MerchentId,
                        Password   = _payPaymentSettings.Password,
                        UserName   = _payPaymentSettings.UserName,
                        TerminalID = _payPaymentSettings.TerminalId,
                        Token      = Token
                    }).Result.Body.ConfirmResult;
                    if (result.ResCod == 0)
                    {
                        this._orderService.InsertOrderNote(new OrderNote
                        {
                            OrderId           = order.Id,
                            Note              = result.TraceNo + " " + result.TransNo,
                            DisplayToCustomer = false,
                            CreatedOnUtc      = DateTime.UtcNow,
                        });
                        _orderProcessingService.MarkOrderAsPaid(order);
                        return(RedirectToRoute("CheckoutCompleted", new { orderId = order.Id }));
                    }
                    else
                    {
                        this._orderService.InsertOrderNote(new OrderNote
                        {
                            OrderId           = order.Id,
                            Note              = result.Message,
                            DisplayToCustomer = false,
                            CreatedOnUtc      = DateTime.UtcNow,
                        });
                    }
                    _orderService.UpdateOrder(order);
                }
            }
            return(base.RedirectToAction("Error", "SizPay", new
            {
                ErrorCode = ResCod,
                Message = Message
            }));
        }
Esempio n. 22
0
        private ActionResult UpdateOrderStatus(Order order, string status)
        {
            status = status.ToUpper();
            var textToResponse = "Your order has been paid";

            switch (status)
            {
            case "CANCELED":
            {
                //mark order as canceled
                if ((order.PaymentStatus == PaymentStatus.Paid || order.PaymentStatus == PaymentStatus.Authorized) &&
                    _orderProcessingService.CanCancelOrder(order))
                {
                    _orderProcessingService.CancelOrder(order, true);
                }

                textToResponse = "Your order has been canceled";
            }
            break;

            case "AUTHORIZED":
            {
                //mark order as authorized
                if (_orderProcessingService.CanMarkOrderAsAuthorized(order))
                {
                    _orderProcessingService.MarkAsAuthorized(order);
                }
                textToResponse = "Your order has been authorized";
            }
            break;

            case "PAID":
            {
                //mark order as paid
                if (_orderProcessingService.CanMarkOrderAsPaid(order) && status.ToUpper() == "PAID")
                {
                    _orderProcessingService.MarkOrderAsPaid(order);
                }
            }
            break;

            default:
            {
                return(GetResponse("Unsupported status"));
            }
            }

            return(GetResponse(textToResponse, true));
        }
Esempio n. 23
0
        public ActionResult Callback()
        {
            PayPointCallback payPointPaymentCallback = null;

            try
            {
                using (var streamReader = new StreamReader(HttpContext.Request.InputStream))
                {
                    payPointPaymentCallback = JsonConvert.DeserializeObject <PayPointCallback>(streamReader.ReadToEnd());
                }
            }
            catch (Exception ex)
            {
                _logger.Error("PayPoint callback error", ex);
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }

            if (payPointPaymentCallback.Transaction.Status != PayPointStatus.SUCCESS)
            {
                _logger.Error(string.Format("PayPoint callback error. Transaction is {0}", payPointPaymentCallback.Transaction.Status));
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }

            Guid orderGuid;

            if (!Guid.TryParse(payPointPaymentCallback.Transaction.MerchantRef, out orderGuid))
            {
                _logger.Error("PayPoint callback error. Data is not valid");
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }

            var order = _orderService.GetOrderByGuid(orderGuid);

            if (order == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }

            //paid order
            if (_orderProcessingService.CanMarkOrderAsPaid(order))
            {
                order.CaptureTransactionId = payPointPaymentCallback.Transaction.TransactionId;
                _orderService.UpdateOrder(order);
                _orderProcessingService.MarkOrderAsPaid(order);
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
Esempio n. 24
0
        public ActionResult MerchantReturn(FormCollection form)
        {
            var processor =
                _paymentService.LoadPaymentMethodBySystemName("Payments.eWayHosted") as eWayHostedPaymentProcessor;

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

            var accessPaymentCode = string.Empty;

            if (form["AccessPaymentCode"] != null)
            {
                accessPaymentCode = Request.Form["AccessPaymentCode"];
            }

            //get the result of the transaction based on the unique payment code
            var validationResult = processor.CheckAccessCode(accessPaymentCode);

            if (!string.IsNullOrEmpty(validationResult.ErrorMessage))
            {
                //failed
                return(RedirectToAction("Index", "Home", new { area = "" }));
            }

            if (string.IsNullOrEmpty(validationResult.TrxnStatus) ||
                !validationResult.TrxnStatus.ToLower().Equals("true"))
            {
                //failed
                return(RedirectToAction("Index", "Home", new { area = "" }));
            }
            var orderId = Convert.ToInt32(validationResult.MerchnatOption1);
            var order   = _orderService.GetOrderById(orderId);

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

            if (_orderProcessingService.CanMarkOrderAsPaid(order))
            {
                _orderProcessingService.MarkOrderAsPaid(order);
            }

            return(RedirectToRoute("CheckoutCompleted", new { orderId = order.Id }));
        }
Esempio n. 25
0
        private void ProcessNotify(WxPayData data)
        {
            var notifyData = data;

            if (!notifyData.IsSet("transaction_id"))
            {
                var res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "支付结果中微信订单号不存在");
                Response.Write(res.ToXml());
                Response.End();
            }

            string transactionId = notifyData.GetValue("transaction_id").ToString();

            if (!QueryOrderWithTransactionId(transactionId))
            {
                var res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "订单查询失败");
                Response.Write(res.ToXml());
                Response.End();
            }
            else
            {
                var res = new WxPayData();
                int orderId;
                if (int.TryParse(data.GetValue("out_trade_no").ToString(), out orderId))
                {
                    var order = _orderService.GetOrderById(orderId);
                    if (order != null && _orderProcessingService.CanMarkOrderAsPaid(order))
                    {
                        _orderProcessingService.MarkOrderAsPaid(order);
                        res.SetValue("return_code", "SUCCESS");
                        res.SetValue("return_msg", "OK");
                    }
                    else
                    {
                        res.SetValue("return_code", "FAIL");
                        res.SetValue("return_msg", "无法将订单设为已付");
                    }
                }

                Response.Write(res.ToXml());
                Response.End();
            }
        }
Esempio n. 26
0
        private void OrderCompleted(Notification notification, Order order)
        {
            if (!decimal.TryParse(notification?.Order?.TotalAmount, out var totalAmount))
            {
                return;
            }

            var targetCurrency =
                _currencyService.GetCurrencyByCode(order.CustomerCurrencyCode);

            var orderTotal = PriceInPayUStandard(order.OrderTotal, targetCurrency);

            if (totalAmount == orderTotal)
            {
                if (_orderProcessingService.CanMarkOrderAsPaid(order))
                {
                    order.CaptureTransactionId = notification?.Order?.OrderId;

                    order.OrderNotes.Add(new OrderNote
                    {
                        Note = $"PayU order id {order.CaptureTransactionId}",
                        DisplayToCustomer = false,
                        CreatedOnUtc      = DateTime.UtcNow
                    });

                    _orderService.UpdateOrder(order);
                    _orderProcessingService.MarkOrderAsPaid(order);
                }
            }
            else
            {
                var error =
                    $"PayU order id {notification?.Order?.OrderId}. Order id {order.Id}. PayU returned order total {totalAmount}. Order total should be equal to {order.OrderTotal}.";

                _logger.Error(error);

                order.OrderNotes.Add(new OrderNote
                {
                    Note = error,
                    DisplayToCustomer = false,
                    CreatedOnUtc      = DateTime.UtcNow
                });

                _orderService.UpdateOrder(order);
            }
        }
        public IActionResult SuccessCallbackHandler(IpnModel model)
        {
            var processor = _paymentService.LoadPaymentMethodBySystemName("Payments.Moneris") as MonerisPaymentProcessor;

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

            var parameters = model.Form;

            if (string.IsNullOrEmpty(GetValue("transactionKey", parameters)) || string.IsNullOrEmpty(GetValue("rvar_order_id", parameters)))
            {
                return(RedirectToAction("Index", "Home", new { area = "" }));
            }

            var transactionKey = GetValue("transactionKey", parameters);

            if (!processor.TransactionVerification(transactionKey, out Dictionary <string, string> values))
            {
                return(RedirectToAction("Index", "Home", new { area = "" }));
            }

            var orderIdValue = GetValue("rvar_order_id", parameters);

            if (!int.TryParse(orderIdValue, out int orderId))
            {
                return(RedirectToAction("Index", "Home", new { area = "" }));
            }

            var order = _orderService.GetOrderById(orderId);

            if (order == null || !_orderProcessingService.CanMarkOrderAsPaid(order))
            {
                return(RedirectToAction("Index", "Home", new { area = "" }));
            }

            if (values.ContainsKey("txn_num"))
            {
                order.AuthorizationTransactionId = values["txn_num"];
                _orderService.UpdateOrder(order);
            }

            _orderProcessingService.MarkOrderAsPaid(order);
            return(RedirectToRoute("CheckoutCompleted", new { orderId = order.Id }));
        }
        private void ProcessOrderStateChangeNotification(string xmlData)
        {
            try
            {
                var changeOrder = (OrderStateChangeNotification)EncodeHelper.Deserialize(xmlData, typeof(OrderStateChangeNotification));

                FinancialOrderState orderState = changeOrder.newfinancialorderstate;
                Order order = GetMerchantOrderByGoogleOrderId(changeOrder.googleordernumber);
                if (order != null)
                {
                    string message = string.Format("Order status {0} from Google: Order Number {1}", orderState, changeOrder.googleordernumber);
                    LogMessage(message);

                    //add a note
                    order.OrderNotes.Add(new OrderNote()
                    {
                        Note         = message,
                        CreatedOnUtc = DateTime.UtcNow
                    });
                    _orderService.UpdateOrder(order);

                    if (orderState == FinancialOrderState.CHARGING ||
                        orderState == FinancialOrderState.REVIEWING)
                    {
                    }

                    if (orderState == FinancialOrderState.CHARGEABLE)
                    {
                        _orderProcessingService.MarkAsAuthorized(order);
                    }
                    if (orderState == FinancialOrderState.CHARGED)
                    {
                        _orderProcessingService.MarkOrderAsPaid(order);
                    }
                    if (orderState == FinancialOrderState.CANCELLED || orderState == FinancialOrderState.CANCELLED_BY_GOOGLE)
                    {
                        _orderProcessingService.CancelOrder(order, true);
                    }
                }
            }
            catch (Exception exc)
            {
                LogMessage("processOrderStateChangeNotification Exception: " + exc.Message + ": " + exc.StackTrace);
            }
        }
Esempio n. 29
0
        public ActionResult CallBack(YandexRequestModel model)
        {
            YandexResponceModel responce = _CheckRequest(model, model.action);

            string responseType = "";

            switch (this.Request.Form["action"])
            {
            case "checkOrder":
                responseType = "checkOrderResponse";
                break;

            case "paymentAviso":
                responseType = "paymentAvisoResponse";
                if (responce.code == 0)
                {
                    try
                    {
                        Order order = _orderService.GetOrderById(Convert.ToInt32(model.orderNumber));

                        if (order != null && _orderProcessingService.CanMarkOrderAsPaid(order))
                        {
                            order.AuthorizationTransactionId = model.invoiceId.ToString();
                            _orderService.UpdateOrder(order);

                            _orderProcessingService.MarkOrderAsPaid(order);

                            responce.code = 0;
                        }
                        else
                        {
                            responce.code = 200;
                        }
                    }
                    catch
                    {
                        responce.code = 200;
                    }
                }
                break;
            }

            return(new XmlActionResult(MakeXml(responseType, responce)));
        }
        /// <summary>
        /// Paid
        /// </summary>
        /// <param name="order">Order</param>
        /// <param name="capture">Capture</param>
        private void MarkOrderAsPaid(Core.Domain.Orders.Order order, Capture capture)
        {
            //compare amounts
            var orderTotal = Math.Round(order.OrderTotal, 2);

            if (!decimal.TryParse(capture.Amount?.Value, out var capturedAmount) || capturedAmount != orderTotal)
            {
                return;
            }

            //all is ok, so paid order
            if (_orderProcessingService.CanMarkOrderAsPaid(order))
            {
                order.CaptureTransactionId     = capture.Id;
                order.CaptureTransactionResult = capture.Status;
                _orderService.UpdateOrder(order);
                _orderProcessingService.MarkOrderAsPaid(order);
            }
        }