Example #1
0
        private void ProcessStatusCallback(string orderCheck, Payment payment, SppContainer <Order> orderStatus)
        {
            if (orderCheck == orderStatus.Data.ClientReference)
            {
                var isStatusCallbackProperty = payment.PaymentProperties.SingleOrDefault(x => x.Key == "isStatusCallback");
                if (isStatusCallbackProperty != null)
                {
                    payment.RemovePaymentProperty(isStatusCallbackProperty);
                }

                payment.PaymentStatus = GetSchibstedUtil(payment.PaymentMethod).GetPaymentStatusFromOrderStatus(orderStatus.Data.Status);

                var orderService = new OrderService();

                switch (payment.PaymentStatus.PaymentStatusId)
                {
                case (int)PaymentStatusCode.Acquired:
                    orderService.ChangeOrderStatus(payment.PurchaseOrder, OrderStatus.Get((int)OrderStatusCode.CompletedOrder));
                    break;

                case (int)PaymentStatusCode.Cancelled:
                    orderService.ChangeOrderStatus(payment.PurchaseOrder, OrderStatus.Get((int)OrderStatusCode.Cancelled));
                    break;

                case (int)PaymentStatusCode.Refunded:
                    orderService.ChangeOrderStatus(payment.PurchaseOrder, OrderStatus.Get((int)OrderStatusCode.Cancelled));
                    break;
                }

                if (!string.IsNullOrEmpty(payment["nextChangedOrders"]))
                {
                    var changedOrders = payment["nextChangedOrders"].Split(',');
                    var nextOrder     = changedOrders.FirstOrDefault();

                    if (nextOrder != null)
                    {
                        var nextPayment = Payment.SingleOrDefault(x => x.TransactionId == changedOrders.FirstOrDefault());
                        if (nextPayment != null)
                        {
                            nextPayment["isStatusCallback"]  = "true";
                            nextPayment["nextChangedOrders"] = string.Join(",", changedOrders.Where(x => x != nextOrder));
                            ProcessCallback(nextPayment);
                        }
                    }
                }
            }
        }
Example #2
0
        private void ProcessOrderPayment(string schibstedOrderId, string orderCheck, Payment payment, SppContainer <Order> orderStatus)
        {
            var    paymentMethod = payment.PaymentMethod;
            string cancelUrl     = paymentMethod.DynamicProperty <string>().CancelUrl;
            string acceptUrl     = paymentMethod.DynamicProperty <string>().AcceptUrl;

            // Save order id on payment
            payment.TransactionId = schibstedOrderId;

            // Compare the checksum, and set payment status
            if (orderCheck != orderStatus.Data.ClientReference && (orderStatus.Data.ClientReference != null && payment.PurchaseOrder.OrderTotal > 0))
            {
                throw new SecurityException("Checksum mismatch");
            }

            // Process payment
            var schibstedUtil = GetSchibstedUtil(payment.PaymentMethod);

            payment.PaymentStatus = schibstedUtil.GetPaymentStatusFromOrderStatus(orderStatus.Data.Status);

            Uri redirectUrl;

            if (payment.PaymentStatus != PaymentStatus.Get((int)PaymentStatusCode.Declined))
            {
                ProcessPaymentRequest(new PaymentRequest(payment.PurchaseOrder, payment));

                // Changing order status to completed, if necessary
                if (payment.PaymentStatus == PaymentStatus.Get((int)PaymentStatusCode.Acquired))
                {
                    new OrderService().ChangeOrderStatus(
                        payment.PurchaseOrder,
                        OrderStatus.Get((int)OrderStatusCode.CompletedOrder));
                }

                // Redirecting to the confirmation page
                redirectUrl = new Uri(_absoluteUrlService.GetAbsoluteUrl(acceptUrl));
            }
            else
            {
                redirectUrl = new Uri(_absoluteUrlService.GetAbsoluteUrl(cancelUrl));
            }

            redirectUrl = redirectUrl.AddOrderGuidParameter(payment.PurchaseOrder)
                          .AddQueryStringParameter("order_id", schibstedOrderId)
                          .AddQueryStringParameter("code", HttpContext.Current.Request["code"]);

            HttpContext.Current.Response.Redirect(redirectUrl.AbsoluteUri);
        }