public override bool Execute(OrderTaskContext context)
 {
     if (context.Inputs["PreviousPaymentStatus"] != null)
     {
         int val = 0;
         if (int.TryParse(context.Inputs["PreviousPaymentStatus"].Value, out val))
         {
             if ((val == (int)Orders.OrderPaymentStatus.Paid) && (context.Order.PaymentStatus != Orders.OrderPaymentStatus.Paid))
             {
                 string statusCode = Orders.OrderStatusCode.Received;
                 Orders.OrderStatusCode orderStatus = Orders.OrderStatusCode.FindByBvin(statusCode);
                 if (orderStatus != null && orderStatus.Bvin != string.Empty)
                 {
                     context.Order.StatusCode = orderStatus.Bvin;
                     context.Order.StatusName = orderStatus.StatusName;
                 }
                 else
                 {
                     EventLog.LogEvent("Change Order Status When Payment Removed", "Could not find order status with id of " + statusCode, EventLogSeverity.Error);
                 }
             }
         }
     }
     return(true);
 }
Exemple #2
0
 public override bool Execute(OrderTaskContext context)
 {
     if ((context.Order.ShippingStatus == Orders.OrderShippingStatus.FullyShipped) && (context.Order.PaymentStatus == Orders.OrderPaymentStatus.Paid))
     {
         Orders.OrderStatusCode orderStatus = Orders.OrderStatusCode.FindByBvin(OrderStatusCode.Completed);
         if (orderStatus != null)
         {
             context.Order.StatusCode = orderStatus.Bvin;
             context.Order.StatusName = orderStatus.StatusName;
         }
     }
     return(true);
 }
Exemple #3
0
        public override bool Execute(OrderTaskContext context)
        {
            if (context.Order.IsPlaced)
            {
                return(true);
            }
            if (context.Order.Items.Count == 0)
            {
                context.Errors.Add(new WorkflowMessage("Order already placed.", Content.SiteTerms.GetTerm(Content.SiteTermIds.OrderAlreadyPlaced), true));
                return(false);
            }



            context.Order.IsPlaced       = true;
            context.Order.TimeOfOrderUtc = DateTime.UtcNow;
            //if (!WebAppSettings.DisableInventory) {
            List <string> errors = new List <string>();

            if (!context.MTApp.OrdersReserveInventoryForAllItems(context.Order, errors))
            {
                foreach (string item in errors)
                {
                    context.Errors.Add(new WorkflowMessage("Stock Too Low", item, true));
                }
                return(false);
            }
            //}

            if (context.MTApp.CurrentRequestContext.RoutingContext.HttpContext != null)
            {
                Orders.OrderNote note = new Orders.OrderNote();
                note.IsPublic = false;
                note.Note     = "Customer IP: " + context.MTApp.CurrentRequestContext.RoutingContext.HttpContext.Request.UserHostAddress;
                note.Note    += "<br> Customer Host: " + context.MTApp.CurrentRequestContext.RoutingContext.HttpContext.Request.UserHostName;
                note.Note    += "<br> Browser: " + context.MTApp.CurrentRequestContext.RoutingContext.HttpContext.Request.UserAgent;
                context.Order.Notes.Add(note);
            }

            Orders.OrderStatusCode c = Orders.OrderStatusCode.FindByBvin(Orders.OrderStatusCode.Received);
            if (c != null)
            {
                context.Order.StatusName  = c.StatusName;
                context.Order.StatusCode  = c.Bvin;
                context.Order.AffiliateID = context.MTApp.ContactServices.GetValidAffiliateId(context.MTApp).ToString();
            }
            return(true);
        }
        public override bool Execute(OrderTaskContext context)
        {
            bool result = true;

            if (context.Order != null)
            {
                Security.FraudCheckData d = new Security.FraudCheckData();
                PopulateFraudData(d, context);

                FraudScorer scorer = new FraudScorer(context.MTApp.CurrentRequestContext);

                context.Order.FraudScore = scorer.ScoreData(d);

                if (context.Order.FraudScore >= 5)
                {
                    Orders.OrderStatusCode s = Orders.OrderStatusCode.FindByBvin(Orders.OrderStatusCode.OnHold);
                    context.Order.StatusCode = s.Bvin;
                    context.Order.StatusName = s.StatusName;
                    context.MTApp.OrderServices.Orders.Update(context.Order);
                }

                if (d.Messages.Count > 0)
                {
                    Orders.OrderNote n = new Orders.OrderNote();
                    n.IsPublic = false;
                    n.Note     = "Fraud Check Failed";
                    foreach (string m in d.Messages)
                    {
                        n.Note += " | " + m;
                    }
                    context.Order.Notes.Add(n);
                }

                context.MTApp.OrderServices.Orders.Update(context.Order);
            }

            return(result);
        }
Exemple #5
0
        public override bool Execute(OrderTaskContext context)
        {
            bool result = true;

            if (context.MTApp.OrderServices.PaymentSummary(context.Order).AmountDue > 0)
            {
                foreach (OrderTransaction p in context.MTApp.OrderServices.Transactions.FindForOrder(context.Order.bvin))
                {
                    List <OrderTransaction> transactions = context.MTApp.OrderServices.Transactions.FindForOrder(context.Order.bvin);

                    if (p.Action == MerchantTribe.Payment.ActionType.PayPalExpressCheckoutInfo)
                    {
                        // if we already have an auth or charge on the card, skip
                        if (p.HasSuccessfulLinkedAction(MerchantTribe.Payment.ActionType.PayPalHold, transactions) ||
                            p.HasSuccessfulLinkedAction(MerchantTribe.Payment.ActionType.PayPalCharge, transactions))
                        {
                            continue;
                        }

                        try
                        {
                            Orders.OrderPaymentManager payManager = new OrderPaymentManager(context.Order,
                                                                                            context.MTApp);

                            bool transactionSuccess = false;

                            if (context.MTApp.CurrentRequestContext.CurrentStore.Settings.PayPal.ExpressAuthorizeOnly)
                            {
                                transactionSuccess = payManager.PayPalExpressHold(p, context.MTApp.OrderServices.PaymentSummary(context.Order).AmountDue);
                            }
                            else
                            {
                                transactionSuccess = payManager.PayPalExpressCharge(p, context.MTApp.OrderServices.PaymentSummary(context.Order).AmountDue);
                            }

                            if (transactionSuccess == false)
                            {
                                result = false;
                            }
                        }
                        catch (Exception ex)
                        {
                            context.Errors.Add(new WorkflowMessage("Exception During Receive Paypal Express Payments", ex.Message + ex.StackTrace, false));
                        }
                        finally
                        {
                            Orders.OrderPaymentStatus previousPaymentStatus = context.Order.PaymentStatus;
                            context.MTApp.OrderServices.EvaluatePaymentStatus(context.Order);
                            context.Inputs.Add("bvsoftware", "PreviousPaymentStatus", previousPaymentStatus.ToString());
                            BusinessRules.Workflow.RunByName(context, WorkflowNames.PaymentChanged);
                        }
                    }
                }
            }

            if (result == false)
            {
                // Add Error
                bool throwErrors = true;
                //throwErrors = this.SettingsManager.GetBooleanSetting("ThrowErrors");
                if (throwErrors == true)
                {
                    if (result == false)
                    {
                        string errorString = string.Empty; // this.SettingsManager.GetSetting("CustomerErrorMessage");
                        if (errorString == string.Empty)
                        {
                            errorString = "An error occured while attempting to process your Paypal Express payment. Please check your payment information and try again";
                        }
                        context.Errors.Add(new WorkflowMessage("Receive Card Failed", errorString, true));
                    }
                }
                else
                {
                    // Hide Error
                    result = true;
                }

                // Failure Status Code
                bool SetStatus = false;
                SetStatus = true; // this.SettingsManager.GetBooleanSetting("SetStatusOnFail");
                if (SetStatus == true)
                {
                    string failCode          = Orders.OrderStatusCode.OnHold;
                    Orders.OrderStatusCode c = Orders.OrderStatusCode.FindByBvin(failCode);
                    if (c != null)
                    {
                        context.Order.StatusCode = c.Bvin;
                        context.Order.StatusName = c.StatusName;
                    }
                }
            }
            return(result);
        }
Exemple #6
0
        public override bool Execute(OrderTaskContext context)
        {
            bool result = true;

            if (context.MTApp.OrderServices.PaymentSummary(context.Order).AmountDue > 0)
            {
                foreach (Orders.OrderTransaction p in context.MTApp.OrderServices.Transactions.FindForOrder(context.Order.bvin))
                {
                    List <Orders.OrderTransaction> transactions = context.MTApp.OrderServices.Transactions.FindForOrder(context.Order.bvin);

                    if (p.Action == MerchantTribe.Payment.ActionType.CreditCardInfo)
                    {
                        // if we already have an auth or charge on the card, skip
                        if (p.HasSuccessfulLinkedAction(MerchantTribe.Payment.ActionType.CreditCardCharge, transactions) ||
                            p.HasSuccessfulLinkedAction(MerchantTribe.Payment.ActionType.CreditCardHold, transactions))
                        {
                            Orders.OrderNote note = new Orders.OrderNote();
                            note.IsPublic = false;
                            note.Note     = "Skipping receive for credit card info because auth or charge already exists. Transaction " + p.Id;
                            context.Order.Notes.Add(note);
                            continue;
                        }

                        try
                        {
                            MerchantTribe.Payment.Transaction t = context.Order.GetEmptyTransaction();
                            t.Card   = p.CreditCard;
                            t.Amount = p.Amount;

                            if (context.MTApp.CurrentRequestContext.CurrentStore.Settings.PaymentCreditCardAuthorizeOnly == true)
                            {
                                t.Action = MerchantTribe.Payment.ActionType.CreditCardHold;
                            }
                            else
                            {
                                t.Action = MerchantTribe.Payment.ActionType.CreditCardCharge;
                            }

                            MerchantTribe.Payment.Method proc = context.MTApp.CurrentRequestContext.CurrentStore.Settings.PaymentCurrentCreditCardProcessor();
                            proc.ProcessTransaction(t);

                            Orders.OrderTransaction ot = new Orders.OrderTransaction(t);
                            ot.LinkedToTransaction = p.IdAsString;
                            context.MTApp.OrderServices.AddPaymentTransactionToOrder(context.Order, ot, context.MTApp);

                            if (t.Result.Succeeded == false)
                            {
                                result = false;
                            }
                        }
                        catch (Exception ex)
                        {
                            context.Errors.Add(new WorkflowMessage("Exception During Receive Credit Card", ex.Message + ex.StackTrace, false));
                            Orders.OrderNote note = new Orders.OrderNote();
                            note.IsPublic = false;
                            note.Note     = "EXCEPTION: " + ex.Message + " | " + ex.StackTrace;
                            context.Order.Notes.Add(note);
                        }
                    }
                }

                // Evaluate Payment Status After Receiving Payments
                Orders.OrderPaymentStatus previousPaymentStatus = context.Order.PaymentStatus;
                context.MTApp.OrderServices.EvaluatePaymentStatus(context.Order);
                context.Inputs.Add("bvsoftware", "PreviousPaymentStatus", previousPaymentStatus.ToString());
                BusinessRules.Workflow.RunByName(context, WorkflowNames.PaymentChanged);
            }
            else
            {
                Orders.OrderNote note = new Orders.OrderNote();
                note.IsPublic = false;
                note.Note     = "Amount due was less than zero. Skipping receive credit cards";
                context.Order.Notes.Add(note);
            }



            if (result == false)
            {
                // Add Error
                bool throwErrors = false;
                throwErrors = context.MTApp.CurrentRequestContext.CurrentStore.Settings.RejectFailedCreditCardOrdersAutomatically;
                if (throwErrors == true)
                {
                    if (result == false)
                    {
                        string errorString = string.Empty; // this.SettingsManager.GetSetting("CustomerErrorMessage");
                        if (errorString == string.Empty)
                        {
                            errorString = "An error occured while attempting to process your credit card. Please check your payment information and try again";
                        }
                        context.Errors.Add(new WorkflowMessage("Receive Card Failed", errorString, true));
                    }
                }
                else
                {
                    // Hide Error
                    result = true;
                }

                // Failure Status Code
                bool SetStatus = false;
                SetStatus = true; // this.SettingsManager.GetBooleanSetting("SetStatusOnFail");
                if (SetStatus == true)
                {
                    string failCode          = Orders.OrderStatusCode.OnHold;
                    Orders.OrderStatusCode c = Orders.OrderStatusCode.FindByBvin(failCode);
                    if (c != null)
                    {
                        context.Order.StatusCode = c.Bvin;
                        context.Order.StatusName = c.StatusName;
                    }
                }
            }
            return(result);
        }