public async Task HandleContinue()
        {
            var orderId = _context.Request.QueryString["orderid"];

            if (String.IsNullOrEmpty(orderId))
            {
                orderId = _context.Request.Form["orderid"];
            }

            ECommerceLog.WriteLog("Continue request received on order id " + orderId);

            using (var data = new DataConnection())
            {
                var order = data.Get <IShopOrder>().SingleOrDefault(o => o.Id == orderId);
                if (order == null)
                {
                    ECommerceLog.WriteLog("No order with id " + orderId);

                    _context.Response.StatusCode = (int)HttpStatusCode.NotFound;

                    return;
                }

                order.WriteLog("continue requested");

                var hasContinued = order.GetLog().Any(l => l.Title == "continue succeeded");
                if (hasContinued)
                {
                    order.WriteLog("debug", "Continue has already succeeded");

                    _context.Response.StatusCode = (int)HttpStatusCode.BadRequest;

                    return;
                }

                var isAuthorized = (PaymentStatus)order.PaymentStatus == PaymentStatus.Authorized;
                if (!isAuthorized)
                {
                    var provider = ResolvePaymentProvider(order.Id);

                    isAuthorized = await provider.IsPaymentAuthorizedAsync(order);
                }

                if (!isAuthorized)
                {
                    order.WriteLog("debug", "Payment isn't authorized");

                    _context.Response.StatusCode = (int)HttpStatusCode.BadRequest;

                    return;
                }

                Receipt(order);

                order.WriteLog("continue succeeded");
            }
        }
        public Task HandleCancel()
        {
            ECommerceLog.WriteLog("Cancel request received");

            var pageUrl = OrderProcessor.HandleCancel(_context);

            RedirectOrIFrame(pageUrl);

            return(Task.FromResult(0));
        }
Esempio n. 3
0
        private bool TryAuthorizeOrder(JObject json, out IShopOrder order)
        {
            var orderId = json["order_id"].Value <string>();

            using (var data = new DataConnection())
            {
                order = data.Get <IShopOrder>().SingleOrDefault(f => f.Id == orderId);
                if (order == null)
                {
                    ECommerceLog.WriteLog("Invalid orderid " + orderId);

                    return(false);
                }

                if (order.PaymentStatus == (int)PaymentStatus.Authorized)
                {
                    order.WriteLog("debug", "Payment is already authorized");

                    return(true);
                }

                var accepted = json["accepted"].Value <bool>();
                if (!accepted)
                {
                    order.WriteLog("debug", "Payment wasn't accepted");

                    return(false);
                }

                var testMode = json["test_mode"].Value <bool>();
                if (testMode && !IsTestMode)
                {
                    order.WriteLog("debug", "Payment was made with a test card but we're not in testmode");

                    return(false);
                }

                var paymentRequest = order.GetPaymentRequest();

                paymentRequest.Accepted                   = true;
                paymentRequest.AuthorizationData          = json.ToString();
                paymentRequest.AuthorizationTransactionId = json["id"].Value <int>().ToString();
                paymentRequest.PaymentMethod              = json["metadata"]["type"].Value <string>();

                data.Update(paymentRequest);

                order.PaymentStatus = (int)PaymentStatus.Authorized;

                data.Update(order);

                order.WriteLog("authorized");

                return(true);
            }
        }
        public Task HandleDefault()
        {
            var orderId = _context.Request.QueryString["orderid"];

            if (String.IsNullOrEmpty(orderId))
            {
                orderId = _context.Request.Form["orderoid"];
            }

            ECommerceLog.WriteLog("Default request received on order id " + orderId);

            using (var data = new DataConnection())
            {
                var order = data.Get <IShopOrder>().SingleOrDefault(o => o.Id == orderId);
                if (order == null)
                {
                    ECommerceLog.WriteLog("No order with id " + orderId);

                    _context.Response.StatusCode = (int)HttpStatusCode.NotFound;

                    return(Task.FromResult(0));
                }

                order.WriteLog("Payment window requested");

                if (order.PaymentStatus == (int)PaymentStatus.Authorized)
                {
                    order.WriteLog("debug", "Order has already been authorized");

                    _context.Response.StatusCode = (int)HttpStatusCode.BadRequest;

                    return(Task.FromResult(0));
                }

                var paymentRequest = order.GetPaymentRequest();
                if (paymentRequest == null)
                {
                    throw new InvalidOperationException($"There is no payment request for order '{orderId}'");
                }

                var provider = ResolvePaymentProvider(order.Id);

                var window = provider.GeneratePaymentWindow(order, paymentRequest, _context.Request.Url);

                HtmlContent(window);
            }

            return(Task.FromResult(0));
        }
        protected virtual async Task <IShopOrder> ResolveOrderAsync(HttpContextBase context)
        {
            var orderId = await ResolveOrderIdFromRequestAsync(context.Request);

            using (var data = new DataConnection())
            {
                var order = data.Get <IShopOrder>().SingleOrDefault(f => f.Id == orderId);
                if (order == null)
                {
                    ECommerceLog.WriteLog("Error, no order with id " + orderId);
                }

                return(order);
            }
        }
Esempio n. 6
0
        protected override async Task <IShopOrder> ResolveOrderAsync(HttpContextBase context)
        {
            //http://tech.quickpay.net/api/callback/

            var input = await GetRequestContentsAsync(context.Request);

            var checkSum = context.Request.Headers.Get("Quickpay-Checksum-Sha256");

            if (checkSum != Sign(input, PrivateKey))
            {
                ECommerceLog.WriteLog("Error validating the checksum");

                return(null);
            }

            var json = (JObject)JsonConvert.DeserializeObject(input);

            return(TryAuthorizeOrder(json, out IShopOrder order) ? order : null);
        }
        public async Task HandleCallback()
        {
            ECommerceLog.WriteLog("Callback request received");

            var orderId = await ResolveOrderIdFromRequestAsync(_context.Request);

            var provider = ResolvePaymentProvider(orderId);

            var order = await provider.HandleCallbackAsync(_context);

            if (order == null)
            {
                ECommerceLog.WriteLog("Callback failed");

                _context.Response.StatusCode = (int)HttpStatusCode.BadRequest;

                return;
            }

            order.WriteLog("callback succeeded");

            ECommerceBackgroundProcess.ProcessOrdersNow();
        }
        public Task HandleDefault()
        {
            var orderId = _context.Request.QueryString["orderid"];

            ECommerceLog.WriteLog("Default request recieved on orderid " + orderId);

            using (var data = new DataConnection())
            {
                var order = data.Get <IShopOrder>().SingleOrDefault(o => o.Id == orderId);
                if (order == null)
                {
                    ECommerceLog.WriteLog("No order with id " + orderId);

                    _context.Response.StatusCode = (int)HttpStatusCode.NotFound;

                    return(Task.FromResult(0));
                }

                order.WriteLog("paymentwindow requested");

                if (order.PaymentStatus == (int)PaymentStatus.Authorized)
                {
                    order.WriteLog("debug", "Order has already been authorized");

                    _context.Response.StatusCode = (int)HttpStatusCode.BadRequest;

                    return(Task.FromResult(0));
                }

                var provider = ResolvePaymentProvider(order.Id);
                var window   = provider.GeneratePaymentWindow(order, _context.Request.Url);

                HtmlContent(window);
            }

            return(Task.FromResult(0));
        }
Esempio n. 9
0
        public PaymentProvider GetProviderInstance(string name)
        {
            return(_providers.GetOrAdd(name, s =>
            {
                var settings = Providers[name];

                var type = Type.GetType(settings.Type);
                if (type == null)
                {
                    return null;
                }

                try
                {
                    return (PaymentProvider)ProvidersHelper.InstantiateProvider(settings, type);
                }
                catch (Exception e)
                {
                    ECommerceLog.WriteLog("Error instantiating provider", e);

                    return null;
                }
            }));
        }