示例#1
0
        /// <summary>
        /// This method does all the validation, retrieving data and writing to sepa and marking as handle for the given <paramref name="order"/>
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        private RefundQueueElement ProcessRefundOrder(RefundQueueElement order, Func <RefundQueueElement, CustomerInfo> httpReuest,
                                                      Action <SepaRowElement> AddToSepaCollection)
        {
            // Retrieve customer info + refund data for this order
            Task <CustomerInfo> httpRequestToMagento = Task <CustomerInfo> .Factory.StartNew(() => httpReuest(order));

            httpRequestToMagento.Wait();
            CustomerInfo customerData = httpRequestToMagento.Result;

            currentCustomer.ValidationFailures.Clear();

            // Validate customer info + refund data.
            customerData.Validate();

            // Found the correct customer!!!
            if (order.OrderID == currentCustomer.OrderID)
            {
                // if both "processingOrder" and "customerData" objects are validated,
                // Merge "processingOrder" and "customerData" in a SepaRowElement object and write to Sepa document.
                if (order.IsValid && customerData.IsValid)
                {
                    SepaRowElement sepaRow = new SepaRowElement
                    {
                        OrderDescription = order.OrderDescription,
                        OrderID          = currentCustomer.OrderID, // This customer order ID came back from Magento.
                        AccountName      = customerData.AccountName,
                        ConnectorID      = order.ConnectorID,
                        Email            = customerData.Email,
                        IBAN             = customerData.IBAN,
                        RefundAmount     = customerData.RefundAmount,
                        OrderResponseID  = order.OrderResponseID,
                        BIC     = currentCustomer.BIC,
                        Address = currentCustomer.Address,
                        Country = currentCustomer.CountryCode
                    };

                    // Log valid order data
                    if (!test)
                    {
                        TraceListenerObject.TraceInformation("OrderID: {0} description: {1}, from connector: {2}, state: {3} is being added to the Sepa collection to be processed.", order.OrderID, order.OrderDescription, order.ConnectorID, order.IsValid);
                    }

                    // Send to Sepa colllection
                    AddToSepaCollection(sepaRow);
                }
                else // Log failures
                {
                }
            }
            else
            {
                // Logging the wrong customer data is retrieved from Magento.
                if (!test)
                {
                    TraceListenerObject.TraceWarning(string.Format("Request of OrderID {0} has resulted in a Customer info mismatch. Customer info OrderID {1}.", order.OrderID, currentCustomer.OrderID));
                }
            }
            return(order);
        }
 /// <summary>
 /// This method insert an order into the RefundQueueHistory in the Concentrator Database.
 /// </summary>
 /// <param name=""></param>
 /// <returns></returns>
 private void InsertOrderHistory(RefundQueueElement order)
 {
     try
     {
         Database.Execute(InsertIntoRefundQueueHistory, order);
         TraceListenerObject.TraceInformation(string.Format("OrderID: {0} description: {1} with State: {2} is logged into the RefeundQueueHistory table", order.OrderID, order.OrderDescription, order.IsValid));
     }
     catch (Exception e)
     {
         TraceListenerObject.TraceWarning(string.Format("OrderID: {0} description: {1} with State: {2} failed to insert in the RefeundQueueHistory table", order.OrderID, order.OrderDescription, order.IsValid));
     }
 }
 /// <summary>
 /// This method deletes an order by a given orderID from the RefundQueue in the Concentrator Database.
 /// </summary>
 /// <param name=""></param>
 /// <returns></returns>
 private void RemoveRefundOrder(RefundQueueElement order)
 {
     try
     {
         Database.Execute(RemoveFromRefundQueue, order.OrderID, order.ConnectorID);
         TraceListenerObject.TraceInformation(string.Format("OrderID: {0} description: {1} with State: {2} is removed from the RefundQueue table", order.OrderID, order.OrderDescription, order.IsValid));
     }
     catch (Exception e)
     {
         TraceListenerObject.TraceWarning(string.Format("OrderID: {0} description: {1} with State: {2} failed to remove from the RefundQueue table", order.OrderID, order.OrderDescription, order.IsValid));
     }
 }
        /// <summary>
        /// This method validates a specific Refund order.
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        private RefundQueueElement Validate(RefundQueueElement order)
        {
            order.Validate();

            if (!order.IsValid)
            {
                foreach (var errors in order.ValidationFailures)
                {
                    foreach (var member in errors.MemberNames)
                    {
                        TraceListenerObject.TraceInformation(string.Format("Member: {0} from sepa Order: {1} did not pass validation, reason: {2}", member, order.OrderID, errors.ErrorMessage));
                    }
                }
            }
            return(order);
        }
示例#5
0
        /// <summary>
        /// This method looks up all the required customer info for the given <paramref name="order"/>.
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        private CustomerInfo HttpRequest(RefundQueueElement order)
        {
            //CustomerInfo result;

            //var request = (HttpWebRequest)WebRequest.Create(MagentoGetCustomerInfoOnOrderIdUrl);
            //using (var response = request.GetResponse())
            //{
            //  using (var reader = new StreamReader(response.GetResponseStream()))
            //  {
            //    var dataResult = reader.ReadToEnd();
            //    result = JsonConvert.DeserializeObject<CustomerInfo>(dataResult);
            //  }
            //}
            //currentCustomer = result;
            //return result;
            return(currentCustomer);
        }