public ShipmentDisplay NewShipment(ShipmentRequestDisplay shipmentRequest) { try { if (!shipmentRequest.Order.Items.Any()) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "The shipment did not include any line items")); } var merchOrder = _orderService.GetByKey(shipmentRequest.Order.Key); var builder = new ShipmentBuilderChain(MerchelloContext, merchOrder, shipmentRequest.Order.Items.Select(x => x.Key), shipmentRequest.ShipMethodKey, shipmentRequest.ShipmentStatusKey, shipmentRequest.TrackingNumber); var attempt = builder.Build(); if (!attempt.Success) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, attempt.Exception)); } return(attempt.Result.ToShipmentDisplay()); } catch (Exception ex) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, string.Format("{0}", ex.Message))); } }
public ShipmentDisplay NewShipment(OrderDisplay order) { try { if (!order.Items.Any()) { throw new InvalidOperationException("The shipment did not include any line items"); } var merchOrder = _orderService.GetByKey(order.Key); var builder = new ShipmentBuilderChain(MerchelloContext, order.ToOrder(merchOrder)); var attempt = builder.Build(); if (!attempt.Success) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, attempt.Exception)); } return(attempt.Result.ToShipmentDisplay()); } catch (Exception ex) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, String.Format("{0}", ex.Message))); } }
public void ShipmentBuilder_Creates_And_Saves_A_Shipment_And_OrderLineItems_Are_Updated() { //// Arrage var builder = new ShipmentBuilderChain(MerchelloContext, _order); //// Act var attempt = builder.Build(); if(!attempt.Success) Console.WriteLine(attempt.Exception.Message); //// Assert Assert.IsTrue(attempt.Success); }
public void ShipmentBuilder_Creates_And_Saves_A_Shipment_And_OrderLineItems_Are_Updated() { //// Arrange var builder = new ShipmentBuilderChain(MerchelloContext.Current, _order, _order.Items.Select(x => x.Key), _shipMethodKey.GetValueOrDefault(), Constants.DefaultKeys.ShipmentStatus.Quoted, "test-tracking"); //// Act var attempt = builder.Build(); if (!attempt.Success) Console.WriteLine(attempt.Exception.Message); //// Assert Assert.IsTrue(attempt.Success); }
public void Can_Save_A_Shipment_After_Its_Built() { //// Arrange var shipmentService = MerchelloContext.Services.ShipmentService; var builder = new ShipmentBuilderChain(MerchelloContext, _order, _order.Items.Select(x => x.Key)); var attempt = builder.Build(); Assert.IsTrue(attempt.Success, "Failed to build shipment"); //// Act var shipment = attempt.Result; shipmentService.Save(shipment); //// Assert Assert.IsTrue(shipment.HasIdentity); }
public void Can_Save_A_Shipment_After_Its_Built() { //// Arrange var shipmentService = MerchelloContext.Current.Services.ShipmentService; var builder = new ShipmentBuilderChain(MerchelloContext.Current, _order, _order.Items.Select(x => x.Key), _shipMethodKey.GetValueOrDefault(), Constants.DefaultKeys.ShipmentStatus.Quoted, "test-tracking"); var attempt = builder.Build(); Assert.IsTrue(attempt.Success, "Failed to build shipment"); //// Act var shipment = attempt.Result; shipmentService.Save(shipment); //// Assert Assert.IsTrue(shipment.HasIdentity); }
public void ShipmentBuilder_Creates_And_Saves_A_Shipment_And_OrderLineItems_Are_Updated() { //// Arrage var builder = new ShipmentBuilderChain(MerchelloContext, _order, _order.Items.Select(x => x.Key)); //// Act var attempt = builder.Build(); if (!attempt.Success) { Console.WriteLine(attempt.Exception.Message); } //// Assert Assert.IsTrue(attempt.Success); }
public void ShipmentBuilder_Creates_And_Saves_A_Shipment_And_OrderLineItems_Are_Updated() { //// Arrange var builder = new ShipmentBuilderChain(MerchelloContext.Current, _order, _order.Items.Select(x => x.Key), _shipMethodKey.GetValueOrDefault(), Constants.ShipmentStatus.Quoted, "test-tracking", "http://somewhere.com", "carrier"); //// Act var attempt = builder.Build(); if (!attempt.Success) { Console.WriteLine(attempt.Exception.Message); } //// Assert Assert.IsTrue(attempt.Success); }
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", "http://url.com", "carrier"); var attempt = builder.Build(); Assert.IsTrue(attempt.Success); }
public void Can_Save_A_Shipment_After_Its_Built() { //// Arrange var shipmentService = MerchelloContext.Current.Services.ShipmentService; var builder = new ShipmentBuilderChain(MerchelloContext.Current, _order, _order.Items.Select(x => x.Key), _shipMethodKey.GetValueOrDefault(), Constants.ShipmentStatus.Quoted, "test-tracking", "http://somewhere.com", "carrier"); var attempt = builder.Build(); Assert.IsTrue(attempt.Success, "Failed to build shipment"); //// Act var shipment = attempt.Result; shipmentService.Save(shipment); //// Assert Assert.IsTrue(shipment.HasIdentity); }
public void Can_Save_A_Shipment_After_Its_Built() { //// Arrange var shipmentService = MerchelloContext.Services.ShipmentService; var builder = new ShipmentBuilderChain(MerchelloContext, _order, _order.Items.Select(x => x.Key), Constants.DefaultKeys.ShipmentStatus.Quoted); var attempt = builder.Build(); Assert.IsTrue(attempt.Success, "Failed to build shipment"); //// Act var shipment = attempt.Result; shipmentService.Save(shipment); //// Assert Assert.IsTrue(shipment.HasIdentity); }
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); }
public ShipmentDisplay NewShipment(ShipmentRequestDisplay shipmentRequest) { try { if (!shipmentRequest.Order.Items.Any()) throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "The shipment did not include any line items")); var merchOrder = _orderService.GetByKey(shipmentRequest.Order.Key); var builder = new ShipmentBuilderChain(MerchelloContext, merchOrder, shipmentRequest.Order.Items.Select(x => x.Key), shipmentRequest.ShipMethodKey, shipmentRequest.ShipmentStatusKey, shipmentRequest.TrackingNumber); var attempt = builder.Build(); if (!attempt.Success) throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, attempt.Exception)); return attempt.Result.ToShipmentDisplay(); } catch (Exception ex) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, String.Format("{0}", ex.Message))); } }
public ShipmentDisplay NewShipment(OrderDisplay order) { try { if(!order.Items.Any()) throw new InvalidOperationException("The shipment did not include any line items"); var merchOrder = _orderService.GetByKey(order.Key); var builder = new ShipmentBuilderChain(MerchelloContext, order.ToOrder(merchOrder)); var attempt = builder.Build(); if(!attempt.Success) throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, attempt.Exception)); return attempt.Result.ToShipmentDisplay(); } catch (Exception ex) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, String.Format("{0}", ex.Message))); } }