Ejemplo n.º 1
0
 public override bool Execute(OrderTaskContext context)
 {
     Orders.OrderNote note = new Orders.OrderNote();
     note.IsPublic = false;
     note.Note = this.Note;            
     context.Order.Notes.Add(note);            
     return true;
 }
Ejemplo n.º 2
0
 public override bool Execute(OrderTaskContext context)
 {
     Orders.OrderNote note = new Orders.OrderNote();
     note.IsPublic = false;
     note.Note     = this.Note;
     context.Order.Notes.Add(note);
     return(true);
 }
Ejemplo n.º 3
0
        public override bool Execute(OrderTaskContext context)
        {
            // Assign Order Number
            if (context.Order.OrderNumber == string.Empty)
            {
                context.Order.OrderNumber = context.MTApp.OrderServices.GenerateNewOrderNumber(context.MTApp.CurrentRequestContext.CurrentStore.Id).ToString();

                Orders.OrderNote note = new Orders.OrderNote();
                note.IsPublic = false;
                note.Note     = "This order was assigned number " + context.Order.OrderNumber;
                context.Order.Notes.Add(note);
            }
            return(true);
        }
Ejemplo n.º 4
0
        public override bool Execute(OrderTaskContext context)
        {
            // Assign Order Number
            if (context.Order.OrderNumber == string.Empty)
            {
                context.Order.OrderNumber = context.MTApp.OrderServices.GenerateNewOrderNumber(context.MTApp.CurrentRequestContext.CurrentStore.Id).ToString();

                Orders.OrderNote note = new Orders.OrderNote();
                note.IsPublic = false;
                note.Note = "This order was assigned number " + context.Order.OrderNumber;
                context.Order.Notes.Add(note);                
            }
            return true;
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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;
		}
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
		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;
		}
        public override bool ProcessCheckout(OrderTaskContext context)
        {
            if (context.HccApp.CurrentRequestContext.RoutingContext.HttpContext != null)
            {
                try
                {
                    PayPalAPI ppAPI = Utilities.PaypalExpressUtilities.GetPaypalAPI(context.HccApp.CurrentStore);

                    string cartReturnUrl = HccUrlBuilder.RouteHccUrl(HccRoute.ThirdPartyPayment, null, Uri.UriSchemeHttps);
                    string cartCancelUrl = HccUrlBuilder.RouteHccUrl(HccRoute.Checkout, null, Uri.UriSchemeHttps);

                    EventLog.LogEvent("PayPal Express Checkout", "CartCancelUrl=" + cartCancelUrl, EventLogSeverity.Information);
                    EventLog.LogEvent("PayPal Express Checkout", "CartReturnUrl=" + cartReturnUrl, EventLogSeverity.Information);

                    PaymentActionCodeType mode = PaymentActionCodeType.Authorization;
                    if (!context.HccApp.CurrentStore.Settings.PayPal.ExpressAuthorizeOnly)
                    {
                        mode = PaymentActionCodeType.Sale;
                    }

                    // Accelerated boarding
                    if (string.IsNullOrWhiteSpace(context.HccApp.CurrentStore.Settings.PayPal.UserName))
                    {
                        mode = PaymentActionCodeType.Sale;
                    }

                    var  solutionType  = context.HccApp.CurrentStore.Settings.PayPal.RequirePayPalAccount ? SolutionTypeType.Mark : SolutionTypeType.Sole;
                    bool isNonShipping = !context.Order.HasShippingItems;

                    bool addressSupplied = false;
                    if (context.Inputs["ViaCheckout"] != null &&
                        context.Inputs["ViaCheckout"].Value == "1")
                    {
                        addressSupplied = true;
                        context.Order.CustomProperties.Add("hcc", "ViaCheckout", "1");
                    }

                    PaymentDetailsItemType[] itemsDetails = GetOrderItemsDetails(context);

                    SetExpressCheckoutResponseType expressResponse;
                    if (addressSupplied)
                    {
                        Contacts.Address address = context.Order.ShippingAddress;

                        // in some cases, this logic will be hit with non-shipping orders, causing an exception
                        if (address == null || string.IsNullOrEmpty(address.Bvin))
                        {
                            // this is a workaround for that use case
                            address = context.Order.BillingAddress;
                        }

                        if (address.CountryData != null)
                        {
                            var itemsTotalWithoutTax = context.Order.TotalOrderAfterDiscounts;
                            if (context.HccApp.CurrentStore.Settings.ApplyVATRules)
                            {
                                itemsTotalWithoutTax -= context.Order.ItemsTax;
                            }
                            string itemsTotal = itemsTotalWithoutTax.ToString("N", CultureInfo.InvariantCulture);
                            string taxTotal   = context.Order.TotalTax.ToString("N", CultureInfo.InvariantCulture);
                            var    shippingTotalWithoutTax = context.Order.TotalShippingAfterDiscounts;
                            if (context.HccApp.CurrentStore.Settings.ApplyVATRules)
                            {
                                shippingTotalWithoutTax -= context.Order.ShippingTax;
                            }
                            string shippingTotal = shippingTotalWithoutTax.ToString("N", CultureInfo.InvariantCulture);

                            string orderTotal = context.Order.TotalGrand.ToString("N", CultureInfo.InvariantCulture);
                            expressResponse = ppAPI.SetExpressCheckout(
                                itemsDetails,
                                itemsTotal,
                                taxTotal,
                                shippingTotal,
                                orderTotal,
                                cartReturnUrl,
                                cartCancelUrl,
                                mode,
                                PayPalAPI.GetCurrencyCodeType(context.HccApp.CurrentStore.Settings.PayPal.Currency),
                                solutionType,
                                address.FirstName + " " + address.LastName,
                                address.CountryData.IsoCode,
                                address.Line1,
                                address.Line2,
                                address.City,
                                address.RegionBvin,
                                address.PostalCode,
                                address.Phone,
                                context.Order.OrderNumber + Guid.NewGuid().ToString(),
                                isNonShipping);
                            if (expressResponse == null)
                            {
                                EventLog.LogEvent("PayPal Express Checkout", "Express Response Was Null!", EventLogSeverity.Error);
                            }
                        }
                        else
                        {
                            EventLog.LogEvent("StartPaypalExpressCheckout", "Country with bvin " + address.CountryBvin + " was not found.", EventLogSeverity.Error);
                            return(false);
                        }
                    }
                    else
                    {
                        decimal includedTax = 0;
                        if (context.HccApp.CurrentStore.Settings.ApplyVATRules)
                        {
                            includedTax = context.Order.ItemsTax;
                        }
                        string taxTotal             = includedTax.ToString("N", CultureInfo.InvariantCulture);
                        var    itemsTotalWithoutTax = context.Order.TotalOrderAfterDiscounts;
                        if (context.HccApp.CurrentStore.Settings.ApplyVATRules)
                        {
                            itemsTotalWithoutTax -= context.Order.ItemsTax;
                        }
                        string itemsTotal = itemsTotalWithoutTax.ToString("N", CultureInfo.InvariantCulture);
                        string orderTotal = context.Order.TotalOrderAfterDiscounts.ToString("N", CultureInfo.InvariantCulture);
                        expressResponse = ppAPI.SetExpressCheckout(itemsDetails,
                                                                   itemsTotal,
                                                                   taxTotal,
                                                                   orderTotal,
                                                                   cartReturnUrl,
                                                                   cartCancelUrl,
                                                                   mode,
                                                                   PayPalAPI.GetCurrencyCodeType(context.HccApp.CurrentStore.Settings.PayPal.Currency),
                                                                   solutionType,
                                                                   context.Order.OrderNumber + Guid.NewGuid().ToString(),
                                                                   isNonShipping);
                        if (expressResponse == null)
                        {
                            EventLog.LogEvent("PayPal Express Checkout", "Express Response2 Was Null!", EventLogSeverity.Error);
                        }
                    }

                    if (expressResponse.Ack == AckCodeType.Success || expressResponse.Ack == AckCodeType.SuccessWithWarning)
                    {
                        context.Order.ThirdPartyOrderId = expressResponse.Token;

                        // Recording of this info is handled on the paypal express
                        // checkout page instead of here.
                        //Orders.OrderPaymentManager payManager = new Orders.OrderPaymentManager(context.Order);
                        //payManager.PayPalExpressAddInfo(context.Order.TotalGrand, expressResponse.Token);

                        EventLog.LogEvent("PayPal Express Checkout", "Response SUCCESS", EventLogSeverity.Information);

                        Orders.OrderNote note = new Orders.OrderNote();
                        note.IsPublic = false;
                        note.Note     = "Paypal Order Accepted With Paypal Order Number: " + expressResponse.Token;
                        context.Order.Notes.Add(note);
                        if (context.HccApp.OrderServices.Orders.Update(context.Order))
                        {
                            string urlTemplate;
                            if (string.Compare(context.HccApp.CurrentStore.Settings.PayPal.Mode, "Live", true) == 0)
                            {
                                urlTemplate = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token={0}";
                            }
                            else
                            {
                                urlTemplate = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token={0}";
                            }
                            HttpContextBase httpContext = new HccHttpContextWrapper(HttpContext.Current);
                            httpContext.Response.Redirect(string.Format(urlTemplate, expressResponse.Token), true);
                        }
                        return(true);
                    }
                    else
                    {
                        foreach (ErrorType ppError in expressResponse.Errors)
                        {
                            context.Errors.Add(new WorkflowMessage(ppError.ErrorCode, ppError.ShortMessage, true));

                            //create a note to save the paypal error info onto the order
                            Orders.OrderNote note = new Orders.OrderNote();
                            note.IsPublic = false;
                            note.Note     = "Paypal error number: " + ppError.ErrorCode + " Paypal Error: '" + ppError.ShortMessage + "' Message: '" + ppError.LongMessage;
                            context.Order.Notes.Add(note);

                            EventLog.LogEvent("Paypal error number: " + ppError.ErrorCode, "Paypal Error: '" + ppError.ShortMessage + "' Message: '" + ppError.LongMessage + "' " + " Values passed to SetExpressCheckout: Total=" + string.Format("{0:c}", context.Order.TotalOrderBeforeDiscounts) + " Cart Return Url: " + cartReturnUrl + " Cart Cancel Url: " + cartCancelUrl, EventLogSeverity.Error);
                        }
                        context.Errors.Add(new WorkflowMessage("Paypal checkout error", GlobalLocalization.GetString("PaypalCheckoutCustomerError"), true));
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    EventLog.LogEvent("Paypal Express Checkout", "Exception occurred during call to Paypal: " + ex.ToString(), EventLogSeverity.Error);
                    context.Errors.Add(new WorkflowMessage("Paypal checkout error", GlobalLocalization.GetString("PaypalCheckoutCustomerError"), true));
                    return(false);
                }
            }

            return(false);
        }
Ejemplo n.º 10
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;
		}
Ejemplo n.º 11
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);
        }
		public override bool Execute(OrderTaskContext context)
		{
			if (context.Inputs["Mode"] != null) {
				if (context.Inputs["Mode"].Value == "PaypalExpress") {
                    if (context.MTApp.CurrentRequestContext.RoutingContext.HttpContext != null)
                    {
						PayPalAPI ppAPI = Utilities.PaypalExpressUtilities.GetPaypalAPI(context.MTApp.CurrentStore);
						try {

                            string cartReturnUrl = string.Empty;
                            string cartCancelUrl = string.Empty;
                            if (context.MTApp.CurrentRequestContext != null)
                            {
                                cartReturnUrl = context.MTApp.CurrentRequestContext.CurrentStore.RootUrlSecure() + "paypalexpresscheckout";
                                cartCancelUrl = context.MTApp.CurrentRequestContext.CurrentStore.RootUrlSecure() + "checkout";
                            }

                            EventLog.LogEvent("PayPal Express Checkout", "CartCancelUrl=" + cartCancelUrl, EventLogSeverity.Information);
                            EventLog.LogEvent("PayPal Express Checkout", "CartReturnUrl=" + cartReturnUrl, EventLogSeverity.Information);

							SetExpressCheckoutResponseType expressResponse;
							PaymentActionCodeType mode = PaymentActionCodeType.Authorization;

                            if (context.MTApp.CurrentRequestContext.CurrentStore.Settings.PayPal.ExpressAuthorizeOnly)
                            {
								mode = PaymentActionCodeType.Order;
							}
							else {
								mode = PaymentActionCodeType.Sale;
							}

                            // Accelerated boarding
                            if (context.MTApp.CurrentRequestContext.CurrentStore.Settings.PayPal.UserName.Trim().Length < 1) mode = PaymentActionCodeType.Sale;


							bool addressSupplied = false;
							if (context.Inputs["AddressSupplied"] != null) {
								if (context.Inputs["AddressSupplied"].Value == "1") {
									addressSupplied = true;
									context.Order.CustomProperties.Add("bvsoftware", "PaypalAddressOverride", "1");
								}
							}

							string amountToPayPal = context.Order.TotalOrderBeforeDiscounts.ToString("N", System.Globalization.CultureInfo.CreateSpecificCulture("en-US"));

							if (addressSupplied) {
								Contacts.Address address = context.Order.ShippingAddress;

								MerchantTribe.Web.Geography.Country country = MerchantTribe.Web.Geography.Country.FindByBvin(address.CountryBvin);
								if (country != null) {
                                    expressResponse = ppAPI.SetExpressCheckout(
                                        amountToPayPal, 
                                        cartReturnUrl, 
                                        cartCancelUrl, 
                                        mode,
                                        PayPalAPI.GetCurrencyCodeType(context.MTApp.CurrentRequestContext.CurrentStore.Settings.PayPal.Currency), 
                                        address.FirstName + " " + address.LastName, 
                                        country.IsoCode, 
                                        address.Line1, 
                                        address.Line2, 
                                        address.City,
									    address.RegionBvin, 
                                        address.PostalCode, 
                                        address.Phone, 
                                        context.Order.OrderNumber + System.Guid.NewGuid().ToString());
                                    if (expressResponse == null)
                                    {
                                        EventLog.LogEvent("PayPal Express Checkout", "Express Response Was Null!", EventLogSeverity.Error);
                                    }
								}
								else {
									EventLog.LogEvent("StartPaypalExpressCheckout", "Country with bvin " + address.CountryBvin + " was not found.", EventLogSeverity.Error);
									return false;
								}
							}
							else {
                                expressResponse = ppAPI.SetExpressCheckout(amountToPayPal, 
                                                                        cartReturnUrl, 
                                                                        cartCancelUrl, 
                                                                        mode,
                                                                        PayPalAPI.GetCurrencyCodeType(context.MTApp.CurrentRequestContext.CurrentStore.Settings.PayPal.Currency), 
                                                                        context.Order.OrderNumber + System.Guid.NewGuid().ToString());
                                if (expressResponse == null)
                                {
                                    EventLog.LogEvent("PayPal Express Checkout", "Express Response2 Was Null!", EventLogSeverity.Error);
                                }
							}

							if (expressResponse.Ack == AckCodeType.Success || expressResponse.Ack == AckCodeType.SuccessWithWarning) {
								context.Order.ThirdPartyOrderId = expressResponse.Token;
								
                                // Recording of this info is handled on the paypal express
                                // checkout page instead of here.
                                //Orders.OrderPaymentManager payManager = new Orders.OrderPaymentManager(context.Order);
                                //payManager.PayPalExpressAddInfo(context.Order.TotalGrand, expressResponse.Token);

                                EventLog.LogEvent("PayPal Express Checkout", "Response SUCCESS", EventLogSeverity.Information);

                                Orders.OrderNote note = new Orders.OrderNote();
                                note.IsPublic = false;
								note.Note = "Paypal Order Accepted With Paypal Order Number: " + expressResponse.Token;
								context.Order.Notes.Add(note);
                                if (context.MTApp.OrderServices.Orders.Update(context.Order))
                                {
                                    if (string.Compare(context.MTApp.CurrentRequestContext.CurrentStore.Settings.PayPal.Mode, "Live", true) == 0)
                                    {
										context.MTApp.CurrentRequestContext.RoutingContext.HttpContext.Response.Redirect("https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + expressResponse.Token, true);
									}
									else {
                                        context.MTApp.CurrentRequestContext.RoutingContext.HttpContext.Response.Redirect("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + expressResponse.Token, true);
									}

								}
								return true;
							}
							else {
								foreach (ErrorType ppError in expressResponse.Errors) {

                                    context.Errors.Add(new WorkflowMessage(ppError.ErrorCode,ppError.ShortMessage, true));

									//create a note to save the paypal error info onto the order
									Orders.OrderNote note = new Orders.OrderNote();
                                    note.IsPublic = false;
									note.Note = "Paypal error number: " + ppError.ErrorCode + " Paypal Error: '" + ppError.ShortMessage + "' Message: '" + ppError.LongMessage;
									context.Order.Notes.Add(note);

									EventLog.LogEvent("Paypal error number: " + ppError.ErrorCode, "Paypal Error: '" + ppError.ShortMessage + "' Message: '" + ppError.LongMessage + "' " + " Values passed to SetExpressCheckout: Total=" + string.Format("{0:c}", context.Order.TotalOrderBeforeDiscounts) + " Cart Return Url: " + cartReturnUrl + " Cart Cancel Url: " + cartCancelUrl, EventLogSeverity.Error);
								}
								context.Errors.Add(new WorkflowMessage("Paypal checkout error", Content.SiteTerms.GetTerm(Content.SiteTermIds.PaypalCheckoutCustomerError), true));
								return false;
							}
						}
						catch (Exception ex) {
							EventLog.LogEvent("Paypal Express Checkout", "Exception occurred during call to Paypal: " + ex.ToString(), EventLogSeverity.Error);
							context.Errors.Add(new WorkflowMessage("Paypal checkout error", Content.SiteTerms.GetTerm(Content.SiteTermIds.PaypalCheckoutCustomerError), true));
							return false;
						}
						finally {
							ppAPI = null;
						}
					}
				}
				else {
					return true;
				}
			}
			else {
				return true;
			}

            return false;
		}
        public override bool Execute(OrderTaskContext context)
        {
            if (context.Inputs["Mode"] != null)
            {
                if (context.Inputs["Mode"].Value == "PaypalExpress")
                {
                    if (context.MTApp.CurrentRequestContext.RoutingContext.HttpContext != null)
                    {
                        PayPalAPI ppAPI = Utilities.PaypalExpressUtilities.GetPaypalAPI(context.MTApp.CurrentStore);
                        try {
                            string cartReturnUrl = string.Empty;
                            string cartCancelUrl = string.Empty;
                            if (context.MTApp.CurrentRequestContext != null)
                            {
                                cartReturnUrl = context.MTApp.CurrentRequestContext.CurrentStore.RootUrlSecure() + "paypalexpresscheckout";
                                cartCancelUrl = context.MTApp.CurrentRequestContext.CurrentStore.RootUrlSecure() + "checkout";
                            }

                            EventLog.LogEvent("PayPal Express Checkout", "CartCancelUrl=" + cartCancelUrl, EventLogSeverity.Information);
                            EventLog.LogEvent("PayPal Express Checkout", "CartReturnUrl=" + cartReturnUrl, EventLogSeverity.Information);

                            SetExpressCheckoutResponseType expressResponse;
                            PaymentActionCodeType          mode = PaymentActionCodeType.Authorization;

                            if (context.MTApp.CurrentRequestContext.CurrentStore.Settings.PayPal.ExpressAuthorizeOnly)
                            {
                                mode = PaymentActionCodeType.Order;
                            }
                            else
                            {
                                mode = PaymentActionCodeType.Sale;
                            }

                            // Accelerated boarding
                            if (context.MTApp.CurrentRequestContext.CurrentStore.Settings.PayPal.UserName.Trim().Length < 1)
                            {
                                mode = PaymentActionCodeType.Sale;
                            }


                            bool addressSupplied = false;
                            if (context.Inputs["AddressSupplied"] != null)
                            {
                                if (context.Inputs["AddressSupplied"].Value == "1")
                                {
                                    addressSupplied = true;
                                    context.Order.CustomProperties.Add("bvsoftware", "PaypalAddressOverride", "1");
                                }
                            }

                            string amountToPayPal = context.Order.TotalOrderBeforeDiscounts.ToString("N", System.Globalization.CultureInfo.CreateSpecificCulture("en-US"));

                            if (addressSupplied)
                            {
                                Contacts.Address address = context.Order.ShippingAddress;

                                MerchantTribe.Web.Geography.Country country = MerchantTribe.Web.Geography.Country.FindByBvin(address.CountryBvin);
                                if (country != null)
                                {
                                    expressResponse = ppAPI.SetExpressCheckout(
                                        amountToPayPal,
                                        cartReturnUrl,
                                        cartCancelUrl,
                                        mode,
                                        PayPalAPI.GetCurrencyCodeType(context.MTApp.CurrentRequestContext.CurrentStore.Settings.PayPal.Currency),
                                        address.FirstName + " " + address.LastName,
                                        country.IsoCode,
                                        address.Line1,
                                        address.Line2,
                                        address.City,
                                        address.RegionBvin,
                                        address.PostalCode,
                                        address.Phone,
                                        context.Order.OrderNumber + System.Guid.NewGuid().ToString());
                                    if (expressResponse == null)
                                    {
                                        EventLog.LogEvent("PayPal Express Checkout", "Express Response Was Null!", EventLogSeverity.Error);
                                    }
                                }
                                else
                                {
                                    EventLog.LogEvent("StartPaypalExpressCheckout", "Country with bvin " + address.CountryBvin + " was not found.", EventLogSeverity.Error);
                                    return(false);
                                }
                            }
                            else
                            {
                                expressResponse = ppAPI.SetExpressCheckout(amountToPayPal,
                                                                           cartReturnUrl,
                                                                           cartCancelUrl,
                                                                           mode,
                                                                           PayPalAPI.GetCurrencyCodeType(context.MTApp.CurrentRequestContext.CurrentStore.Settings.PayPal.Currency),
                                                                           context.Order.OrderNumber + System.Guid.NewGuid().ToString());
                                if (expressResponse == null)
                                {
                                    EventLog.LogEvent("PayPal Express Checkout", "Express Response2 Was Null!", EventLogSeverity.Error);
                                }
                            }

                            if (expressResponse.Ack == AckCodeType.Success || expressResponse.Ack == AckCodeType.SuccessWithWarning)
                            {
                                context.Order.ThirdPartyOrderId = expressResponse.Token;

                                // Recording of this info is handled on the paypal express
                                // checkout page instead of here.
                                //Orders.OrderPaymentManager payManager = new Orders.OrderPaymentManager(context.Order);
                                //payManager.PayPalExpressAddInfo(context.Order.TotalGrand, expressResponse.Token);

                                EventLog.LogEvent("PayPal Express Checkout", "Response SUCCESS", EventLogSeverity.Information);

                                Orders.OrderNote note = new Orders.OrderNote();
                                note.IsPublic = false;
                                note.Note     = "Paypal Order Accepted With Paypal Order Number: " + expressResponse.Token;
                                context.Order.Notes.Add(note);
                                if (context.MTApp.OrderServices.Orders.Update(context.Order))
                                {
                                    if (string.Compare(context.MTApp.CurrentRequestContext.CurrentStore.Settings.PayPal.Mode, "Live", true) == 0)
                                    {
                                        context.MTApp.CurrentRequestContext.RoutingContext.HttpContext.Response.Redirect("https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + expressResponse.Token, true);
                                    }
                                    else
                                    {
                                        context.MTApp.CurrentRequestContext.RoutingContext.HttpContext.Response.Redirect("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + expressResponse.Token, true);
                                    }
                                }
                                return(true);
                            }
                            else
                            {
                                foreach (ErrorType ppError in expressResponse.Errors)
                                {
                                    context.Errors.Add(new WorkflowMessage(ppError.ErrorCode, ppError.ShortMessage, true));

                                    //create a note to save the paypal error info onto the order
                                    Orders.OrderNote note = new Orders.OrderNote();
                                    note.IsPublic = false;
                                    note.Note     = "Paypal error number: " + ppError.ErrorCode + " Paypal Error: '" + ppError.ShortMessage + "' Message: '" + ppError.LongMessage;
                                    context.Order.Notes.Add(note);

                                    EventLog.LogEvent("Paypal error number: " + ppError.ErrorCode, "Paypal Error: '" + ppError.ShortMessage + "' Message: '" + ppError.LongMessage + "' " + " Values passed to SetExpressCheckout: Total=" + string.Format("{0:c}", context.Order.TotalOrderBeforeDiscounts) + " Cart Return Url: " + cartReturnUrl + " Cart Cancel Url: " + cartCancelUrl, EventLogSeverity.Error);
                                }
                                context.Errors.Add(new WorkflowMessage("Paypal checkout error", Content.SiteTerms.GetTerm(Content.SiteTermIds.PaypalCheckoutCustomerError), true));
                                return(false);
                            }
                        }
                        catch (Exception ex) {
                            EventLog.LogEvent("Paypal Express Checkout", "Exception occurred during call to Paypal: " + ex.ToString(), EventLogSeverity.Error);
                            context.Errors.Add(new WorkflowMessage("Paypal checkout error", Content.SiteTerms.GetTerm(Content.SiteTermIds.PaypalCheckoutCustomerError), true));
                            return(false);
                        }
                        finally {
                            ppAPI = null;
                        }
                    }
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 14
0
        public override bool Execute(OrderTaskContext context)
        {
            Collection <string> manufacturers = new Collection <string>();
            Collection <string> vendors       = new Collection <string>();

            foreach (Orders.LineItem item in context.Order.Items)
            {
                if (item.ShipFromMode == Shipping.ShippingMode.ShipFromManufacturer)
                {
                    if (item.ShipFromNotificationId != string.Empty)
                    {
                        if (!manufacturers.Contains(item.ShipFromNotificationId))
                        {
                            manufacturers.Add(item.ShipFromNotificationId);
                        }
                    }
                    else
                    {
                        EventLog.LogEvent("RunAllDropShipWorkflows.bv", "Item with sku " + item.ProductSku + " is marked as Ship From Manufacturer, but contains no Manufacturer Id", EventLogSeverity.Warning);
                    }
                }
                else if (item.ShipFromMode == Shipping.ShippingMode.ShipFromVendor)
                {
                    if (item.ShipFromNotificationId != string.Empty)
                    {
                        if (!vendors.Contains(item.ShipFromNotificationId))
                        {
                            vendors.Add(item.ShipFromNotificationId);
                        }
                    }
                    else
                    {
                        EventLog.LogEvent("RunAllDropShipWorkflows.bv", "Item with sku " + item.ProductSku + " is marked as Ship From Vendor, but contains no Vendor Id", EventLogSeverity.Warning);
                    }
                }
            }

            foreach (string item in manufacturers)
            {
                Contacts.VendorManufacturer mfg = context.MTApp.ContactServices.Manufacturers.Find(item);
                if (mfg != null)
                {
                    if (mfg.Bvin != string.Empty)
                    {
                        bool success = false;
                        //if (WebAppSettings.SendDropShipNotificationsThroughWebService) {
                        //    itemsNeedToBeDropShipped = true;
                        //    success = true;
                        //}
                        //else {
                        if (!SendEmail(context.MTApp, mfg, context.Order))
                        {
                            Orders.OrderNote n = new Orders.OrderNote();
                            n.IsPublic = false;
                            n.Note     = "Drop shipper notices for " + mfg.DisplayName + " were not able to send correctly.";
                            context.Order.Notes.Add(n);
                            context.MTApp.OrderServices.Orders.Upsert(context.Order);
                        }
                        else
                        {
                            success = true;
                        }
                        //}

                        if (success)
                        {
                            Orders.OrderNote n = new Orders.OrderNote();
                            n.IsPublic = false;
                            n.Note     = "Drop shipper notices for " + mfg.DisplayName + " were sent successfully.";
                            context.Order.Notes.Add(n);
                            context.MTApp.OrderServices.Orders.Upsert(context.Order);
                        }
                    }
                }
            }

            foreach (string item in vendors)
            {
                Contacts.VendorManufacturer vendor = context.MTApp.ContactServices.Vendors.Find(item);
                if (vendor != null)
                {
                    if (vendor.Bvin != string.Empty)
                    {
                        bool success = false;
                        //if (WebAppSettings.SendDropShipNotificationsThroughWebService) {
                        //    itemsNeedToBeDropShipped = true;
                        //    success = true;
                        //}
                        //else {
                        if (!SendEmail(context.MTApp, vendor, context.Order))
                        {
                            Orders.OrderNote n = new Orders.OrderNote();
                            n.IsPublic = false;
                            n.Note     = "Drop shipper notices for " + vendor.DisplayName + " were not able to send correctly.";
                            context.Order.Notes.Add(n);
                            context.MTApp.OrderServices.Orders.Upsert(context.Order);
                        }
                        else
                        {
                            success = true;
                        }
                        //}

                        if (success)
                        {
                            Orders.OrderNote n = new Orders.OrderNote();
                            n.IsPublic = false;
                            n.Note     = "Drop shipper notices for " + vendor.DisplayName + " were sent successfully.";
                            context.Order.Notes.Add(n);
                            context.MTApp.OrderServices.Orders.Upsert(context.Order);
                        }
                    }
                }
            }

            //if (itemsNeedToBeDropShipped) {
            //    return LogDropShipNotification(context.Order);
            //}
            return(true);
        }
		public override bool Execute(OrderTaskContext context)
		{
			Collection<string> manufacturers = new Collection<string>();
			Collection<string> vendors = new Collection<string>();
			foreach (Orders.LineItem item in context.Order.Items) {

					
						if (item.ShipFromMode == Shipping.ShippingMode.ShipFromManufacturer) {
							if (item.ShipFromNotificationId != string.Empty) {
								if (!manufacturers.Contains(item.ShipFromNotificationId)) {
									manufacturers.Add(item.ShipFromNotificationId);
								}
							}
							else {
								EventLog.LogEvent("RunAllDropShipWorkflows.bv", "Item with sku " + item.ProductSku + " is marked as Ship From Manufacturer, but contains no Manufacturer Id", EventLogSeverity.Warning);
							}
						}
						else if (item.ShipFromMode == Shipping.ShippingMode.ShipFromVendor) {
							if (item.ShipFromNotificationId != string.Empty) {
								if (!vendors.Contains(item.ShipFromNotificationId)) {
									vendors.Add(item.ShipFromNotificationId);
								}
							}
							else {
								EventLog.LogEvent("RunAllDropShipWorkflows.bv", "Item with sku " + item.ProductSku + " is marked as Ship From Vendor, but contains no Vendor Id", EventLogSeverity.Warning);
							}
						}
					
								
			}
			
			foreach (string item in manufacturers) {
                Contacts.VendorManufacturer mfg = context.MTApp.ContactServices.Manufacturers.Find(item);
				if (mfg != null) {
					if (mfg.Bvin != string.Empty) {
						bool success = false;
                        //if (WebAppSettings.SendDropShipNotificationsThroughWebService) {
                        //    itemsNeedToBeDropShipped = true;
                        //    success = true;
                        //}
                        //else {
                        if (!SendEmail(context.MTApp, mfg, context.Order))
                        {
								Orders.OrderNote n = new Orders.OrderNote();
                                n.IsPublic = false;
								n.Note = "Drop shipper notices for " + mfg.DisplayName + " were not able to send correctly.";
								context.Order.Notes.Add(n);
                                context.MTApp.OrderServices.Orders.Upsert(context.Order);
							}
							else {
								success = true;
							}
						//}

						if (success) {
							Orders.OrderNote n = new Orders.OrderNote();
                            n.IsPublic = false;
							n.Note = "Drop shipper notices for " + mfg.DisplayName + " were sent successfully.";
							context.Order.Notes.Add(n);
                            context.MTApp.OrderServices.Orders.Upsert(context.Order);
						}
					}
				}
			}

			foreach (string item in vendors) {
                Contacts.VendorManufacturer vendor = context.MTApp.ContactServices.Vendors.Find(item);
				if (vendor != null) {
					if (vendor.Bvin != string.Empty) {
						bool success = false;
                        //if (WebAppSettings.SendDropShipNotificationsThroughWebService) {
                        //    itemsNeedToBeDropShipped = true;
                        //    success = true;
                        //}
                        //else {
                        if (!SendEmail(context.MTApp, vendor, context.Order))
                        {
								Orders.OrderNote n = new Orders.OrderNote();
								n.IsPublic = false;
								n.Note = "Drop shipper notices for " + vendor.DisplayName + " were not able to send correctly.";
								context.Order.Notes.Add(n);
                                context.MTApp.OrderServices.Orders.Upsert(context.Order);
							}
							else {
								success = true;
							}
						//}

						if (success) {
							Orders.OrderNote n = new Orders.OrderNote();
							n.IsPublic = false;
							n.Note = "Drop shipper notices for " + vendor.DisplayName + " were sent successfully.";
							context.Order.Notes.Add(n);
                            context.MTApp.OrderServices.Orders.Upsert(context.Order);
						}
					}
				}
			}

            //if (itemsNeedToBeDropShipped) {
            //    return LogDropShipNotification(context.Order);
            //}
			return true;
		}