Пример #1
0
        public override void Execute(Payment.Payment payment)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(string.Format("Send email, {0} <br />", Description));
            Console.WriteLine(sb.ToString());
        }
Пример #2
0
        public Task <Payment.Payment> Store(Guid paymentId, MaskedPaymentRequest paymentRequest, PaymentResponse paymentResponse)
        {
            var payment = new Payment.Payment(paymentRequest, paymentResponse);

            _payments.Add(paymentId, new Payment.Payment(paymentRequest, paymentResponse));

            return(Task.FromResult(payment));
        }
Пример #3
0
        public override void Execute(Payment.Payment payment)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(string.Format("Issue a package slip, {0} <br />", Description));

            string path = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();

            Common.IO.FileHelper.Writefile(string.Format("{0}\\log.txt", path), sb.ToString());
        }
Пример #4
0
 public void ProcessPayment(Payment.Payment payment, string description)
 {
     // TODO: support transactions !!!
     foreach (var rule in Rules)
     {
         if (rule.IsRuleMatchForPayment(payment))
         {
             foreach (var item in rule.Actions)
             {
                 var action = new ActionExecuter.Factories.ActionExecuterFactory(_CacheProvider).CreateActionExecuter(item.Type, description);
                 action.Execute(payment);
             }
         }
     }
 }
Пример #5
0
 public void AddPayment(Payment.Payment payment)
 {
     if (payment.Amount == 0)
     {
         throw new InvalidChargeException("Cannot add payment to invoice, invalid amount");
     }
     if (payment.Currency != this.Currency)
     {
         throw new InvalidChargeException("Cannot add payment to invoice, invalid currency");
     }
     if (payment.Date.Year != this.Year || payment.Date.Month != this.Month)
     {
         throw new InvalidChargeException("Cannot add payment to invoice, invalid charge date");
     }
     Payments.Add(payment);
 }
Пример #6
0
        public bool IsRuleMatchForPayment(Payment.Payment payment, List <Criteria> criterias)
        {
            if (criterias == null || criterias.Count == 0)
            {
                throw new RequiredException("Criteria's is required");
            }

            // if one criteria is available
            if (criterias.Count == 1)
            {
                return(criterias[0].IsMatched(payment));
            }

            // chained criteria
            bool ruleMatchedToPayment = true;

            foreach (var item in criterias)
            {
                bool criteriaMtched = item.IsMatched(payment);

                if (item.ChainedCriteria == ChainedCriteria.And)
                {
                    ruleMatchedToPayment = ruleMatchedToPayment && criteriaMtched;
                }
                else if (item.ChainedCriteria == ChainedCriteria.Or)
                {
                    ruleMatchedToPayment = ruleMatchedToPayment || criteriaMtched;
                }

                // not matched
                if (ruleMatchedToPayment == false)
                {
                    break;
                }
            }

            return(ruleMatchedToPayment);
        }
Пример #7
0
 public bool IsMatched(Payment.Payment payment)
 {
     return(_CriteriaRuleHandler.IsMatched(payment, this));
 }
Пример #8
0
        public bool IsMatched(Payment.Payment payment, Criteria cirteria)
        {
            bool criteriaMatched = false;

            // check the CriteriaType
            switch (cirteria.CriteriaType)
            {
            case CriteriaType.ProductTag:
            {
                if (cirteria.CriteriaOperator == CriteriaOperator.Equal)
                {
                    // if payment is done for this productTag
                    if (payment.Product.ProductTag.Where(p => p.Id == int.Parse(cirteria.Value)).Count() > 0)
                    {
                        criteriaMatched = true;
                    }
                }
                break;
            }

            case CriteriaType.ProductId:
            {
                if (cirteria.CriteriaOperator == CriteriaOperator.Equal)
                {
                    // if payment is done for this product
                    if (payment.Product.Id == int.Parse(cirteria.Value))
                    {
                        criteriaMatched = true;
                    }
                }
                break;
            }

            case CriteriaType.ProductPrice:
            {
                if (cirteria.CriteriaOperator == CriteriaOperator.Equal)
                {
                    // if payment price is equal with criteria value
                    if (payment.Product.Price == decimal.Parse(cirteria.Value.ToString()))
                    {
                        criteriaMatched = true;
                    }
                }
                else if (cirteria.CriteriaOperator == CriteriaOperator.BiggerThan)
                {
                    // if payment price is equal with criteria value
                    if (payment.Product.Price > decimal.Parse(cirteria.Value.ToString()))
                    {
                        criteriaMatched = true;
                    }
                }
                else if (cirteria.CriteriaOperator == CriteriaOperator.LessThan)
                {
                    // if payment price is equal with criteria value
                    if (payment.Product.Price < decimal.Parse(cirteria.Value.ToString()))
                    {
                        criteriaMatched = true;
                    }
                }
                break;
            }

            default:
            {
                break;
            }
            }

            return(criteriaMatched);
        }
Пример #9
0
 public bool IsRuleMatchForPayment(Payment.Payment payment)
 {
     return(_RuleHandler.IsRuleMatchForPayment(payment, this.Criterias));
 }
Пример #10
0
 public abstract void Execute(Payment.Payment payment);