コード例 #1
0
        internal BasicResult AddPaymentToTransaction1(string transaction1Id, TransactionResult data)
        {
            if (string.IsNullOrEmpty(transaction1Id))
            {
                throw new ArgumentException("The value cannot be empty", "transaction1Id");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            using (var session = this.store.Write())
            {
                var result = new BasicResult();
                var tran   = session.Data.Transactions1.SingleOrDefault(t => t.OrderId == transaction1Id);
                result.Data["Transaction"] = tran;

                if (tran == null)
                {
                    result.Errors.Add(new BasicResultError("Cannot find transaction " + transaction1Id));
                    return(result);
                }

                var paymentIds = tran.PaymentIds ?? new List <string>();
                tran.PaymentIds = paymentIds;
                if (paymentIds.Contains(data.OrderId))
                {
                    result.Errors.Add(new BasicResultError("This payment is already associated with this item"));
                    return(result);
                }

                if (data.AmountCents != null)
                {
                    paymentIds.Add(data.OrderId);

                    tran.AmountPaid += (data.AmountCents.Value / 100M);
                }

                if (tran.AmountPaid >= tran.Amount)
                {
                    tran.IsPaid = true;
                }

                session.Save();
                result.Succeed = true;
                return(result);
            }
        }
コード例 #2
0
        internal BasicResult AddPaymentToTransaction1(string transaction1Id, string paymentId)
        {
            if (string.IsNullOrEmpty(transaction1Id))
            {
                throw new ArgumentException("The value cannot be empty", "transaction1Id");
            }
            if (string.IsNullOrEmpty(paymentId))
            {
                throw new ArgumentException("The value cannot be empty", "paymentId");
            }

            using (var session = this.store.Write())
            {
                var result = new BasicResult();
                var tran   = session.Data.Transactions1.SingleOrDefault(t => t.OrderId == transaction1Id);

                if (tran == null)
                {
                    result.Errors.Add(new BasicResultError("Cannot find transaction " + transaction1Id));
                    return(result);
                }

                if (tran.PaymentIds != null && tran.PaymentIds.Contains(paymentId))
                {
                    result.Errors.Add(new BasicResultError("Payment " + paymentId + " in already associated with this transaction"));
                    return(result);
                }

                tran.PaymentIds = tran.PaymentIds ?? new List <string>();
                tran.PaymentIds.Add(paymentId);

                session.Save();
                result.Succeed = true;
                return(result);
            }
        }
コード例 #3
0
        internal BasicResult AddPaymentToTransaction1(string transaction1Id, string paymentId)
        {
            if (string.IsNullOrEmpty(transaction1Id))
                throw new ArgumentException("The value cannot be empty", "transaction1Id");
            if (string.IsNullOrEmpty(paymentId))
                throw new ArgumentException("The value cannot be empty", "paymentId");

            using (var session = this.store.Write())
            {
                var result = new BasicResult();
                var tran = session.Data.Transactions1.SingleOrDefault(t => t.OrderId == transaction1Id);

                if (tran == null)
                {
                    result.Errors.Add(new BasicResultError("Cannot find transaction " + transaction1Id));
                    return result;
                }

                if (tran.PaymentIds != null && tran.PaymentIds.Contains(paymentId))
                {
                    result.Errors.Add(new BasicResultError("Payment " + paymentId + " in already associated with this transaction"));
                    return result;
                }

                tran.PaymentIds = tran.PaymentIds ?? new List<string>();
                tran.PaymentIds.Add(paymentId);

                session.Save();
                result.Succeed = true;
                return result;
            }
        }
コード例 #4
0
        internal BasicResult AddPaymentToTransaction1(string transaction1Id, TransactionResult data)
        {
            if (string.IsNullOrEmpty(transaction1Id))
                throw new ArgumentException("The value cannot be empty", "transaction1Id");
            if (data == null)
                throw new ArgumentNullException("data");

            using (var session = this.store.Write())
            {
                var result = new BasicResult();
                var tran = session.Data.Transactions1.SingleOrDefault(t => t.OrderId == transaction1Id);
                result.Data["Transaction"] = tran;

                if (tran == null)
                {
                    result.Errors.Add(new BasicResultError("Cannot find transaction " + transaction1Id));
                    return result;
                }

                var paymentIds = tran.PaymentIds ?? new List<string>();
                tran.PaymentIds = paymentIds;
                if (paymentIds.Contains(data.OrderId))
                {
                    result.Errors.Add(new BasicResultError("This payment is already associated with this item"));
                    return result;
                }

                if (data.AmountCents != null)
                {
                    paymentIds.Add(data.OrderId);

                    tran.AmountPaid += (data.AmountCents.Value / 100M);
                }

                if (tran.AmountPaid >= tran.Amount)
                {
                    tran.IsPaid = true;
                }

                session.Save();
                result.Succeed = true;
                return result;
            }
        }