Пример #1
0
        public static IPayment PaymentForInserting(Guid paymentMethodKey, PaymentMethodType paymentMethodType, decimal amount, Guid? customerKey = null)
        {
            var payment = new Payment(paymentMethodType, amount, paymentMethodKey)
            {
                CustomerKey = customerKey
            };

            return payment;
        }
Пример #2
0
        public void Can_Detect_A_ShipmentStatusChange()
        {
            //// Arrange
            var address = new Address()
                              {
                                  Address1 = "111 Somewhere St.",
                                  Locality = "Bellingham",
                                  Region = "WA",
                                  PostalCode = "98225",
                                  CountryCode = "US",
                                  Name = "Merchello"
                              };

            var invoice = MockInvoiceDataMaker.GetMockInvoiceForTaxation();

            var payment = new Payment(PaymentMethodType.Cash, invoice.Total) { Collected = true, Authorized = true };

            MerchelloContext.Current.Services.PaymentService.Save(payment);

            MerchelloContext.Current.Services.InvoiceService.Save(invoice);

            var appliedPaymentService = ((ServiceContext)(MerchelloContext.Current.Services)).AppliedPaymentService;

            var appliedPayment = appliedPaymentService.CreateAppliedPaymentWithKey(
                payment.Key,
                invoice.Key,
                AppliedPaymentType.Debit,
                "Payment applied",
                payment.Amount);

            invoice = MerchelloContext.Current.Services.InvoiceService.GetByKey(invoice.Key);

            Assert.NotNull(invoice);

            var order = invoice.PrepareOrder();

            MerchelloContext.Current.Services.OrderService.Save(order);

            var builder = new ShipmentBuilderChain(MerchelloContext.Current, order, order.Items.Select(x => x.Key), Guid.NewGuid(), Constants.DefaultKeys.ShipmentStatus.Packaging, "Track");

            var attempt = builder.Build();

            Assert.IsTrue(attempt.Success);
        }
Пример #3
0
        /// <summary>
        /// Creates and saves a payment
        /// </summary>
        /// <param name="paymentTfKey">The payment typefield key</param>
        /// <param name="amount">The amount of the payment</param>
        /// <param name="paymentMethodKey">The optional paymentMethodKey</param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param>
        /// <returns>Returns <see cref="IPayment"/></returns>
        internal IPayment CreatePaymentWithKey(Guid paymentTfKey, decimal amount, Guid? paymentMethodKey, bool raiseEvents = true)
        {
            Mandate.ParameterCondition(!Guid.Empty.Equals(paymentTfKey), "paymentTfKey");

            var payment = new Payment(paymentTfKey, amount, paymentMethodKey, new ExtendedDataCollection());

            if (raiseEvents)
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs<IPayment>(payment), this))
                {
                    payment.WasCancelled = true;
                    return payment;
                }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreatePaymentRepository(uow))
                {
                    repository.AddOrUpdate(payment);
                    uow.Commit();
                }
            }

            if (raiseEvents) Created.RaiseEvent(new Events.NewEventArgs<IPayment>(payment), this);

            return payment;
        }
Пример #4
0
        /// <summary>
        /// Creates a payment without saving it to the database
        /// </summary>
        /// <param name="paymentMethodType">The type of the payment method</param>
        /// <param name="amount">The amount of the payment</param>
        /// <param name="paymentMethodKey">The optional payment method Key</param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param>
        /// <returns>Returns <see cref="IPayment"/></returns>
        public IPayment CreatePayment(PaymentMethodType paymentMethodType, decimal amount, Guid? paymentMethodKey, bool raiseEvents = true)
        {
            var payment = new Payment(paymentMethodType, amount, paymentMethodKey);

            if(raiseEvents)
            if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs<IPayment>(payment), this))
            {
                payment.WasCancelled = true;
                return payment;
            }

            if (raiseEvents)
            Created.RaiseEvent(new Events.NewEventArgs<IPayment>(payment), this);

            return payment;
        }