/// <summary>
        /// Handles the <see cref="SalePreparationBase"/> finalizing event.  AvaTax require the "quote" be finalized so that 
        /// it can actually be recorded for reporting purposes.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="args">
        /// The args.
        /// </param>
        private void SalePreparationBaseOnFinalizing(SalePreparationBase sender, SalesPreparationEventArgs<IPaymentResult> args)
        {
            var result = args.Entity;
            var invoice = result.Invoice;

            if (!result.Payment.Success) return;

            var taxation = MerchelloContext.Current.Gateways.Taxation;

            var providerKey = new Guid("DBC48C38-0617-44EA-989A-18AAD8D5DE52");

            IAddress taxAddress = null;
            var shippingItems = invoice.ShippingLineItems().ToArray();
            if (shippingItems.Any())
            {
                var shipment = shippingItems.First().ExtendedData.GetShipment<OrderLineItem>();
                taxAddress = shipment.GetDestinationAddress();
            }

            taxAddress = taxAddress ?? invoice.GetBillingAddress();

            var taxMethod = taxation.GetTaxMethodForTaxAddress(taxAddress);

            // If the taxMethod is not found or 
            if (taxMethod == null || !providerKey.Equals(taxMethod.ProviderKey)) return;

            var provider = taxation.GetProviderByKey(taxMethod.ProviderKey) as AvaTaxTaxationGatewayProvider;

            if (provider == null) return;

            var avaTaxMethod = provider.GetAvaTaxationGatewayMethod(taxMethod);

            avaTaxMethod.CalculateTaxForInvoice(invoice, taxAddress, false);
        }
示例#2
0
        private void SalePreparationBaseOnFinalizing(SalePreparationBase sender, SalesPreparationEventArgs <IPaymentResult> args)
        {
            var result = args.Entity;

            if (result.ApproveOrderCreation)
            {
                // order
                var order = result.Invoice.PrepareOrder(MerchelloContext.Current);

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

            var customerKey = result.Invoice.CustomerKey;

            // Clean up the sales prepartation item cache
            if (customerKey == null || Guid.Empty.Equals(customerKey))
            {
                return;
            }
            var customer = MerchelloContext.Current.Services.CustomerService.GetAnyByKey(customerKey.Value);

            if (customer == null)
            {
                return;
            }
            var itemCacheService = MerchelloContext.Current.Services.ItemCacheService;
            var itemCache        = itemCacheService.GetItemCacheByCustomer(customer, ItemCacheType.Checkout);

            itemCacheService.Delete(itemCache);
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InvoiceBuilderChain"/> class.
        /// </summary>
        /// <param name="salePreparation">
        /// The sale preparation.
        /// </param>
        internal InvoiceBuilderChain(SalePreparationBase salePreparation)
        {
            Mandate.ParameterNotNull(salePreparation, "salesPreparation");
            _salePreparation = salePreparation;

            ResolveChain(Core.Constants.TaskChainAlias.SalesPreparationInvoiceCreate);
        }
        /// <summary>
        /// Builds a <see cref="SalePreparationSummary"/>
        /// </summary>
        /// <param name="preparation">
        /// The preparation.
        /// </param>
        /// <returns>
        /// The <see cref="SalePreparationSummary"/>.
        /// </returns>
        public SalePreparationSummary Build(SalePreparationBase preparation)
        {
            if (preparation.IsReadyToInvoice())
            {
                var invoice = preparation.PrepareInvoice();
                return(new SalePreparationSummary()
                {
                    TotalLabel = "Total",
                    CurrencySymbol = _currency.Symbol,
                    Items = invoice.Items.Where(x => x.LineItemType == LineItemType.Product).Select(x => _basketLineItemFactory.Build(x)),
                    ItemTotal = ModelExtensions.FormatPrice(invoice.TotalItemPrice(), _currency.Symbol),
                    ShippingTotal = ModelExtensions.FormatPrice(invoice.TotalShipping(), _currency.Symbol),
                    TaxTotal = ModelExtensions.FormatPrice(invoice.TotalTax(), _currency.Symbol),
                    DiscountsTotal = ModelExtensions.FormatPrice(invoice.TotalDiscounts(), _currency.Symbol),
                    InvoiceTotal = ModelExtensions.FormatPrice(invoice.Total, _currency.Symbol)
                });
            }

            return(new SalePreparationSummary()
            {
                TotalLabel = "Sub Total",
                CurrencySymbol = _currency.Symbol,
                Items = preparation.ItemCache.Items.Select(x => _basketLineItemFactory.Build(x)),
                ItemTotal = ModelExtensions.FormatPrice(preparation.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Product).Sum(x => x.TotalPrice), _currency.Symbol),
                ShippingTotal = ModelExtensions.FormatPrice(preparation.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Shipping).Sum(x => x.TotalPrice), _currency.Symbol),
                TaxTotal = ModelExtensions.FormatPrice(preparation.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Tax).Sum(x => x.TotalPrice), _currency.Symbol),
                DiscountsTotal = ModelExtensions.FormatPrice(preparation.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Discount).Sum(x => x.TotalPrice), _currency.Symbol),
                InvoiceTotal = ModelExtensions.FormatPrice(preparation.ItemCache.Items.Where(x => x.LineItemType != LineItemType.Discount).Sum(x => x.TotalPrice) - preparation.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Discount).Sum(x => x.TotalPrice), _currency.Symbol)
            });
        }
示例#5
0
        protected override IPaymentResult PerformProcessPayment(SalePreparationBase preparation, IPaymentMethod paymentMethod)
        {
            // We have to use the CheckoutConfirmationModel in this implementation.  If this were to be used
            // outside of a demo, you could consider writing your own base controller that inherits directly from
            // Merchello.Web.Mvc.PaymentMethodUiController<TModel> and complete the transaction there in which case the
            // BazaarPaymentMethodFormControllerBase would be a good example.

            var form = UmbracoContext.HttpContext.Request.Form;
            var purchaseOrderNumber = form.Get("purchaseOrderNumber");

            if (string.IsNullOrEmpty(purchaseOrderNumber))
            {
                var invalidData = new InvalidDataException("The Purchase Order Number cannot be an empty string");
                return(new PaymentResult(Attempt <IPayment> .Fail(invalidData), null, false));
            }

            // 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.SetPurchaseOrderNumber(purchaseOrderNumber);

            // We will want this to be an Authorize(paymentMethod.Key, args);
            // -- Also in a real world situation you would want to validate the PO number somehow.
            return(preparation.AuthorizePayment(paymentMethod.Key, args));
        }
示例#6
0
        // AuthorizeCapturePayment will save the invoice with an Invoice Number.
        private IPaymentResult ProcessPayment(SalePreparationBase preparation, 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(preparation.AuthorizeCapturePayment(paymentMethod.Key, args));
        }
示例#7
0
        /// <summary>
        /// Responsible for actually processing the payment with the PaymentProvider
        /// </summary>
        /// <param name="preparation">
        /// The preparation.
        /// </param>
        /// <param name="paymentMethod">
        /// The payment method.
        /// </param>
        /// <returns>
        /// The <see cref="IPaymentResult"/>.
        /// </returns>
        protected override IPaymentResult PerformProcessPayment(SalePreparationBase preparation, IPaymentMethod paymentMethod)
        {
            // ----------------------------------------------------------------------------
            // WE NEED TO GET THE PAYMENT METHOD "NONCE" FOR BRAINTREE

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

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

            return(this.ProcessPayment(preparation, paymentMethod, paymentMethodNonce));
        }
        /// <summary>
        /// Handles the <see cref="SalePreparationBase"/> finalizing event.  AvaTax require the "quote" be finalized so that
        /// it can actually be recorded for reporting purposes.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="args">
        /// The args.
        /// </param>
        private void SalePreparationBaseOnFinalizing(SalePreparationBase sender, SalesPreparationEventArgs <IPaymentResult> args)
        {
            if (!sender.ApplyTaxesToInvoice)
            {
                return;
            }

            var result  = args.Entity;
            var invoice = result.Invoice;

            if (!result.Payment.Success)
            {
                return;
            }

            var taxation = MerchelloContext.Current.Gateways.Taxation;

            var providerKey = new Guid("DBC48C38-0617-44EA-989A-18AAD8D5DE52");

            IAddress taxAddress    = null;
            var      shippingItems = invoice.ShippingLineItems().ToArray();

            if (shippingItems.Any())
            {
                var shipment = shippingItems.First().ExtendedData.GetShipment <OrderLineItem>();
                taxAddress = shipment.GetDestinationAddress();
            }

            taxAddress = taxAddress ?? invoice.GetBillingAddress();

            var taxMethod = taxation.GetTaxMethodForTaxAddress(taxAddress);

            // If the taxMethod is not found or
            if (taxMethod == null || !providerKey.Equals(taxMethod.ProviderKey))
            {
                return;
            }

            var provider = taxation.GetProviderByKey(taxMethod.ProviderKey) as AvaTaxTaxationGatewayProvider;

            if (provider == null)
            {
                return;
            }

            var avaTaxMethod = provider.GetAvaTaxationGatewayMethod(taxMethod);

            avaTaxMethod.CalculateTaxForInvoice(invoice, taxAddress, false);
        }
示例#9
0
    private void SalePreparationBaseOnInvoicePrepared(SalePreparationBase sender, SalesPreparationEventArgs <IInvoice> e)
    {
        // custom line items
        var ed1 = new ExtendedDataCollection();

        ed1.SetValue(Merchello.Core.Constants.ExtendedDataKeys.Taxable, false.ToString());
        ed1.SetValue(Merchello.Core.Constants.ExtendedDataKeys.Shippable, false.ToString());

        var typeField = EnumTypeFieldConverter.LineItemType.Custom("CcFee");

        //// Act
        var ccFee = new InvoiceLineItem(
            typeField.TypeKey,
            "CC Fee",
            "ccfee",
            1,
            1.0m,
            ed1);

        e.Entity.Items.Add(ccFee);
        e.Entity.Total += 1.0m;

        var ed2 = new ExtendedDataCollection();
        var shippingLineItem = e.Entity.ShippingLineItems().FirstOrDefault();

        if (shippingLineItem != null)
        {
            ////
            if (shippingLineItem.Price >= 30)
            {
                var shipping10Off = new InvoiceLineItem(
                    EnumTypeFieldConverter.LineItemType.Discount.TypeKey,
                    "10 Off Shipping",
                    "BreakOnShipping",
                    1,
                    10M,
                    ed2);
                e.Entity.Items.Add(shipping10Off);
                e.Entity.Total -= 10M;
            }
        }
    }
示例#10
0
        private void SalePreparationBaseOnFinalizing(SalePreparationBase sender, SalesPreparationEventArgs <IPaymentResult> salesPreparationEventArgs)
        {
            var result = salesPreparationEventArgs.Entity;

            result.Invoice.AuditCreated();

            if (result.Payment.Success)
            {
                if (result.Invoice.InvoiceStatusKey == Core.Constants.InvoiceStatus.Paid)
                {
                    result.Payment.Result.AuditPaymentCaptured(result.Payment.Result.Amount);
                }
                else
                {
                    result.Payment.Result.AuditPaymentAuthorize(result.Invoice);
                }
            }
            else
            {
                result.Payment.Result.AuditPaymentDeclined();
            }
        }
示例#11
0
        /// <summary>
        /// Records the redemption of a coupon offer.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void SalePreparationBaseOnFinalizing(SalePreparationBase sender, SalesPreparationEventArgs <IPaymentResult> e)
        {
            var invoice = e.Entity.Invoice;

            // get the collection of redemptions to be record
            var visitor = new CouponRedemptionLineItemVisitor(invoice.CustomerKey);

            invoice.Items.Accept(visitor);

            if (!visitor.Redemptions.Any())
            {
                return;
            }

            if (MerchelloContext.Current != null)
            {
                ((ServiceContext)MerchelloContext.Current.Services).OfferRedeemedService.Save(visitor.Redemptions);
            }
            else
            {
                LogHelper.Debug <CouponRedemptionEventHandler>("MerchelloContext was null.  Could not record coupon redemption.");
            }
        }
示例#12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ValidateCommonCurrency"/> class.
 /// </summary>
 /// <param name="salePreparation">
 /// The sale preparation.
 /// </param>
 public ValidateCommonCurrency(SalePreparationBase salePreparation)
     : base(salePreparation)
 {
 }
示例#13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AddCouponDiscountsToInvoiceTask"/> class.
 /// </summary>
 /// <param name="salePreparation">
 /// The <see cref="IBasketSalePreparation"/>.
 /// </param>
 public AddCouponDiscountsToInvoiceTask(SalePreparationBase salePreparation)
     : base(salePreparation)
 {
 }
 /// <summary>
 /// Responsible for actually processing the payment with the PaymentProvider
 /// </summary>
 /// <param name="preparation">
 /// The preparation.
 /// </param>
 /// <param name="paymentMethod">
 /// The payment method.
 /// </param>
 /// <returns>
 /// The <see cref="IPaymentResult"/>.
 /// </returns>
 protected abstract IPaymentResult PerformProcessPayment(SalePreparationBase preparation, IPaymentMethod paymentMethod);
示例#15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ValidateCommonCurrency"/> class.
 /// </summary>
 /// <param name="salePreparation">
 /// The sale preparation.
 /// </param>
 public ValidateCommonCurrency(SalePreparationBase salePreparation)
     : base(salePreparation)
 {            
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AddBillingInfoToInvoiceTask"/> class.
 /// </summary>
 /// <param name="salePreparation">
 /// The sale preparation.
 /// </param>
 public AddBillingInfoToInvoiceTask(SalePreparationBase salePreparation)
     : base(salePreparation)
 {            
 }
示例#17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AddBillingInfoToInvoiceTask"/> class.
 /// </summary>
 /// <param name="salePreparation">
 /// The sale preparation.
 /// </param>
 public AddBillingInfoToInvoiceTask(SalePreparationBase salePreparation)
     : base(salePreparation)
 {
 }
示例#18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InvoiceCreationAttemptChainTaskBase"/> class.
        /// </summary>
        /// <param name="salePreparation">
        /// The sale preparation.
        /// </param>
        protected InvoiceCreationAttemptChainTaskBase(SalePreparationBase salePreparation)
        {
            Mandate.ParameterNotNull(salePreparation, "salePreparation");

            _salePreparation = salePreparation;
        }
        public virtual void Init()
        {
            Customer = PreTestDataWorker.MakeExistingAnonymousCustomer();
            Basket   = Web.Workflow.Basket.GetBasket(MerchelloContext.Current, Customer);

            var odd = true;

            for (var i = 0; i < ProductCount; i++)
            {
                var product = PreTestDataWorker.MakeExistingProduct(true, WeightPerProduct, PricePerProduct);
                product.AddToCatalogInventory(PreTestDataWorker.WarehouseCatalog);
                product.CatalogInventories.First().Count = 10;
                product.TrackInventory = true;
                PreTestDataWorker.ProductService.Save(product);
                Basket.AddItem(product, 2);

                odd = !odd;
            }

            BillingAddress = new Address()
            {
                Name        = "Out there",
                Address1    = "some street",
                Locality    = "some city",
                Region      = "ST",
                PostalCode  = "98225",
                CountryCode = "US"
            };

            var origin = new Address()
            {
                Name        = "Somewhere",
                Address1    = "origin street",
                Locality    = "origin city",
                Region      = "ST",
                PostalCode  = "98225",
                CountryCode = "US"
            };



            PreTestDataWorker.DeleteAllItemCaches();
            PreTestDataWorker.DeleteAllInvoices();


            Customer.ExtendedData.AddAddress(BillingAddress, AddressType.Billing);
            ItemCache = new Core.Models.ItemCache(Customer.Key, ItemCacheType.Checkout);

            PreTestDataWorker.ItemCacheService.Save(ItemCache);

            foreach (var item in Basket.Items)
            {
                ItemCache.AddItem(item.AsLineItemOf <ItemCacheLineItem>());
            }


            // setup the checkout
            SalePreparationMock = new SalePreparationMock(MerchelloContext.Current, ItemCache, Customer);

            // add the shipment rate quote
            var shipment      = Basket.PackageBasket(MerchelloContext.Current, BillingAddress).First();
            var shipRateQuote = shipment.ShipmentRateQuotes(MerchelloContext.Current).FirstOrDefault();

            //_checkoutMock.ItemCache.Items.Add(shipRateQuote.AsLineItemOf<InvoiceLineItem>());
            SalePreparationMock.SaveShipmentRateQuote(shipRateQuote);
        }
示例#20
0
        /// <summary>
        /// The sale preparation base on finalizing.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private static void SalePreparationBaseOnFinalizing(SalePreparationBase sender, SalesPreparationEventArgs <IPaymentResult> e)
        {
            var context = new CheckoutStageResolverContext();

            context.Reset();
        }
示例#21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AddNotesToInvoiceTask"/> class.
 /// </summary>
 /// <param name="salePreparation">
 /// The sale preparation.
 /// </param>
 public AddNotesToInvoiceTask(SalePreparationBase salePreparation)
     : base(salePreparation)
 {
 }
        /// <summary>
        /// Performs audits on SalePrepartionBase.Finalizing
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="salesPreparationEventArgs">
        /// The sales preparation event args.
        /// </param>
        private void SalePreparationBaseOnFinalizing(SalePreparationBase sender, SalesPreparationEventArgs<IPaymentResult> salesPreparationEventArgs)
        {
            var result = salesPreparationEventArgs.Entity;

            result.Invoice.AuditCreated();

            if (result.Payment.Success)
            {
                if (result.Invoice.InvoiceStatusKey == Core.Constants.DefaultKeys.InvoiceStatus.Paid)
                {
                    result.Payment.Result.AuditPaymentCaptured(result.Payment.Result.Amount);
                }
                else
                {
                    result.Payment.Result.AuditPaymentAuthorize(result.Invoice);
                }
            }
            else
            {
                result.Payment.Result.AuditPaymentDeclined();
            }
        }
示例#23
0
 /// <summary>
 /// Responsible for actually processing the payment with the PaymentProvider
 /// </summary>
 /// <param name="preparation">
 /// The preparation.
 /// </param>
 /// <param name="paymentMethod">
 /// The payment method.
 /// </param>
 /// <returns>
 /// The <see cref="IPaymentResult"/>.
 /// </returns>
 protected override IPaymentResult PerformProcessPayment(SalePreparationBase preparation, IPaymentMethod paymentMethod)
 {
     return(preparation.AuthorizePayment(paymentMethod.Key));
 }
示例#24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ApplyTaxesToInvoiceTax"/> class.
 /// </summary>
 /// <param name="salePreparation">
 /// The sale preparation.
 /// </param>
 public ApplyTaxesToInvoiceTax(SalePreparationBase salePreparation)
     : base(salePreparation)
 {            
 }
 public ApplyTaxesToInvoiceTax(SalePreparationBase salePreparation)
     : base(salePreparation)
 {
 }
示例#26
0
 public ConvertItemCacheItemsToInvoiceItemsTask(SalePreparationBase salePreparation)
     : base(salePreparation)
 {
 }