Exemplo n.º 1
0
        /// <summary>
        /// Creates a <see cref="ICheckoutSummaryModel{TBillingAddress, TShippingAddress, TLineItem}"/>.
        /// </summary>
        /// <param name="checkoutManager">
        /// The <see cref="ICheckoutManagerBase"/>.
        /// </param>
        /// <returns>
        /// The <see cref="ICheckoutSummaryModel{TBillingAddress, TShippingAddress, TLineItem}"/>.
        /// </returns>
        public TSummary Create(ICheckoutManagerBase checkoutManager)
        {
            if (!checkoutManager.Payment.IsReadyToInvoice())
            {
                var logData   = MultiLogger.GetBaseLoggingData();
                var invalidOp = new InvalidOperationException("CheckoutManager is not ready to invoice. Try calling the overloaded Create method passing the IBasket");
                MultiLogHelper.Error <CheckoutSummaryModelFactory <TSummary, TBillingAddress, TShippingAddress, TLineItem> >("Could not create checkout summary", invalidOp, logData);
                throw invalidOp;
            }

            var invoice = checkoutManager.Payment.PrepareInvoice();

            var billing  = invoice.GetBillingAddress();
            var shipping = invoice.GetShippingAddresses().FirstOrDefault();


            return(new TSummary
            {
                BillingAddress = Create <TBillingAddress>(billing ?? new Address {
                    AddressType = AddressType.Billing
                }),
                ShippingAddress = Create <TShippingAddress>(shipping ?? new Address {
                    AddressType = AddressType.Shipping
                }),
                Items = invoice.Items.Select(Create),
                Total = invoice.Total
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Builds a <see cref="SalePreparationSummary"/>
        /// </summary>
        /// <param name="manager">
        /// The preparation.
        /// </param>
        /// <returns>
        /// The <see cref="SalePreparationSummary"/>.
        /// </returns>
        public SalePreparationSummary Build(ICheckoutManagerBase manager)
        {
            if (manager.Payment.IsReadyToInvoice())
            {
                var invoice = manager.Payment.PrepareInvoice();
                return(new SalePreparationSummary()
                {
                    TotalLabel = "Total",
                    Currency = _currency,
                    Items = invoice.Items.Where(x => x.LineItemType == LineItemType.Product).Select(x => _basketLineItemFactory.Build(x)),
                    ItemTotal = ModelExtensions.FormatPrice(invoice.TotalItemPrice(), _currency),
                    ShippingTotal = ModelExtensions.FormatPrice(invoice.TotalShipping(), _currency),
                    TaxTotal = ModelExtensions.FormatPrice(invoice.TotalTax(), _currency),
                    DiscountsTotal = ModelExtensions.FormatPrice(invoice.TotalDiscounts(), _currency),
                    InvoiceTotal = ModelExtensions.FormatPrice(invoice.Total, _currency),
                });
            }

            return(new SalePreparationSummary()
            {
                TotalLabel = "Sub Total",
                Currency = _currency,
                Items = manager.Context.ItemCache.Items.Select(x => _basketLineItemFactory.Build(x)),
                ItemTotal = ModelExtensions.FormatPrice(manager.Context.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Product).Sum(x => x.TotalPrice), _currency),
                ShippingTotal = ModelExtensions.FormatPrice(manager.Context.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Shipping).Sum(x => x.TotalPrice), _currency),
                TaxTotal = ModelExtensions.FormatPrice(manager.Context.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Tax).Sum(x => x.TotalPrice), _currency),
                DiscountsTotal = ModelExtensions.FormatPrice(manager.Context.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Discount).Sum(x => x.TotalPrice), _currency),
                InvoiceTotal = ModelExtensions.FormatPrice(manager.Context.ItemCache.Items.Where(x => x.LineItemType != LineItemType.Discount).Sum(x => x.TotalPrice) - manager.Context.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Discount).Sum(x => x.TotalPrice), _currency),
            });
        }
        /// <summary>
        /// Builds a <see cref="SalePreparationSummary"/>
        /// </summary>
        /// <param name="manager">
        /// The preparation.
        /// </param>
        /// <returns>
        /// The <see cref="SalePreparationSummary"/>.
        /// </returns>
        public SalePreparationSummary Build(ICheckoutManagerBase manager)
        {

            if (manager.Payment.IsReadyToInvoice())
            {
                var invoice = manager.Payment.PrepareInvoice();
                return new SalePreparationSummary()
                           {
                               TotalLabel = "Total",
                               Currency = _currency,
                               Items = invoice.Items.Where(x => x.LineItemType == LineItemType.Product).Select(x => _basketLineItemFactory.Build(x)),
                               ItemTotal = ModelExtensions.FormatPrice(invoice.TotalItemPrice(), _currency),
                               ShippingTotal = ModelExtensions.FormatPrice(invoice.TotalShipping(), _currency),
                               TaxTotal = ModelExtensions.FormatPrice(invoice.TotalTax(), _currency),
                               DiscountsTotal = ModelExtensions.FormatPrice(invoice.TotalDiscounts(), _currency),
                               InvoiceTotal = ModelExtensions.FormatPrice(invoice.Total, _currency),                               
                           };
            }
            
            return new SalePreparationSummary()
                {
                    TotalLabel = "Sub Total",
                    Currency = _currency,
                    Items = manager.Context.ItemCache.Items.Select(x => _basketLineItemFactory.Build(x)),
                    ItemTotal = ModelExtensions.FormatPrice(manager.Context.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Product).Sum(x => x.TotalPrice), _currency),
                    ShippingTotal = ModelExtensions.FormatPrice(manager.Context.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Shipping).Sum(x => x.TotalPrice), _currency),
                    TaxTotal = ModelExtensions.FormatPrice(manager.Context.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Tax).Sum(x => x.TotalPrice), _currency),
                    DiscountsTotal = ModelExtensions.FormatPrice(manager.Context.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Discount).Sum(x => x.TotalPrice), _currency),
                    InvoiceTotal = ModelExtensions.FormatPrice(manager.Context.ItemCache.Items.Where(x => x.LineItemType != LineItemType.Discount).Sum(x => x.TotalPrice) - manager.Context.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Discount).Sum(x => x.TotalPrice), _currency),
                };
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CheckoutInvoiceBuilderChain"/> class.
        /// </summary>
        /// <param name="checkoutManager">
        /// The checkout manager.
        /// </param>
        internal CheckoutInvoiceBuilderChain(ICheckoutManagerBase checkoutManager)
        {
            Mandate.ParameterNotNull(checkoutManager, "checkoutManager");

            _checkoutManager = checkoutManager;

            ResolveChain(Core.Constants.TaskChainAlias.CheckoutManagerInvoiceCreate);
        }
Exemplo n.º 5
0
        /// <summary>
        /// The process payment.
        /// </summary>
        /// <param name="checkoutManager">
        /// Merchello's <see cref="ICheckoutManagerBase"/>.
        /// </param>
        /// <param name="paymentMethod">
        /// The payment method.
        /// </param>
        /// <param name="paymentMethodNonce">
        /// The payment method nonce.
        /// </param>
        /// <returns>
        /// The <see cref="IPaymentResult"/>.
        /// </returns>
        /// <remarks>
        /// AuthorizeCapturePayment will save the invoice with an Invoice Number.
        /// </remarks>
        protected virtual IPaymentResult ProcessPayment(ICheckoutManagerBase checkoutManager, IPaymentMethod paymentMethod, string paymentMethodNonce)
        {
            // You need a ProcessorArgumentCollection for this transaction to store the payment method nonce
            // The braintree package includes an extension method off of the ProcessorArgumentCollection - SetPaymentMethodNonce([nonce]);
            var args = new ProcessorArgumentCollection();

            args.SetPaymentMethodNonce(paymentMethodNonce);

            // We will want this to be an AuthorizeCapture(paymentMethod.Key, args);
            return(checkoutManager.Payment.AuthorizeCapturePayment(paymentMethod.Key, args));
        }
        /// <summary>
        /// Collects the Braintree Token (nonce) and processes the payment.
        /// </summary>
        /// <param name="checkoutManager">
        /// The checkout manager.
        /// </param>
        /// <param name="paymentMethod">
        /// The payment method.
        /// </param>
        /// <returns>
        /// The <see cref="IPaymentResult"/>.
        /// </returns>
        protected override IPaymentResult PerformProcessPayment(ICheckoutManagerBase checkoutManager, IPaymentMethod paymentMethod)
        {
            //// ----------------------------------------------------------------------------
            //// WE NEED TO GET THE PAYMENT METHOD "NONCE" FOR BRAINTREE

            var form = this.UmbracoContext.HttpContext.Request.Form;
            var paymentMethodNonce = form.Get("paypal_payment_method_nonce");

            //// ----------------------------------------------------------------------------

            return(this.ProcessPayment(checkoutManager, paymentMethod, paymentMethodNonce));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a <see cref="ICheckoutSummaryModel{TBillingAddress, TShippingAddress, TLineItem}"/>.
        /// </summary>
        /// <param name="basket">
        /// The <see cref="IBasket"/>.
        /// </param>
        /// <param name="checkoutManager">
        /// The <see cref="ICheckoutManagerBase"/>.
        /// </param>
        /// <returns>
        /// The <see cref="ICheckoutSummaryModel{TBillingAddress, TShippingAddress, TLineItem}"/>.
        /// </returns>
        public TSummary Create(IBasket basket, ICheckoutManagerBase checkoutManager)
        {
            var billing  = checkoutManager.Customer.GetBillToAddress();
            var shipping = checkoutManager.Customer.GetShipToAddress();

            return(new TSummary
            {
                BillingAddress = Create <TBillingAddress>(billing ?? new Address {
                    AddressType = AddressType.Billing
                }),
                ShippingAddress = Create <TShippingAddress>(shipping ?? new Address {
                    AddressType = AddressType.Shipping
                }),
                Items = basket.Items.Select(Create),
                Total = basket.TotalBasketPrice
            });
        }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AddNotesToInvoiceTask"/> class.
 /// </summary>
 /// <param name="checkoutManager">
 /// The <see cref="ICheckoutManagerBase"/>.
 /// </param>
 public AddNotesToInvoiceTask(ICheckoutManagerBase checkoutManager)
     : base(checkoutManager)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConvertItemCacheItemsToInvoiceItemsTask"/> class.
 /// </summary>
 /// <param name="checkoutManager">
 /// The <see cref="ICheckoutManagerBase"/>.
 /// </param>
 public ConvertItemCacheItemsToInvoiceItemsTask(ICheckoutManagerBase checkoutManager)
     : base(checkoutManager)
 {
 }
 /// <summary>
 /// Responsible for actually processing the payment with the PaymentProvider
 /// </summary>
 /// <param name="checkoutManager">
 /// The preparation.
 /// </param>
 /// <param name="paymentMethod">
 /// The payment method.
 /// </param>
 /// <returns>
 /// The <see cref="IPaymentResult"/>.
 /// </returns>
 protected abstract IPaymentResult PerformProcessPayment(ICheckoutManagerBase checkoutManager, IPaymentMethod paymentMethod);
Exemplo n.º 11
0
 /// <summary>
 /// Gets a clone of the ItemCache
 /// </summary>
 /// <param name="checkoutManager">
 /// The <see cref="ICheckoutManagerBase"/>.
 /// </param>
 /// <returns>
 /// The <see cref="IItemCache"/>.
 /// </returns>
 internal static IItemCache CloneItemCache(this ICheckoutManagerBase checkoutManager)
 {
     // The ItemCache needs to be cloned as line items may be altered while applying constraints
     return(CloneItemCache(checkoutManager.Context.ItemCache));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ValidateCommonCurrency"/> class.
 /// </summary>
 /// <param name="checkoutManager">
 /// The <see cref="ICheckoutManagerBase"/>.
 /// </param>
 public ValidateCommonCurrency(ICheckoutManagerBase checkoutManager)
     : base(checkoutManager)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConvertItemCacheItemsToInvoiceItemsTask"/> class.
 /// </summary>
 /// <param name="checkoutManager">
 /// The <see cref="ICheckoutManagerBase"/>.
 /// </param>
 public ConvertItemCacheItemsToInvoiceItemsTask(ICheckoutManagerBase checkoutManager)
     : base(checkoutManager)
 {
 }
Exemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AddCouponDiscountsToInvoiceTask"/> class.
 /// </summary>
 /// <param name="checkoutManager">
 /// The checkout manager.
 /// </param>
 public AddCouponDiscountsToInvoiceTask(ICheckoutManagerBase checkoutManager)
     : base(checkoutManager)
 {
 }
Exemplo n.º 15
0
 /// <summary>
 /// Responsible for actually processing the payment with the PaymentProvider
 /// </summary>
 /// <param name="checkoutManager">
 /// The preparation.
 /// </param>
 /// <param name="paymentMethod">
 /// The payment method.
 /// </param>
 /// <returns>
 /// The <see cref="IPaymentResult"/>.
 /// </returns>
 protected override IPaymentResult PerformProcessPayment(ICheckoutManagerBase checkoutManager, IPaymentMethod paymentMethod)
 {
     return checkoutManager.Payment.AuthorizePayment(paymentMethod.Key);
 }
Exemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AddNotesToInvoiceTask"/> class.
 /// </summary>
 /// <param name="checkoutManager">
 /// The <see cref="ICheckoutManagerBase"/>.
 /// </param>
 public AddNotesToInvoiceTask(ICheckoutManagerBase checkoutManager)
     : base(checkoutManager)
 {
 }
Exemplo n.º 17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CheckoutManagerInvoiceCreationAttemptChainTaskBase"/> class.
        /// </summary>
        /// <param name="checkoutManager">
        /// The checkout manager.
        /// </param>
        protected CheckoutManagerInvoiceCreationAttemptChainTaskBase(ICheckoutManagerBase checkoutManager)
        {
            Mandate.ParameterNotNull(checkoutManager, "checkoutManger");

            this.CheckoutManager = checkoutManager;
        }
Exemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ValidateCommonCurrency"/> class.
 /// </summary>
 /// <param name="checkoutManager">
 /// The <see cref="ICheckoutManagerBase"/>.
 /// </param>
 public ValidateCommonCurrency(ICheckoutManagerBase checkoutManager)
     : base(checkoutManager)
 {
 }
Exemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ApplyTaxesToInvoiceTask"/> class.
 /// </summary>
 /// <param name="checkoutManager">
 /// The checkout manager.
 /// </param>
 public ApplyTaxesToInvoiceTask(ICheckoutManagerBase checkoutManager)
     : base(checkoutManager)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ApplyTaxesToInvoiceTask"/> class.
 /// </summary>
 /// <param name="checkoutManager">
 /// The checkout manager.
 /// </param>
 public ApplyTaxesToInvoiceTask(ICheckoutManagerBase checkoutManager)
     : base(checkoutManager)
 {
 }
Exemplo n.º 21
0
 /// <summary>
 /// Responsible for actually processing the payment with the PaymentProvider
 /// </summary>
 /// <param name="checkoutManager">
 /// The preparation.
 /// </param>
 /// <param name="paymentMethod">
 /// The payment method.
 /// </param>
 /// <returns>
 /// The <see cref="IPaymentResult"/>.
 /// </returns>
 protected override IPaymentResult PerformProcessPayment(ICheckoutManagerBase checkoutManager, IPaymentMethod paymentMethod)
 {
     return(checkoutManager.Payment.AuthorizePayment(paymentMethod.Key));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AddCouponDiscountsToInvoiceTask"/> class.
 /// </summary>
 /// <param name="checkoutManager">
 /// The checkout manager.
 /// </param>
 public AddCouponDiscountsToInvoiceTask(ICheckoutManagerBase checkoutManager)
     : base(checkoutManager)
 {
 }
Exemplo n.º 23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AddInvoiceNumberPrefixTask"/> class.
 /// </summary>
 /// <param name="checkoutManager">
 /// The checkout manager.
 /// </param>
 public AddInvoiceNumberPrefixTask(ICheckoutManagerBase checkoutManager)
     : base(checkoutManager)
 {
 }
Exemplo n.º 24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AddBillingInfoToInvoiceTask"/> class.
 /// </summary>
 /// <param name="checkoutManager">
 /// The checkout manager.
 /// </param>
 public AddBillingInfoToInvoiceTask(ICheckoutManagerBase checkoutManager)
     : base(checkoutManager)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AddBillingInfoToInvoiceTask"/> class.
 /// </summary>
 /// <param name="checkoutManager">
 /// The checkout manager.
 /// </param>
 public AddBillingInfoToInvoiceTask(ICheckoutManagerBase checkoutManager)
     : base(checkoutManager)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AddInvoiceNumberPrefixTask"/> class.
 /// </summary>
 /// <param name="checkoutManager">
 /// The checkout manager.
 /// </param>
 public AddInvoiceNumberPrefixTask(ICheckoutManagerBase checkoutManager)
     : base(checkoutManager)
 {
 }