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 DebitOrderNumber = form.Get("DebitOrderNumber"); if (string.IsNullOrEmpty(DebitOrderNumber)) { 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.SetDebitOrderNumber(DebitOrderNumber); // 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); }
/// <summary> /// Builds a <see cref="SalePreparationSummary"/> /// </summary> /// <param name="preparation"> /// The preparation. /// </param> /// <param name="theme">The Bazaar them</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), }; }
// 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); }
/// <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 /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="args"> /// The <see cref="IPaymentResult"/> /// </param> private void SalePreparationBaseOnFinalizing(SalePreparationBase sender, SalesPreparationEventArgs<IPaymentResult> args) { var result = args.Entity; 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); }
/// <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."); } }
/// <summary> /// Handles the <see cref="SalePreparationBase"/> finalizing event /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="args"> /// The <see cref="IPaymentResult"/> /// </param> private void SalePreparationBaseOnFinalizing(SalePreparationBase sender, SalesPreparationEventArgs <IPaymentResult> args) { var result = args.Entity; 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); }
/// <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> /// Initializes a new instance of the <see cref="ApplyTaxesToInvoiceTax"/> class. /// </summary> /// <param name="salePreparation"> /// The sale preparation. /// </param> public ApplyTaxesToInvoiceTax(SalePreparationBase salePreparation) : base(salePreparation) { }
/// <summary> /// Initializes a new instance of the <see cref="ConvertItemCacheItemsToInvoiceItemsTask"/> class. /// </summary> /// <param name="salePreparation"> /// The sale preparation. /// </param> public ConvertItemCacheItemsToInvoiceItemsTask(SalePreparationBase salePreparation) : base(salePreparation) { }
/// <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> /// Initializes a new instance of the <see cref="AddBillingInfoToInvoiceTask"/> class. /// </summary> /// <param name="salePreparation"> /// The sale preparation. /// </param> public AddBillingInfoToInvoiceTask(SalePreparationBase salePreparation) : base(salePreparation) { }
public virtual void Init() { Customer = PreTestDataWorker.MakeExistingAnonymousCustomer(); Basket = Web.Workflow.Basket.GetBasket(MerchelloContext, 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.EntityKey, ItemCacheType.Checkout); PreTestDataWorker.ItemCacheService.Save(ItemCache); foreach (var item in Basket.Items) { ItemCache.AddItem(item.AsLineItemOf<ItemCacheLineItem>()); } // setup the checkout SalePreparationMock = new SalePreparationMock(MerchelloContext, ItemCache, Customer); // add the shipment rate quote var shipment = Basket.PackageBasket(MerchelloContext, BillingAddress).First(); var shipRateQuote = shipment.ShipmentRateQuotes(MerchelloContext).FirstOrDefault(); //_checkoutMock.ItemCache.Items.Add(shipRateQuote.AsLineItemOf<InvoiceLineItem>()); SalePreparationMock.SaveShipmentRateQuote(shipRateQuote); }
/// <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> /// 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); }
/// <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(); }