Пример #1
0
        // Load will return null if the dalItem is not found, or throw an exception if an error happens
        public static Payment Load(int paymentId)
        {
            DAL.CustomersDataContext dc = new DAL.CustomersDataContext();
            DAL.PaymentHeader ph = findRecord(dc, paymentId);

            Payment bo = new Payment();
            map(ph, PaymentTransaction.LoadWithPaymentId(dc, paymentId), bo);

            return bo;
        }
Пример #2
0
        public void Setup()
        {
            dbConnStr = buildConnectionString(CustomerManagementTest.Properties.Settings.Default.TestDb, () => DateTimeOffset.UtcNow.ToString("yyyy-MM-dd_hh:mm:ssZ"));

            using (var db = new CustomerContext(dbConnStr))
            {
                var payment = new Payment {Amount=300M, Response="response", StatusCode="code" };
                db.Save(payment);
                db.SaveChanges();
                id = payment.Id;
            }
        }
Пример #3
0
        public Payment UpdatePayment(long paymentId, Payment pay)
        {
            using (var db = Db())
            {
                var payment = db.Payments.FirstOrDefault(p => p.Id == paymentId);
                if (payment == null)
                    throw new ArgumentNullException("Payment does not exist");
                db.Attach(payment);

                payment.Amount = pay.Amount;
                payment.Response = pay.Response;
                payment.StatusCode = pay.StatusCode;

                db.SaveChanges();
                return pay;
            }
        }
Пример #4
0
        // link to invoice
        public Payment CreatePayment(long invoiceId, long paymentTypeId, decimal amount, string response, string statuscode)
        {
            using (var db = Db())
            {
                var invoice = db.Invoices.FirstOrDefault(i => i.Id == invoiceId);

                if (invoice == null)
                    throw new ArgumentNullException("Invoice does not exist");

                var paymentType = db.PaymentTypes.FirstOrDefault(p => p.Id == paymentTypeId);

                if (paymentType == null)
                    throw new ArgumentNullException("Payment Type does not exist");

                db.Attach(paymentType);
                db.Attach(invoice);
                var payment = new Payment
                {
                    Invoice=invoice,
                    Amount = amount,
                    Response = response,
                    StatusCode = statuscode,
                    PaymentType = paymentType
                };

                db.Save(payment);
                db.SaveChanges();

                return payment;
            }
        }
        internal static Payment createRandomPayment()
        {
            Invoice i = createRandomInvoice();
            i.Save();

            Payment p = new Payment();
            p.InvoiceId = i.Id;
            p.LastFourDigitsOfCreditCard = (short) rnd.Next(10000);
            p.ExpirationMonth = (byte) rnd.Next(12);
            p.ExpirationYear = (short) (2010 + rnd.Next(100));
            p.PaymentTransactions.Add(createRandomPaymentTransaction());

            return p;
        }
Пример #6
0
        private void map(DAL.CustomersDataContext dc, Payment payment, DAL.PaymentHeader dalPaymentHeader)
        {
            bool isNew = payment.Id == 0;
            bool isModified = false;

            if (dalPaymentHeader.InvoiceHeaderId != payment.InvoiceId)
            {
                dalPaymentHeader.InvoiceHeaderId = payment.InvoiceId;
                isModified = true;
            }

            if (dalPaymentHeader.LastFourDigitsOfCreditCard != payment.LastFourDigitsOfCreditCard)
            {
                dalPaymentHeader.LastFourDigitsOfCreditCard = payment.LastFourDigitsOfCreditCard;
                isModified = true;
            }

            if (dalPaymentHeader.ExpirationMonth != payment.ExpirationMonth)
            {
                dalPaymentHeader.ExpirationMonth = payment.ExpirationMonth;
                isModified = true;
            }

            if (dalPaymentHeader.ExpirationYear != payment.ExpirationYear)
            {
                dalPaymentHeader.ExpirationYear = payment.ExpirationYear;
                isModified = true;
            }

            if (isNew)
            {
                dalPaymentHeader.CreatedBy = payment.LastChangedBy;
                dalPaymentHeader.CreatedDate = DateTime.Now;
            }

            if (isModified)
            {
                dalPaymentHeader.LastChangedBy = payment.LastChangedBy;
                dalPaymentHeader.LastChangedDate = DateTime.Now;
            }
        }
Пример #7
0
        private static void map(DAL.PaymentHeader ph, IEnumerable<PaymentTransaction> paymentTransactions, Payment bo)
        {
            bo.Id = ph.Id;
            bo.InvoiceId = ph.InvoiceHeaderId;
            bo.LastFourDigitsOfCreditCard = ph.LastFourDigitsOfCreditCard;
            bo.ExpirationMonth = ph.ExpirationMonth;
            bo.ExpirationYear = ph.ExpirationYear;

            bo.PaymentTransactions = new List<PaymentTransaction>(paymentTransactions);
        }
        public void TestUpdatePayment()
        {
            List<UiItem> uiitems = new List<UiItem>
            {
                    new UiItem {Item=items[0], Pricing=items[0].ItemPricings[0], ItemUnits=3},
                    new UiItem {Item=items[1], Pricing=items[1].ItemPricings[0], ItemUnits=4},
                    new UiItem {Item=items[2], Pricing=items[2].ItemPricings[0], ItemUnits=5},
            };

            var invoice = cs.CreateInvoice(customer.Id, Invoice.Type.Invoice, uiitems, "Note", "Payment Note");
            var paymenttype = cs.CreatePaymentType(customer.Id, "Source", 3);
            var payment = cs.CreatePayment(invoice.Id, paymenttype.Id, 120M, "Response", "statusCode");
            var  updatepaym = new Payment { Response = "Response update", StatusCode = "code update", Amount = 100M};
            cs.UpdatePayment(payment.Id, updatepaym);
            var updatedpayment = cs.GetPayment(payment.Id);

            Assert.IsTrue(updatedpayment.Response=="Response update" && updatedpayment.StatusCode=="code update" && updatedpayment.Amount==100M, "Not all fields are updated correctly");
        }