Пример #1
0
        private bool ProcessTransaction(OrderTaskContext context, OrderTransaction p)
        {
            bool result = true;

            try
            {
                var         payManager  = new OrderPaymentManager(context.Order, context.HccApp);
                var         orderNumber = !string.IsNullOrEmpty(p.OrderNumber) ? p.OrderNumber : context.Order.OrderNumber;
                Transaction t           = payManager.CreateEmptyTransaction();
                t.Card = p.CreditCard;
                t.Card.SecurityCode = context.Inputs.GetProperty("hcc", "CardSecurityCode");
                t.Amount            = p.Amount;
                t.Items             = GetLineItemsForTransaction(context, orderNumber);

                if (context.HccApp.CurrentStore.Settings.PaymentCreditCardAuthorizeOnly)
                {
                    t.Action = ActionType.CreditCardHold;
                }
                else
                {
                    t.Action = ActionType.CreditCardCharge;
                }

                PaymentGateway proc = PaymentGateways.CurrentPaymentProcessor(context.HccApp.CurrentStore);
                proc.ProcessTransaction(t);

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

                if (!t.Result.Succeeded || t.Action == ActionType.CreditCardIgnored)
                {
                    foreach (var m in t.Result.Messages)
                    {
                        if (m.Severity == MessageType.Error ||
                            m.Severity == MessageType.Warning)
                        {
                            context.Errors.Add(new WorkflowMessage("Payment Error:", m.Description, true));
                        }
                    }
                    result = false;
                }
            }
            catch (Exception ex)
            {
                context.Errors.Add(new WorkflowMessage("Exception During Receive Credit Card", ex.Message + ex.StackTrace, false));
                OrderNote note = new OrderNote();
                note.IsPublic = false;
                note.Note     = "EXCEPTION: " + ex.Message + " | " + ex.StackTrace;
                context.Order.Notes.Add(note);
            }

            return(result);
        }
        private void CashReceive(HotcakesApplication app, OrderPaymentManager pm, decimal amount, Order o)
        {
            var t = pm.CreateEmptyTransaction();

            t.Amount = amount;
            t.Action = ActionType.CashReceived;
            var ot = new OrderTransaction(t)
            {
                Success = true, TimeStampUtc = o.TimeOfOrderUtc
            };

            app.OrderServices.AddPaymentTransactionToOrder(o, ot);
        }
        public override bool Execute(OrderTaskContext context)
        {
            var result = true;

            if (context.HccApp.OrderServices.PaymentSummary(context.Order).AmountDueWithAuth > 0)
            {
                List <OrderTransaction> transactions = context.HccApp.OrderServices.Transactions
                                                       .FindForOrder(context.Order.bvin)
                                                       .OrderByDescending(x => x.TimeStampUtc)
                                                       .ToList();

                decimal dueAmount = context.HccApp.OrderServices.PaymentSummary(context.Order).AmountDueWithAuth;

                foreach (OrderTransaction p in transactions)
                {
                    if (p.Action == ActionType.GiftCardInfo)
                    {
                        // if we already have an auth or charge on the card, skip
                        if (p.HasSuccessfulLinkedAction(ActionType.GiftCardDecrease, transactions) ||
                            p.HasSuccessfulLinkedAction(ActionType.GiftCardCapture, transactions) ||
                            p.HasSuccessfulLinkedAction(ActionType.GiftCardHold, transactions))
                        {
                            var note = new OrderNote();
                            note.IsPublic = false;
                            note.Note     = "Skipping receive for gift card info because auth or charge already exists. Transaction " + p.Id;
                            context.Order.Notes.Add(note);
                            continue;
                        }

                        try
                        {
                            var         payManager    = new OrderPaymentManager(context.Order, context.HccApp);
                            var         storeSettings = context.HccApp.CurrentStore.Settings;
                            Transaction t             = payManager.CreateEmptyTransaction();
                            t.GiftCard.CardNumber = p.GiftCard.CardNumber;
                            t.Amount = p.Amount;

                            GiftCardGateway proc = storeSettings.PaymentCurrentGiftCardProcessor();

                            if (storeSettings.PaymentGiftCardAuthorizeOnly && proc.CanAuthorize)
                            {
                                t.Action = ActionType.GiftCardHold;
                            }
                            else
                            {
                                t.Action = ActionType.GiftCardDecrease;
                            }

                            proc.ProcessTransaction(t);

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

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

                        dueAmount = context.HccApp.OrderServices.PaymentSummary(context.Order).AmountDueWithAuth;
                        //Amount required in order is already charged. No need to charge on other transactions
                        if (dueAmount <= 0)
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                var note = new OrderNote();
                note.IsPublic = false;
                note.Note     = "Amount due was less than zero. Skipping receive gift cards";
                context.Order.Notes.Add(note);
            }

            if (!result)
            {
                string errorString = "An error occurred while attempting to process your gift card. Please check your payment information and try again";
                context.Errors.Add(new WorkflowMessage("Receive Gift Card Failed", errorString, true));

                // Failure Status Code
                string          failCode = OrderStatusCode.OnHold;
                OrderStatusCode c        = OrderStatusCode.FindByBvin(failCode);
                if (c != null)
                {
                    context.Order.StatusCode = c.Bvin;
                    context.Order.StatusName = c.StatusName;
                }
            }
            return(result);
        }