public static void CollectPaymentAndShipPendingOrders(MerchantTribeApplication app)
        {
            OrderSearchCriteria criteria = new OrderSearchCriteria();
            criteria.IsPlaced = true;
            criteria.StatusCode = OrderStatusCode.ReadyForPayment;
            int pageSize = 1000;            
            int totalCount = 0;

            List<OrderSnapshot> orders = app.OrderServices.Orders.FindByCriteriaPaged(criteria, 1, pageSize, ref totalCount);
            if (orders != null)
            {
                foreach (OrderSnapshot os in orders)
                {
                    Order o = app.OrderServices.Orders.FindForCurrentStore(os.bvin);
                    OrderPaymentManager payManager = new OrderPaymentManager(o, app);
                    payManager.CreditCardCompleteAllCreditCards();
                    payManager.PayPalExpressCompleteAllPayments();
                    if (o.PaymentStatus == OrderPaymentStatus.Paid ||
                        o.PaymentStatus == OrderPaymentStatus.Overpaid)
                    {
                        if (o.ShippingStatus == OrderShippingStatus.FullyShipped)
                        {
                            o.StatusCode = OrderStatusCode.Completed;
                            o.StatusName = "Completed";
                        }
                        else
                        {
                            o.StatusCode = OrderStatusCode.ReadyForShipping;
                            o.StatusName = "Ready for Shipping";
                        }
                        app.OrderServices.Orders.Update(o);
                    }
                }
            }
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            orderId = Request.QueryString["id"];
            o = MyPage.MTApp.OrderServices.Orders.FindForCurrentStore(orderId);
            payManager = new OrderPaymentManager(o, MyPage.MTApp);

            if (!Page.IsPostBack)
            {
                this.mvPayments.SetActiveView(this.viewCreditCards);
                LoadCreditCardLists();

                if (MyPage.MTApp.CurrentStore.PlanId < 2)
                {
                    //this.lnkCash.Visible = false;
                    this.lnkCheck.Visible = false;
                    this.lnkPO.Visible = false;
                }
            }


        }
        private void SavePaymentSelections(CheckoutViewModel model)
        {
            OrderPaymentManager payManager = new OrderPaymentManager(model.CurrentOrder, MTApp);
            payManager.ClearAllNonStoreCreditTransactions();

            bool found = false;

            if (model.PaymentViewModel.SelectedPayment == "creditcard")
            {
                found = true;
                payManager.CreditCardAddInfo(model.PaymentViewModel.DataCreditCard, model.CurrentOrder.TotalGrandAfterStoreCredits(MTApp.OrderServices));
            }

            if ((found == false) && (model.PaymentViewModel.SelectedPayment == "check"))
            {
                found = true;
                payManager.OfflinePaymentAddInfo(model.CurrentOrder.TotalGrandAfterStoreCredits(MTApp.OrderServices), "Customer will pay by check.");
            }

            if ((found == false) && (model.PaymentViewModel.SelectedPayment == "telephone"))
            {
                found = true;
                payManager.OfflinePaymentAddInfo(model.CurrentOrder.TotalGrandAfterStoreCredits(MTApp.OrderServices), "Customer will call with payment info.");
            }

            if ((found == false) && (model.PaymentViewModel.SelectedPayment == "purchaseorder"))
            {
                found = true;
                payManager.PurchaseOrderAddInfo(model.PaymentViewModel.DataPurchaseOrderNumber.Trim(), model.CurrentOrder.TotalGrandAfterStoreCredits(MTApp.OrderServices));
            }
            if ((found == false) && (model.PaymentViewModel.SelectedPayment == "companyaccount"))
            {
                found = true;
                payManager.CompanyAccountAddInfo(model.PaymentViewModel.DataCompanyAccountNumber.Trim(), model.CurrentOrder.TotalGrandAfterStoreCredits(MTApp.OrderServices));
            }

            if ((found == false) && (model.PaymentViewModel.SelectedPayment == "cod"))
            {
                found = true;
                payManager.OfflinePaymentAddInfo(model.CurrentOrder.TotalGrandAfterStoreCredits(MTApp.OrderServices), "Customer will pay cash on delivery.");
            }

            if ((found == false) && (model.PaymentViewModel.SelectedPayment == "paypal"))
            {
                found = true;
                // Need token and id before we can add this to the order
                // Handled on the checkout page.
                //payManager.PayPalExpressAddInfo(o.TotalGrand);
            }
        }
        private void ApplyRewardsPoints(CheckoutViewModel model)
        {
            // Remove any current points info transactions
            foreach (OrderTransaction t in MTApp.OrderServices.Transactions.FindForOrder(model.CurrentOrder.bvin))
            {
                if (t.Action == MerchantTribe.Payment.ActionType.RewardPointsInfo)
                {
                    MTApp.OrderServices.Transactions.Delete(t.Id);
                }
            }

            // Don't add if we're not using points
            if (!model.UseRewardsPoints) return;

            // Apply Info to Order
            OrderPaymentManager payManager = new OrderPaymentManager(model.CurrentOrder, MTApp);
            payManager.RewardsPointsAddInfo(RewardsPotentialCredit(model));
        }
        private void SavePaymentInfo(CheckoutViewModel model)
        {
            OrderPaymentManager payManager = new OrderPaymentManager(model.CurrentOrder, MTApp);
            payManager.ClearAllTransactions();

            string token = model.PayPalToken;
            string payerId = model.PayPalPayerId;
            if (!string.IsNullOrEmpty(payerId))
            {
                // This is to fix a bug with paypal returning multiple payerId's
                payerId = payerId.Split(',')[0];
            }

            payManager.PayPalExpressAddInfo(model.CurrentOrder.TotalGrand, token, payerId);
        }
Esempio n. 6
0
        private void SavePaymentInfo(Order o)
        {

            OrderPaymentManager payManager = new OrderPaymentManager(o, MTApp);

            payManager.ClearAllNonStoreCreditTransactions();

            bool found = false;

            if (this.rbCreditCard.Checked == true)
            {
                found = true;
                payManager.CreditCardAddInfo(this.CreditCardInput1.GetCardData(), o.TotalGrandAfterStoreCredits(MTApp.OrderServices));
            }

            if ((found == false) && (this.rbCheck.Checked == true))
            {
                found = true;
                payManager.OfflinePaymentAddInfo(o.TotalGrandAfterStoreCredits(MTApp.OrderServices), "Customer will pay by check.");
            }

            if ((found == false) && (this.rbTelephone.Checked == true))
            {
                found = true;
                payManager.OfflinePaymentAddInfo(o.TotalGrandAfterStoreCredits(MTApp.OrderServices), "Customer will call with payment info.");
            }

            if ((found == false) && (this.rbPurchaseOrder.Checked == true))
            {
                found = true;
                payManager.PurchaseOrderAddInfo(this.PurchaseOrderField.Text.Trim(), o.TotalGrandAfterStoreCredits(MTApp.OrderServices));
            }
            if ((found == false) && (this.rbCompanyAccount.Checked == true))
            {
                found = true;
                payManager.CompanyAccountAddInfo(this.accountnumber.Text.Trim(), o.TotalGrandAfterStoreCredits(MTApp.OrderServices));
            }

            if ((found == false) && (this.rbCOD.Checked == true))
            {
                found = true;
                payManager.OfflinePaymentAddInfo(o.TotalGrandAfterStoreCredits(MTApp.OrderServices), "Customer will pay cash on delivery.");
            }

            MTApp.OrderServices.Orders.Update(o);       
        }
		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;
		}