public static IInvoice GetMockInvoiceForTaxation() { var origin = new Address() { Organization = "Mindfly Web Design Studios", Address1 = "114 W. Magnolia St. Suite 300", Locality = "Bellingham", Region = "WA", PostalCode = "98225", CountryCode = "US", Email = "*****@*****.**", Phone = "555-555-5555" }; var billToShipTo = new Address() { Name = "Space Needle", Address1 = "400 Broad St", Locality = "Seattle", Region = "WA", PostalCode = "98109", CountryCode = "US", }; var invoiceService = new InvoiceService(); var invoice = invoiceService.CreateInvoice(Core.Constants.DefaultKeys.InvoiceStatus.Unpaid); invoice.SetBillingAddress(billToShipTo); var extendedData = new ExtendedDataCollection(); // this is typically added automatically in the checkout workflow extendedData.SetValue(Core.Constants.ExtendedDataKeys.CurrencyCode, "USD"); extendedData.SetValue(Core.Constants.ExtendedDataKeys.Taxable, true.ToString()); // make up some line items var l1 = new InvoiceLineItem(LineItemType.Product, "Item 1", "I1", 10, 1, extendedData); var l2 = new InvoiceLineItem(LineItemType.Product, "Item 2", "I2", 2, 40, extendedData); invoice.Items.Add(l1); invoice.Items.Add(l2); var shipment = new ShipmentMock(origin, billToShipTo, invoice.Items); var shipmethod = new ShipMethodMock(); var quote = new ShipmentRateQuote(shipment, shipmethod) { Rate = 16.22M }; invoice.Items.Add(quote.AsLineItemOf<InvoiceLineItem>()); invoice.Total = invoice.Items.Sum(x => x.TotalPrice); return invoice; }
public void Init() { var billTo = new Address() { Organization = "Mindfly Web Design Studios", Address1 = "114 W. Magnolia St. Suite 504", Locality = "Bellingham", Region = "WA", PostalCode = "98225", CountryCode = "US", Email = "*****@*****.**", Phone = "555-555-5555" }; // create an invoice var invoiceService = new InvoiceService(); _invoice = invoiceService.CreateInvoice(Core.Constants.DefaultKeys.InvoiceStatus.Unpaid); _invoice.SetBillingAddress(billTo); _invoice.Total = 120M; var extendedData = new ExtendedDataCollection(); // this is typically added automatically in the checkout workflow extendedData.SetValue(Core.Constants.ExtendedDataKeys.CurrencyCode, "USD"); // make up some line items var l1 = new InvoiceLineItem(LineItemType.Product, "Item 1", "I1", 10, 1, extendedData); var l2 = new InvoiceLineItem(LineItemType.Product, "Item 2", "I2", 2, 40, extendedData); var l3 = new InvoiceLineItem(LineItemType.Shipping, "Shipping", "shipping", 1, 10M, extendedData); var l4 = new InvoiceLineItem(LineItemType.Tax, "Tax", "tax", 1, 10M, extendedData); _invoice.Items.Add(l1); _invoice.Items.Add(l2); _invoice.Items.Add(l3); _invoice.Items.Add(l4); var processorSettings = new AuthorizeNetProcessorSettings { LoginId = ConfigurationManager.AppSettings["xlogin"], TransactionKey = ConfigurationManager.AppSettings["xtrankey"], UseSandbox = true }; Provider.GatewayProviderSettings.ExtendedData.SaveProcessorSettings(processorSettings); if (Provider.PaymentMethods.Any()) return; var resource = Provider.ListResourcesOffered().ToArray(); Provider.CreatePaymentMethod(resource.First(), "Credit Card", "Credit Card"); }
public void Init() { var billTo = new Address() { Organization = "Flightpath", Address1 = "36 West 25th Street", Locality = "New York", Region = "NY", PostalCode = "10010", CountryCode = "US", Email = "*****@*****.**", Phone = "212-555-5555" }; // create an invoice var invoiceService = new InvoiceService(); _invoice = invoiceService.CreateInvoice(Core.Constants.DefaultKeys.InvoiceStatus.Unpaid); _invoice.SetBillingAddress(billTo); _invoice.Total = 120M; var extendedData = new ExtendedDataCollection(); // this is typically added automatically in the checkout workflow extendedData.SetValue(Core.Constants.ExtendedDataKeys.CurrencyCode, "USD"); // make up some line items var l1 = new InvoiceLineItem(LineItemType.Product, "Item 1", "I1", 10, 1, extendedData); var l2 = new InvoiceLineItem(LineItemType.Product, "Item 2", "I2", 2, 40, extendedData); var l3 = new InvoiceLineItem(LineItemType.Shipping, "Shipping", "shipping", 1, 10M, extendedData); var l4 = new InvoiceLineItem(LineItemType.Tax, "Tax", "tax", 1, 10M, extendedData); _invoice.Items.Add(l1); _invoice.Items.Add(l2); _invoice.Items.Add(l3); _invoice.Items.Add(l4); var processorSettings = new StripeProcessorSettings { ApiKey = ConfigurationManager.AppSettings["stripeApiKey"] }; Provider.GatewayProviderSettings.ExtendedData.SaveProcessorSettings(processorSettings); if (Provider.PaymentMethods.Any()) return; var resource = Provider.ListResourcesOffered().ToArray(); Provider.CreatePaymentMethod(resource.First(), "Credit Card", "Credit Card"); }
/// <summary> /// Maps <see cref="AdjustmentLineItemReference"/> to <see cref="IInvoiceLineItem"/>. /// </summary> /// <param name="adj"> /// The adj. /// </param> /// <returns> /// The <see cref="IInvoiceLineItem"/>. /// </returns> public static IInvoiceLineItem ToInvoiceLineItem(this AdjustmentLineItemReference adj) { var item = new InvoiceLineItem(LineItemType.Adjustment, adj.Name, Guid.NewGuid().ToString(), 1, adj.Price); if (adj.Key.Equals(Guid.Empty)) { item.ExtendedData.SetValue("userName", adj.UserName); item.ExtendedData.SetValue("email", adj.Email); } else { item.Key = adj.Key; } return item; }
public void Can_Create_An_Invoice_With_A_CustomLineItem() { //// Arrange var invoice = MockInvoiceDataMaker.GetMockInvoiceForTaxation(); Assert.NotNull(invoice, "Invoice is null"); var extendedData = new ExtendedDataCollection(); extendedData.SetValue(Constants.ExtendedDataKeys.Taxable, false.ToString()); var typeField = EnumTypeFieldConverter.LineItemType.Custom("CcFee"); //// Act var ccFee = new InvoiceLineItem( typeField.TypeKey, "CC Fee", "ccfee", 1, 1.0m, extendedData); invoice.Items.Add(ccFee); Assert.IsTrue(invoice.CustomLineItems().Any()); }
public void Can_Create_A_Customer_Invoice_And_Order() { // Adding the shipmethod is typically done in the back office through the UI. // Interested in the use case to dynamically add theses? var key = Constants.ProviderKeys.Shipping.FixedRateShippingProviderKey; var defaultCatalogKey = Constants.DefaultKeys.Warehouse.DefaultWarehouseCatalogKey; // this would have to be done through the back office as it uses an internal service var us = MerchelloContext.Current.Services.StoreSettingService.GetCountryByCode("US"); var usCountry = new ShipCountry(defaultCatalogKey, us); ((ServiceContext)MerchelloContext.Current.Services).ShipCountryService.Save(usCountry); // we can use this later. var rateTableProvider = (FixedRateShippingGatewayProvider)MerchelloContext.Current.Gateways.Shipping.GetProviderByKey(key); // again usually done in the back office if (!rateTableProvider.ShipMethods.Any()) { // creates the rate table for ship rate quotes var gwShipmeMethod = (FixedRateShippingGatewayMethod)rateTableProvider.CreateShipMethod(FixedRateShippingGatewayMethod.QuoteType.VaryByWeight, usCountry, "Ground (Vary by Weight)"); gwShipmeMethod.RateTable.AddRow(0, 10, 5); gwShipmeMethod.RateTable.AddRow(10, 15, 10); // total weight should be 10M so we should hit this tier gwShipmeMethod.RateTable.AddRow(15, 25, 25); gwShipmeMethod.RateTable.AddRow(25, 10000, 100); rateTableProvider.SaveShippingGatewayMethod(gwShipmeMethod); } // Get the persisted customer const string loginName = "rusty"; var customerService = MerchelloContext.Current.Services.CustomerService; var customer = customerService.GetByLoginName(loginName) ?? customerService.CreateCustomerWithKey(loginName, "Rusty", "Swayne", "*****@*****.**"); // I'll use this for billing and shipping var billingAddress = new Address() { Name = "Mindfly Web Design Studio", Address1 = "114 W. Magnolia St. Suite 300", Locality = "Bellingham", Region = "WA", PostalCode = "98225", CountryCode = "US" }; // Most of the time this information is brought in from the IProductVariant - but the idea is you can // describe things on the fly var extendedData = new ExtendedDataCollection(); // this is used to determine where a shipment originates extendedData.SetValue(Constants.ExtendedDataKeys.WarehouseCatalogKey, defaultCatalogKey.ToString()); // items set to shippable extendedData.SetValue(Constants.ExtendedDataKeys.TrackInventory, "false"); extendedData.SetValue(Constants.ExtendedDataKeys.Shippable, "true"); extendedData.SetValue(Constants.ExtendedDataKeys.Weight, "1.25"); extendedData.SetValue(Constants.ExtendedDataKeys.CurrencyCode, "USD"); var item = new InvoiceLineItem(LineItemType.Product, "My product", "mySku", 2, 10M, extendedData); var invoiceService = MerchelloContext.Current.Services.InvoiceService; var invoice = invoiceService.CreateInvoice(Constants.DefaultKeys.InvoiceStatus.Unpaid); // I'd say we need to add a parameter to the service so we don't have to do this // http://issues.merchello.com/youtrack/issue/M-434 ((Invoice)invoice).CustomerKey = customer.Key; // The version key is useful in some cases to invalidate shipping quotes or taxation calculations invoice.VersionKey = Guid.NewGuid(); invoice.Items.Add(item); // at this point the invoice is not saved and we don't have an invoice number // however, we may want to quote shipping so we need a shipment // Shipment Statuses are new in 1.5.0 var warehouse = MerchelloContext.Current.Services.WarehouseService.GetDefaultWarehouse(); var shipmentStatus = MerchelloContext.Current.Services.ShipmentService.GetShipmentStatusByKey( Constants.DefaultKeys.ShipmentStatus.Quoted); // since we know all the items in the invoice will be shipped we don't need to filter var shipment = new Shipment(shipmentStatus, warehouse.AsAddress(), billingAddress, invoice.Items); // since we already know the shipping provider we want from above we can do var quotes = rateTableProvider.QuoteShippingGatewayMethodsForShipment(shipment); // if we wanted Merchello to get quotes from all shipping providers we'd do the following // var quotes = shipment.ShipmentRateQuotes(); if (quotes.Any()) { // this check makes certain a quote was returned. For example if the collection of items was outside the allowable // weight range, the provider would not return a quote. // Add the first quote to the invoice. invoice.Items.Add(quotes.FirstOrDefault().AsLineItemOf<InvoiceLineItem>()); } // you do need to update the total ... this is usually done in the InvoiceBuilder in // instantiated by a SalesPreparation sub class var charges = invoice.Items.Where(x => x.LineItemType != LineItemType.Discount).Sum(x => x.TotalPrice); var discounts = invoice.Items.Where(x => x.LineItemType == LineItemType.Discount).Sum(x => x.TotalPrice); // total the invoice decimal converted; invoice.Total = decimal.TryParse((charges - discounts).ToString(CultureInfo.InvariantCulture), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture.NumberFormat, out converted) ? converted : 0; // Now we save the invoice since we have to have a real record of something to collect a payment against // This also generates the invoice number invoiceService.Save(invoice); Console.WriteLine(invoice.InvoiceNumber); // cash payment method var cashProvider = MerchelloContext.Current.Gateways.Payment.GetProviderByKey(Constants.ProviderKeys.Payment.CashPaymentProviderKey); if (cashProvider != null) { var cash = cashProvider.PaymentMethods.FirstOrDefault(); // default install has a single payment method "Cash" // I usually Authorize a cash payment if taken online since we don't really see the money. Capture is used // when the money comes in. In your inquiry, it looks like you are assuming the money is in hand at the // time of the purchase, so we'll use AuthorizeCapture straight away. var attempt = invoice.AuthorizeCapturePayment(cash.Key); if (! attempt.Payment.Success) { // handle the error } // otherwise you'll notice var approved = attempt.ApproveOrderCreation; // equals true // the order will be automatically created by the event handler in Merchello.Core.Gateways.GatewayEvents // however in this test I don't have the event wired up so I have to do it manuall if (approved) { var order = invoice.PrepareOrder(); MerchelloContext.Current.Services.OrderService.Save(order); var items = order.Items; } } // Cash provider is not active }
public void Can_Map_An_Invoice_With_A_Custom_LineItemType_To_InvoiceDisplay() { //// Arrange var invoice = MockInvoiceDataMaker.GetMockInvoiceForTaxation(); Assert.NotNull(invoice, "Invoice is null"); var extendedData = new ExtendedDataCollection(); extendedData.SetValue(Constants.ExtendedDataKeys.Taxable, false.ToString()); var typeField = EnumTypeFieldConverter.LineItemType.Custom("CcFee"); //// Act var ccFee = new InvoiceLineItem( typeField.TypeKey, "CC Fee", "ccfee", 1, 1.0m, extendedData); invoice.Items.Add(ccFee); var display = invoice.ToInvoiceDisplay(); //// Assert Assert.NotNull(display); Assert.IsFalse(display.Items.Any(x => x.LineItemTypeField == null), "One or more of the LineItemTypeFields where null"); }
public InvoiceLineItem BuildEntity(InvoiceItemDto dto) { var lineItem = new InvoiceLineItem(dto.LineItemTfKey, dto.Name, dto.Sku, dto.Quantity, dto.Price, string.IsNullOrEmpty(dto.ExtendedData) ? new ExtendedDataCollection() : new ExtendedDataCollection(dto.ExtendedData)) { Key = dto.Key, ContainerKey = dto.ContainerKey, Exported = dto.Exported, UpdateDate = dto.UpdateDate, CreateDate = dto.CreateDate }; lineItem.ResetDirtyProperties(); return lineItem; }
private void MakeInvoice() { var origin = new Address() { Organization = "Mindfly Web Design Studios", Address1 = "114 W. Magnolia St. Suite 300", Locality = "Bellingham", Region = "WA", PostalCode = "98225", CountryCode = "US", Email = "*****@*****.**", Phone = "555-555-5555" }; //var billToShipTo = new Address() // { // Name = "The President of the United States", // Address1 = "1600 Pennsylvania Ave NW", // Locality = "Washington", // Region = "DC", // PostalCode = "20500", // CountryCode = "US", // }; var billToShipTo = new Address() { Name = "Old Office", Address1 = "211 W Holly St H22", Locality = "Bellingham", Region = "WA", PostalCode = "98225", CountryCode = "US", }; var invoiceService = new InvoiceService(); Invoice = invoiceService.CreateInvoice(Core.Constants.DefaultKeys.InvoiceStatus.Unpaid); Invoice.SetBillingAddress(billToShipTo); Invoice.Total = 120M; var extendedData = new ExtendedDataCollection(); // this is typically added automatically in the checkout workflow extendedData.SetValue(Core.Constants.ExtendedDataKeys.CurrencyCode, "USD"); extendedData.SetValue(Core.Constants.ExtendedDataKeys.Taxable, true.ToString()); // make up some line items var l1 = new InvoiceLineItem(LineItemType.Product, "Item 1", "I1", 10, 1, extendedData); var l2 = new InvoiceLineItem(LineItemType.Product, "Item 2", "I2", 2, 40, extendedData); Invoice.Items.Add(l1); Invoice.Items.Add(l2); var shipment = new ShipmentMock(origin, billToShipTo, Invoice.Items); var shipmethod = new ShipMethodMock(); var quote = new ShipmentRateQuote(shipment, shipmethod) { Rate = 16.22M }; Invoice.Items.Add(quote.AsLineItemOf<InvoiceLineItem>()); }
public void TestCaseNumber_6_Section_B_A_And_B() { //Arrange const string cardType = "MasterCard"; const string card = "5454545454545454"; const string cardCode = ""; const string postalCode = "L6L2X9"; const int amount = 41; // Setup extended data for invoice var extendedData = new ExtendedDataCollection(); // this is typically added automatically in the checkout workflow extendedData.SetValue(Core.Constants.ExtendedDataKeys.CurrencyCode, "USD"); _invoice.BillToPostalCode = postalCode; // Set the total value for the invoice. _invoice.Total = amount; // make up some line items for the invoice var l1 = new InvoiceLineItem(LineItemType.Product, "Item 1", "I1", 1, amount, extendedData); _invoice.Items.Add(l1); var creditCardMethod = Provider.GetPaymentGatewayMethodByPaymentCode("CreditCard"); Assert.NotNull(creditCardMethod); var ccEntry = TestHelper.GetCreditCardFormData(cardType, card, cardCode); // Act var result = _payment.AuthorizeCapturePayment(_invoice, amount, ccEntry.AsProcessorArgumentCollection()); var result2 = _payment.VoidPayment(_invoice, result.Payment.Result, ccEntry.AsProcessorArgumentCollection()); // Assert Assert.IsTrue(result.Payment.Success); Assert.IsTrue(result.ApproveOrderCreation); Assert.AreEqual("0", result2.Payment.Result.ExtendedData.GetValue(Constants.ExtendedDataKeys.VoidProcStatus)); // Log Results for certification TestHelper.LogInformation("Test 6A Section B", result); TestHelper.LogInformation("Test 6B Section B", result2); }
public void TestCaseNumber_3_Section_B() { //Arrange const string cardType = "VISA"; const string card = "4788250000028291"; const string cardCode = ""; const string postalCode = "11111"; const decimal amount = 38.01M; // Setup extended data for invoice var extendedData = new ExtendedDataCollection(); // this is typically added automatically in the checkout workflow extendedData.SetValue(Core.Constants.ExtendedDataKeys.CurrencyCode, "USD"); _invoice.BillToPostalCode = postalCode; // Set the total value for the invoice. _invoice.Total = amount; // make up some line items for the invoice var l1 = new InvoiceLineItem(LineItemType.Product, "Item 1", "I1", 1, amount, extendedData); _invoice.Items.Add(l1); var creditCardMethod = Provider.GetPaymentGatewayMethodByPaymentCode("CreditCard"); Assert.NotNull(creditCardMethod); var ccEntry = TestHelper.GetCreditCardFormData(cardType, card, cardCode); // Act var result = _payment.AuthorizeCapturePayment(_invoice, amount, ccEntry.AsProcessorArgumentCollection()); // Assert Assert.IsFalse(result.Payment.Success); Assert.IsFalse(result.ApproveOrderCreation); // Log Results for certification TestHelper.LogInformation("Test 3 Section B", result); }
public void TestCaseNumber_24_Section_A_A_And_B() { //Arrange const string cardType = "VISA"; const string card = "4055011111111111"; const string cardCode = "333"; const string postalCode = "22222"; const int amount = 90; const int taxAmount = 10; // Setup extended data for invoice var extendedData = new ExtendedDataCollection(); // this is typically added automatically in the checkout workflow extendedData.SetValue(Core.Constants.ExtendedDataKeys.CurrencyCode, "USD"); _invoice.BillToPostalCode = postalCode; // Set the total value for the invoice. _invoice.Total = amount + taxAmount; _invoice.PoNumber = "PW0001"; // make up some line items for the invoice var l1 = new InvoiceLineItem(LineItemType.Product, "Item 1", "I1", 1, amount - taxAmount, extendedData); var l2 = new InvoiceLineItem(LineItemType.Tax, "Item 2", "I2", 1, taxAmount, extendedData); _invoice.Items.Add(l1); _invoice.Items.Add(l2); var creditCardMethod = Provider.GetPaymentGatewayMethodByPaymentCode("CreditCard"); Assert.NotNull(creditCardMethod); var ccEntry = TestHelper.GetCreditCardFormData(cardType, card, cardCode); // Act var result = _payment.AuthorizePayment(_invoice, ccEntry.AsProcessorArgumentCollection()); var result2 = _payment.CapturePayment(_invoice, result.Payment.Result, amount, ccEntry.AsProcessorArgumentCollection()); // Assert Assert.IsTrue(result.Payment.Success); Assert.IsTrue(result.ApproveOrderCreation); Assert.IsTrue(result2.Payment.Success); Assert.IsTrue(result2.ApproveOrderCreation); // Log Results for certification TestHelper.LogInformation("Test 24A Section A", result); TestHelper.LogInformation("Test 24B Section A", result2); }
public void TestCaseNumber_3_Section_C_MasterCard_AuthCapture() { //Arrange const string cardType = "MasterCard"; const string card = "5454545454545454"; const string cardCode = "333"; const string postalCode = "44444"; const int amount = 41; const string aav = "Asju1ljfl86bAAAAAACm9zU6aqY"; const string eci = "5"; // Setup extended data for invoice var extendedData = new ExtendedDataCollection(); // this is typically added automatically in the checkout workflow extendedData.SetValue(Core.Constants.ExtendedDataKeys.CurrencyCode, "USD"); _invoice.BillToPostalCode = postalCode; // Set the total value for the invoice. _invoice.Total = amount; // make up some line items for the invoice var l1 = new InvoiceLineItem(LineItemType.Product, "Item 1", "I1", 1, amount, extendedData); _invoice.Items.Add(l1); var creditCardMethod = Provider.GetPaymentGatewayMethodByPaymentCode("CreditCard"); Assert.NotNull(creditCardMethod); var ccEntry = TestHelper.GetCreditCardFormData(cardType, card, cardCode); ccEntry.AuthenticationVerification = aav; ccEntry.AuthenticationVerificationEci = eci; // Act var result = _payment.AuthorizeCapturePayment(_invoice, amount, ccEntry.AsProcessorArgumentCollection()); // Assert Assert.IsTrue(result.Payment.Success); Assert.IsTrue(result.ApproveOrderCreation); // Log Results for certification TestHelper.LogInformation("Test 3 Section C MasterCard Auth Capture", result); }
public void TestCaseNumber_5_Section_C_Visa_AuthCapture() { //Arrange const string cardType = "Visa"; const string card = "4788250000028291"; const string cardCode = "111"; const string postalCode = "55555"; const int amount = 1055; const string cavv = "CAAQCZkRERI0VniQEhERAAAAAAA="; //const string cavv = "BwABA4kRERI0VniQEhERAAAAAAA="; const string eci = "6"; // Setup extended data for invoice var extendedData = new ExtendedDataCollection(); // this is typically added automatically in the checkout workflow extendedData.SetValue(Core.Constants.ExtendedDataKeys.CurrencyCode, "USD"); _invoice.BillToPostalCode = postalCode; // Set the total value for the invoice. _invoice.Total = amount; // make up some line items for the invoice var l1 = new InvoiceLineItem(LineItemType.Product, "Item 1", "I1", 1, amount, extendedData); _invoice.Items.Add(l1); var creditCardMethod = Provider.GetPaymentGatewayMethodByPaymentCode("CreditCard"); Assert.NotNull(creditCardMethod); var ccEntry = TestHelper.GetCreditCardFormData(cardType, card, cardCode); ccEntry.AuthenticationVerification = cavv; ccEntry.AuthenticationVerificationEci = eci; // Act var result = _payment.AuthorizeCapturePayment(_invoice, amount, ccEntry.AsProcessorArgumentCollection()); // Assert Assert.IsTrue(result.Payment.Success); Assert.IsTrue(result.ApproveOrderCreation); // Log Results for certification TestHelper.LogInformation("Test 5 Section C Visa Auth Capture", result); }