// This method sets the shipping fee based on the amount given through the extension page public override int CalculateShippingCharge2(string orderID, string shipmentID, out double shippingCharge, out string isoCurrencyCode) { // Set the shipping charge to the value that was given on the extension page shippingCharge = double.Parse(Storefront.GetValue(FieldType.ModuleField, "shipping_charge", UniqueName)); isoCurrencyCode = "USD"; // Send the new data back to the storefront for the shipping charge return(eSuccess); }
public override int CouldCollect(string orderID) { string sxiname = Storefront.GetValue("OrderProperty", "SxiModuleForCollection", orderID); if (sxiname == this.UniqueName) { return(eSuccess); } return(eFailure); }
public override int CouldCollect(string orderID) { // Asks the module whether it could collect on the order. // This controls enabling of the Collect Payment button in the Orders and Order Details pages on the Administrator site. string sxiname = Storefront.GetValue("OrderProperty", "SxiModuleForCollection", orderID); if (sxiname == this.UniqueName) { return(eSuccess); } return(eFailure); }
public void AddLinkButtonTwo(ControlCollection cc, string storefrontUrl) { // Add code to page for the next navbar piece Page page = (Page)HttpContext.Current.Handler; string format = "<td class='navBarSeparator'></td><td class='navBarCell'><div class='navBarButton' style='float: left;'><div class='navBarButton-t'><div class='navBarButton-b'><div class='navBarButton-l'><div class='navBarButton-r'><div class='navBarButton-tl'><div class='navBarButton-tr'><div class='navBarButton-bl'><div class='navBarButton-br'><div class='navBarButton-inner'><a class='navBarButton' target='_blank' href='{0}'>{1}</a></div></div></div></div></div></div></div></div></div></div></td>"; if (page.Request.Url.ToString().IndexOf("previesreport.aspx") != -1) { format = format.Replace("navBarButton", "navBarButtonSelected"); } // Add the name for our navbar piece the user specified string text = string.Format(format, storefrontUrl, StorefrontAPI.Storefront.GetValue("ModuleField", _SA_LINK_NAME_TWO, _UNIQUE_NAME)); // Get user specfied link for link two button string linkTwoUrl = Storefront.GetValue("ModuleField", _SA_LINK_TWO_URL, _UNIQUE_NAME); // This variable holds the link two url the user provided from the extension setup page // Log that the text has been set and what it is /* * LMTF.LogMessagesToFile(storeFrontName, LOG_FILENAME1, LOG_FILENAME2, $"|----------------------------------------------------------|"); * LMTF.LogMessagesToFile(storeFrontName, LOG_FILENAME1, LOG_FILENAME2, "AddLinkButton called text: " + text); * if ((string)ModuleData[_SA_DEBUGGING_MODE] == "true") * { * LogMessage($"|----------------------------------------------------------|"); * LogMessage("AddLinkButton called text: " + text); * } */ // Add navbar to correct place in list foreach (Control startingControl in cc) { if (startingControl.ToString().IndexOf("pageheader_ascx") != -1) { Control childControl = ControlFinder.FindChildControl(startingControl, "phLeftSide"); try { childControl.Controls.AddAt(childControl.Controls.Count - 2, new LiteralControl(text)); } catch (Exception ex) { string message = ex.Message; } } if (startingControl.HasControls()) { AddLinkButtonTwo(startingControl.Controls, linkTwoUrl); } } }
public override int UserLogon_Before(string uid) { string name; name = Storefront.GetValue("UserProperty", "LogonName", uid); if (name == "webster") { return(eShouldAbort); } else { return(eSuccess); } }
// Pass the module data we collected into a list public override int GetConfigurationStatus() { // Retrieve storefrontname to use with logging string storeFrontName = SF.GetValue(FieldType.SystemProperty, SystemProperty.STOREFRONT_NAME, null); // Create the list to hold our configuration values from the storefront var configValues = new List <string>(4); string storefrontName = Storefront.GetValue("ModuleField", _SA_STOREFRONT_NAME, _UNIQUE_NAME); // This variable holds the store front name the user provided from the extension setup page string domain = Storefront.GetValue("ModuleField", _SA_DOMAIN, _UNIQUE_NAME); // This variable holds the domain the user provided from the extension setup page string linkName = Storefront.GetValue("ModuleField", _SA_LINK_NAME, _UNIQUE_NAME); // This variable holds the link name the user provided from the extension setup page string linkNameTwo = Storefront.GetValue("ModuleField", _SA_LINK_NAME_TWO, _UNIQUE_NAME); // This variable holds the link name two the user provided from the extension setup page string linkTwoUrl = Storefront.GetValue("ModuleField", _SA_LINK_TWO_URL, _UNIQUE_NAME); // This variable holds the link two url the user provided from the extension setup page configValues.Add(storefrontName); configValues.Add(domain); configValues.Add(linkName); configValues.Add(linkNameTwo); configValues.Add(linkTwoUrl); // Inform that we have called the on pageload event LMTF.LogMessagesToFile(storeFrontName, LOG_FILENAME1, LOG_FILENAME2, $"|----------------------------------------------------------|"); LMTF.LogMessagesToFile(storeFrontName, LOG_FILENAME1, LOG_FILENAME2, $"GetConfigurationStatus Method: Storefront Name: {storefrontName}"); // Logs the storefront name LMTF.LogMessagesToFile(storeFrontName, LOG_FILENAME1, LOG_FILENAME2, $"GetConfigurationStatus Method: Domain: {domain}"); // Logs the domain LMTF.LogMessagesToFile(storeFrontName, LOG_FILENAME1, LOG_FILENAME2, $"GetConfigurationStatus Method: Link Name: {linkName}"); // Logs the link name LMTF.LogMessagesToFile(storeFrontName, LOG_FILENAME1, LOG_FILENAME2, $"GetConfigurationStatus Method: Link Name Two: {linkNameTwo}"); // Logs the link name two LMTF.LogMessagesToFile(storeFrontName, LOG_FILENAME1, LOG_FILENAME2, $"GetConfigurationStatus Method: Link Name Two: {linkTwoUrl}"); // Logs the link two url // Log the values we have currently to the storefront logs if ((string)ModuleData[_SA_DEBUGGING_MODE] == "true") { LogMessage($"|----------------------------------------------------------|"); LogMessage($"GetConfigurationStatus Method: Storefront Name: {storefrontName}"); // Logs the storefront name LogMessage($"GetConfigurationStatus Method: Domain: {domain}"); // Logs the domain LogMessage($"GetConfigurationStatus Method: Link Name: {linkName}"); // Logs the link name LogMessage($"GetConfigurationStatus Method: Link Name Two: {linkNameTwo}"); // Logs the link name two LogMessage($"GetConfigurationStatus Method: Link Two URL: {linkTwoUrl}"); // Logs the link two url } // Check to ensure we actually have values before returning them return(configValues.Any(v => string.IsNullOrEmpty(v)) ? eDoNotCall : eSuccess); }
protected void ComputeDocumentPrices(string[] docids, double[] prices) { try { for (int i = 0; i < docids.Length; i++) { string id = (string)docids[i]; string n = ""; string q = Storefront.GetValue("PrintingField", "PrintingQuantity", id); if (q == null || q == "") { q = "1"; } string db = Storefront.GetValue("DocumentProperty", "DatabaseToMerge_AssetID", id); if (db != null && db != "") { n = Storefront.GetValue("AssetProperty", "NumberOfRows", db); } if (n == null || n == "") { n = "1"; } int ncopies = int.Parse(q) * int.Parse(n); prices[i] = ncopies * 9.00; // $9.00 each } } catch (Exception ex) { string s = ex.Message; } }
// This method is used to get adjust the tax rate for the user's order public override int CalculateTax2(string OrderID, double taxableAmount, string currencyCode, string[] priceCategories, string[] priceTaxLocales, double[] priceAmount, string[] taxLocaleId, ref double[] taxAmount) { #region |--This section of code shows what we have been passed if debug mode is "on"--| // Check if debug mode is turned on; If it is then we log these messages if ((string)ModuleData[_AT_DEBUGGING_MODE] == "true") { // Used to help to see where these mesages are in the Storefront logs page LogMessage($"* *"); // Adds a space for easier viewing LogMessage($"* START *"); // Show when we start this process LogMessage($"* *"); // Shows what values are passed at beginning LogMessage($"OrderID is: {OrderID}"); // Tells the id for the order being calculated LogMessage($"TaxableAmount is: {taxableAmount.ToString()}"); // Tells the amount to be taxed (currently set to 0) LogMessage($"CurrencyCode is: {currencyCode}"); // Tells the type of currency used LogMessage($"PriceCategories is: {priceCategories.Length.ToString()}"); // Not Null, but empty LogMessage($"PriceTaxLocales is: {priceTaxLocales.Length.ToString()}"); // Not Null, but empty LogMessage($"PriceAmount is: {priceAmount.Length.ToString()}"); // Not Null, but empty LogMessage($"TaxLocaleId is: {taxLocaleId.Length.ToString()}"); // Shows the number of tax locales found for this order LogMessage($"TaxLocaleId[0] is: {taxLocaleId[0].ToString()}"); // Sends a number value which corresponds to the tax rate row in the tax rates table excel file // These Log the messages to a log .txt file // The logs an be found in the Logs folder in the storefront's deployment LogMessageToFile($"* *"); // Adds a space for easier viewing LogMessageToFile($"* START *"); // Show when we start this process LogMessageToFile($"* *"); // Shows what values are passed at beginning in .txt file LogMessageToFile($"OrderID is: {OrderID}"); // Tells the id for the order being calculated LogMessageToFile($"TaxableAmount is: {taxableAmount.ToString()}"); // Tells the amount to be taxed (currently set to 0) LogMessageToFile($"CurrencyCode is: {currencyCode}"); // Tells the type of currency used LogMessageToFile($"PriceCategories is: {priceCategories.Length.ToString()}"); // Not Null, but empty LogMessageToFile($"PriceTaxLocales is: {priceTaxLocales.Length.ToString()}"); // Not Null, but empty LogMessageToFile($"PriceAmount is: {priceAmount.Length.ToString()}"); // Not Null, but empty LogMessageToFile($"TaxLocaleId is: {taxLocaleId.Length.ToString()}"); // Shows the number of tax locales found for this order LogMessageToFile($"TaxLocaleId[0] is: {taxLocaleId[0].ToString()}"); // Sends a number value which corresponds to the tax rate row in the tax rates table excel file } #endregion #region |--This section is where we get and set the values from the shipping page where the user has entered their address info--| // Check if debug mode is turned on; If it is then we log these messages if ((string)ModuleData[_AT_DEBUGGING_MODE] == "true") { // Shows the section where we get and display what has been added to the shipping page fields LogMessage($"* *"); // Adds a space for easier viewing LogMessage($"*Shipping Fields Section *"); // Show when we reach the shipping fields section LogMessage($"* *"); // Shows the section where we get and display what has been added to the shipping page fields in the .txt file LogMessageToFile($"* *"); // Adds a space for easier viewing LogMessageToFile($"*Shipping Fields Section *"); // Show when we reach the shipping fields section LogMessageToFile($"* *"); } // This section saves the user's shipping info to variables to use with calculating the tax rate to return // Listed in the same order as in the address book on the site var SFirstName = Storefront.GetValue("OrderField", "ShippingFirstName", OrderID); // This gets the first name that the user has on the shipping page var SLastName = Storefront.GetValue("OrderField", "ShippingLastName", OrderID); // This gets the last name that the user has on the shipping page var SAddress1 = Storefront.GetValue("OrderField", "ShippingAddress1", OrderID); // This gets the address field 1 that the user has on the shipping page var SAddress2 = Storefront.GetValue("OrderField", "ShippingAddress2", OrderID); // This gets the address field 2 that the user has on the shipping page var SCity = Storefront.GetValue("OrderField", "ShippingCity", OrderID); // This gets the city that the user has on the shipping page var SState = Storefront.GetValue("OrderField", "ShippingState", OrderID); // This gets the state that the user has on the shipping page var SPostalCode = Storefront.GetValue("OrderField", "ShippingPostalCode", OrderID); // This gets the zip code that the user has on the shipping page var SCountry = Storefront.GetValue("OrderField", "ShippingCountry", OrderID); // This gets the country that the user has on the shipping page // Get the handling charge to use with taxes var hCharge = Storefront.GetValue("OrderField", "HandlingCharge", OrderID); // This gets the handling charge for the order var sCharge = Storefront.GetValue("OrderField", "ShippingCharge", OrderID); // This gets the shipping charge for the order // Check if debug mode is turned on; If it is then we log these messages if ((string)ModuleData[_AT_DEBUGGING_MODE] == "true") { // Log to show that we have retrieved the zipcode form the shipping page LogMessage($"Shipping FirstName: {SFirstName}"); // This logs the first name that the user has on the shipping page LogMessage($"Shipping LastName: {SLastName}"); // This logs the last name that the user has on the shipping page LogMessage($"Shipping Address1: {SAddress1}"); // This logs the address field 1 that the user has on the shipping page LogMessage($"Shipping Address2: {SAddress2}"); // This logs the address field 2 that the user has on the shipping page LogMessage($"Shipping City: {SCity}"); // This logs the city that the user has on the shipping page LogMessage($"Shipping State: {SState}"); // This logs the state that the user has on the shipping page LogMessage($"Shipping PostalCode: {SPostalCode}"); // This logs the zip code that the user has on the shipping page LogMessage($"Shipping Country: {SCountry}"); // This logs the country that the user has on the shipping page LogMessage($"Handling Charge: {hCharge}"); // This logs the zip code that the user has on the shipping page LogMessage($"Shipping Charge: {sCharge}"); // This logs the country that the user has on the shipping page // Log to show that we have retrieved the zipcode form the shipping page in the .txt file LogMessageToFile($"Shipping FirstName: {SFirstName}"); // This logs the first name that the user has on the shipping page LogMessageToFile($"Shipping LastName: {SLastName}"); // This logs the last name that the user has on the shipping page LogMessageToFile($"Shipping Address1: {SAddress1}"); // This logs the address field 1 that the user has on the shipping page LogMessageToFile($"Shipping Address2: {SAddress2}"); // This logs the address field 2 that the user has on the shipping page LogMessageToFile($"Shipping City: {SCity}"); // This logs the city that the user has on the shipping page LogMessageToFile($"Shipping State: {SState}"); // This logs the state that the user has on the shipping page LogMessageToFile($"Shipping PostalCode: {SPostalCode}"); // This logs the zip code that the user has on the shipping page LogMessageToFile($"Shipping Country: {SCountry}"); // This logs the country that the user has on the shipping page LogMessageToFile($"Handling Charge: {hCharge}"); // This logs the zip code that the user has on the shipping page LogMessageToFile($"Shipping Charge: {sCharge}"); // This logs the country that the user has on the shipping page } #endregion #region |--Database call to retrieve the subtotal--| // Check if debug mode is turned on; If it is then we log these messages if ((string)ModuleData[_AT_DEBUGGING_MODE] == "true") { // Shows the section where we change the tax rate LogMessage($"* *"); // Adds a space for easier viewing LogMessage($"*Tax Rates Section Part 1*"); // Show when we reach the tax rates section LogMessage($"* *"); // Set the tax amount based on a few zipcodes and send it back to pageflex LogMessage($"Tax amount is: " + taxAmount[0].ToString() + " before we make our DB or Avalara calls"); // Shows the current tax amount (currently set to 0) // Shows the section where we change the tax rate in the .txt file LogMessageToFile($"* *"); // Adds a space for easier viewing LogMessageToFile($"*Tax Rates Section Part 1*"); // Show when we reach the tax rates section LogMessageToFile($"* *"); // Set the tax amount based on a few zipcodes and send it back to pageflex in the .txt file LogMessageToFile($"Tax amount is: " + taxAmount[0].ToString() + " before we make our DB or Avalara calls"); // Shows the current tax amount (currently set to 0) } // Get our DB logon info from the storefront string dataSource = Storefront.GetValue("ModuleField", _DATA_SOURCE, _UNIQUE_NAME); // This variable holds the datasource the user provided from the extension setup page string initialCatalog = Storefront.GetValue("ModuleField", _INITIAL_CATALOG, _UNIQUE_NAME); // This variable holds the datasource the user provided from the extension setup page string userID = Storefront.GetValue("ModuleField", _USER_ID, _UNIQUE_NAME); // This variable holds the datasource the user provided from the extension setup page string userPassword = Storefront.GetValue("ModuleField", _USER_PASSWORD, _UNIQUE_NAME); // This variable holds the datasource the user provided from the extension setup page // Check if debug mode is turned on; If it is then we log these messages if ((string)ModuleData[_AT_DEBUGGING_MODE] == "true") { // Log messages to show what was retrieved from the storefront LogMessage($"DB logon information:"); // This logs that we are logging the DB Logon information LogMessage($"Data Source is: {dataSource}"); // This logs the data source that the user has on the extension configuration page LogMessage($"Initial Catalog is: {initialCatalog}"); // This logs the initial catalog that the user has on the extension configuration page LogMessage($"User ID is: {userID}"); // This logs the user id that the user has on the extension configuration page LogMessage($"User Password is: {userPassword}"); // This logs the user password that the user has on the extension configuration page LogMessageToFile($"DB logon information:"); // This logs that we are logging the DB Logon information LogMessageToFile($"Data Source is: {dataSource}"); // This logs the data source that the user has on the extension configuration page LogMessageToFile($"Initial Catalog is: {initialCatalog}"); // This logs the initial catalog that the user has on the extension configuration page LogMessageToFile($"User ID is: {userID}"); // This logs the user id that the user has on the extension configuration page LogMessageToFile($"User Password is: {userPassword}"); // This logs the user password that the user has on the extension configuration page } // Our credentials to connect to the DB string connectionString = $"Data Source={dataSource};" + $"Initial Catalog={initialCatalog};" + $"User ID={userID};" + $"Password={userPassword};" + "Persist Security Info=True;" + "Connection Timeout=15"; // Check if debug mode is turned on; If it is then we log these messages if ((string)ModuleData[_AT_DEBUGGING_MODE] == "true") { LogMessage($"Full Connection String: {connectionString}"); // This logs the full connection string to see it is all together properly LogMessageToFile($"Full Connection String: {connectionString}"); // This logs the full connection string to see it is all together properly } // The query to be ran on the DB /* * Query: SELECTS the "Order Group ID", the "Price"(Cast as money) , the "Shipping Charge"(Cast as money) , and the "Handling Charge"(Cast as money) * FROM three tables: "OrderedDocuments", "OrderGroups", and "Shipments" that have been INNER JOINED together based on the "OrderGroupID" * WHERE the "OrderGroupID" equals the orderID of our current order on the storefront */ string queryString = "SELECT OrderedDocuments.OrderGroupID," + "CAST(OrderedDocuments.Price / 100.00 as money) as Price," + "CAST(Shipments.ShippingAmount / 100.00 as money) as Shipping," + "CAST(OrderGroups.HandlingCharge / 100.00 as money) as Handling " + "FROM OrderedDocuments " + "INNER JOIN OrderGroups ON OrderGroups.OrderGroupID = OrderedDocuments.OrderGroupID " + "INNER JOIN Shipments ON Shipments.OrderGroupID = OrderedDocuments.OrderGroupID " + "WHERE OrderedDocuments.OrderGroupID = @orderID"; // This is how to call it using a stored procedure I currently have setup on "Interface DB" //string queryString = "USE [Interface] " + "DECLARE @return_value Int EXEC @return_value = [dbo].[GetRates] @OrderID = 1787 SELECT @return_value as 'Return Value'"; if ((string)ModuleData[_AT_DEBUGGING_MODE] == "true") { // Log to let the developer know we are trying to connect to DB using connection string LogMessage("starting DB connection"); // This logs that we are starting the DB connection process LogMessageToFile("starting DB connection"); // This logs that we are starting the DB connection process } try { // Setup the connection to the db using our credentials using (SqlConnection connection = new SqlConnection(connectionString)) { // Open the connection using what we have setup connection.Open(); if ((string)ModuleData[_AT_DEBUGGING_MODE] == "true") { // Log to let the developer know connection to DB was successful LogMessage("DB connection successful"); // This logs that the DB connection process was a success LogMessageToFile("DB connection successful"); // This logs that the DB connection process was a success } // Setup our query to call SqlCommand commandGetRates = new SqlCommand(queryString, connection); commandGetRates.Parameters.AddWithValue("@orderID", OrderID); if ((string)ModuleData[_AT_DEBUGGING_MODE] == "true") { // Log to let the developer know we finished running our query LogMessage("Query finished running"); // This logs that the query run has finished LogMessageToFile("Query finished running"); // This logs that the query run has finished } // Setup a reader to handle what our query returns using (SqlDataReader reader = commandGetRates.ExecuteReader()) { // Read back what our query retrieves while (reader.Read()) { if ((string)ModuleData[_AT_DEBUGGING_MODE] == "true") { // Log and show the results we retrieved from the DB LogMessage(string.Format("From DB Reader: OrderID: {0}, Price: {1}, Shipping: {2}, Handling: {3}", reader["OrderGroupID"], reader["Price"], reader["Shipping"], reader["Handling"])); LogMessageToFile(string.Format("From DB Reader: OrderID: {0}, Price: {1}, Shipping: {2}, Handling: {3}", reader["OrderGroupID"], reader["Price"], reader["Shipping"], reader["Handling"])); } // Filling the variables to hold our totals from the DB retrieval step subTotal = Convert.ToDecimal(reader["Price"]); // This gets the subtotal that the user has on the extension configuration page shippingCharge = Convert.ToDecimal(reader["Shipping"]); // This gets the shipping charge that the user has on the extension configuration page handlingCharge = Convert.ToDecimal(reader["Handling"]); // This gets the handling charge that the user has on the extension configuration page } // Calculate the total amount to be taxed by Avalara totalTaxableAmount = subTotal + shippingCharge + handlingCharge; if ((string)ModuleData[_AT_DEBUGGING_MODE] == "true") { // Log messages to show what we retrieved from DB and have stored into variables LogMessage($"Totals read from the DB and stored in variables"); // This logs that the DB read has finished and we are showing what is in the variables saved LogMessage($"subTotal: {subTotal}"); // This logs the subtotal variable LogMessage($"shippingCharge: {shippingCharge}"); // This logs the shipping charge variable LogMessage($"handlingCharge: {handlingCharge}"); // This logs the handling charge variable LogMessageToFile($"Totals read from the DB and stored in variables"); // This logs that the DB read has finished and we are showing what is in the variables saved LogMessageToFile($"subTotal: {subTotal}"); // This logs the subtotal variable LogMessageToFile($"shippingCharge: {shippingCharge}"); // This logs the shipping charge variable LogMessageToFile($"handlingCharge: {handlingCharge}"); // This logs the handling charge variable // Log message to show what the total taxable amount that will be sent to Avalara is LogMessage($"Total Taxable Amount: {totalTaxableAmount}"); // This logs the total taxable amount LogMessageToFile($"Total Taxable Amount: {totalTaxableAmount}"); // This logs the total taxable amount } // Always call Close when done reading. reader.Close(); } // Called by dispose, but good practice to close when done with connection. connection.Close(); } } catch { // Log issue with storefront and to file regardless of whether in debug mode or not LogMessage("Error in DB connection and data retrieval process"); // This logs that there was an error in the DB process LogMessageToFile("Error in DB connection and data retrieval process"); // This logs that there was an error in the DB process } #endregion #region |--This is the section that connects and pulls info from avalara--| // Check if debug mode is turned on; If it is then we log these messages if ((string)ModuleData[_AT_DEBUGGING_MODE] == "true") { // Shows the section where we change the tax rate LogMessage($"* *"); // Adds a space for easier viewing LogMessage($"*Tax Rates Section Part 2*"); // Show when we reach the tax rates 2 section LogMessage($"* *"); // Set the tax amount based on a few zipcodes and send it back to pageflex LogMessage($"Tax amount is: " + taxAmount[0].ToString() + " before we make our Avalara call"); // Shows the current tax amount (currently set to 0) // Shows the section where we change the tax rate in the .txt file LogMessageToFile($"* *"); // Adds a space for easier viewing LogMessageToFile($"*Tax Rates Section Part 2*"); // Show when we reach the tax rates 2 section LogMessageToFile($"* *"); // Set the tax amount based on a few zipcodes and send it back to pageflex in the .txt file LogMessageToFile($"Tax amount is: " + taxAmount[0].ToString() + " before we make our Avalara call"); // Shows the current tax amount (currently set to 0) } // Get our Avalara logon info from the storefront string AVCompanyName = Storefront.GetValue("ModuleField", _AV_COMPANY_NAME, _UNIQUE_NAME); // This gets the company name that the user has on the extension configuration page string AVCompanyCode = Storefront.GetValue("ModuleField", _AV_COMPANY_CODE, _UNIQUE_NAME); // This gets the company code that the user has on the extension configuration page string AVuserID = Storefront.GetValue("ModuleField", _AV_USER_ID, _UNIQUE_NAME); // This gets the user id that the user has on the extension configuration page string AVuserPassword = Storefront.GetValue("ModuleField", _AV_USER_PASSWORD, _UNIQUE_NAME); // This gets the user password that the user has on the extension configuration page // Check if debug mode is turned on; If it is then we log these messages if ((string)ModuleData[_AT_DEBUGGING_MODE] == "true") { // Log messages to show what was retrieved from the storefront LogMessage($"Avalara logon information:"); // This logs that we are displaying the Avalara logon information LogMessage($"Company Name: {AVCompanyName}"); // This logs the company name variable LogMessage($"Company Code: {AVCompanyCode}"); // This logs the company code variable LogMessage($"AValara User ID: {AVuserID}"); // This logs the user id variable LogMessage($"Avalara User Password: {AVuserPassword}"); // This logs the user password variable LogMessageToFile($"Avalara logon information:"); // This logs that we are displaying the Avalara logon information LogMessageToFile($"Company Name: {AVCompanyName}"); // This logs the company name variable LogMessageToFile($"Company Code: {AVCompanyCode}"); // This logs the company code variable LogMessageToFile($"AValara User ID: {AVuserID}"); // This logs the user id variable LogMessageToFile($"Avalara User Password: {AVuserPassword}"); // This logs the user password variable } // Create a client and set up authentication var client = new AvaTaxClient("AvalaraTaxExtension", "1.0", Environment.MachineName, AvaTaxEnvironment.Production) .WithSecurity($"{AVuserID}", $"{AVuserPassword}"); // Check if debug mode is turned on; If it is then we log these messages if ((string)ModuleData[_AT_DEBUGGING_MODE] == "true") { // Show user creation passed LogMessage("Client created"); // This logs that the Avalara client has been created // Show user creation passed in the .txt file LogMessageToFile("Client created"); // This logs that the Avalara client has been created } // This creates the transaction that reaches out to alavara and gets the amount of tax for the user based on info we send // send client we created above in code, the company on alavara I created, type of transaction, and the company code I set up for company var transaction = new TransactionBuilder(client, $"{AVCompanyName}", DocumentType.SalesOrder, $"{AVCompanyCode}") // Pass the variables we pulled from pageflex in the address line .WithAddress(TransactionAddressType.SingleLocation, SAddress1, SAddress2, null, SCity, SState, SPostalCode, SCountry) // Pass the amount of money to calculate tax on (This should be a variable once figure out what it is) .WithLine(totalTaxableAmount) // Run transaction .Create(); // Check if debug mode is turned on; If it is then we log these messages if ((string)ModuleData[_AT_DEBUGGING_MODE] == "true") { // Log that we have created a transaction LogMessage("The transaction has been created"); // This logs that the Avalara transaction has been created // Log that we have created a transaction in the .txt file LogMessageToFile("The transaction has been created"); // This logs that the Avalara transaction has been created } // Retrieves the tax amount from Avalara and sets it to a variable // (It is returned as a decimal? so we havve to convert it to a decimal) // (The ?? 0 sets it to 0 if transaction.totalTax is null) decimal tax2 = transaction.totalTax ?? 0; // Check if debug mode is turned on; If it is then we log these messages if ((string)ModuleData[_AT_DEBUGGING_MODE] == "true") { //Log what is returned LogMessage($"Your calculated tax was: {tax2}"); // This logs that the calculated tax for the order //Log what is returned in the .txt file LogMessageToFile($"Your calculated tax was: {tax2}"); // This logs that the calculated tax for the order } //Set the tax amount on pageflex to the returned value from Avalara taxAmount[0] = decimal.ToDouble(tax2); // Set our new tax rate to a value we choose (for testing) // Check if debug mode is turned on; If it is then we log these messages if ((string)ModuleData[_AT_DEBUGGING_MODE] == "true") { LogMessage($"The zipcode was: " + SPostalCode); // Log message to inform we used this zipcode to get the amount returned LogMessage($"The new TaxAmount is: " + taxAmount[0].ToString()); // Shows the tax amount after we changed it // Send message saying we have completed this process LogMessage($"* *"); // Adds a space for easier viewing LogMessage($"* end *"); // Show when we reach the end of the extension LogMessage($"* *"); // Log for .txt file LogMessageToFile($"The zipcode was: " + SPostalCode); // Log message to inform we used this zipcode to get the amount returned LogMessageToFile($"The new TaxAmount is: " + taxAmount[0].ToString()); // Shows the tax amount after we changed it // Send message saying we have completed this process in the .txt file LogMessageToFile($"* *"); // Adds a space for easier viewing LogMessageToFile($"* end *"); // Show when we reach the end of the extension LogMessageToFile($"* *"); } // Kept for reference and future use // avalara logging doesn't work from inside extension // client.LogToFile("MySixthExtension\\avataxapi.log"); #endregion return(eSuccess); }
// This method is used to get adjust the tax rate for the user's order public override int CalculateTax2(string OrderID, double taxableAmount, string currencyCode, string[] priceCategories, string[] priceTaxLocales, double[] priceAmount, string[] taxLocaleId, ref double[] taxAmount) { #region This section of code shows what we have been passed // Used to help to see where these mesages are in the Storefront logs page LogMessage($"* space *"); // Adds a space for easier viewing LogMessage($"* START *"); // Show when we start this process LogMessage($"* space *"); // Shows what values are passed at beginning LogMessage(OrderID); // Tells the id for the order being calculated LogMessage(taxableAmount.ToString()); // Tells the amount to be taxed (currently set to 0) LogMessage(currencyCode); // Tells the type of currency used LogMessage(priceCategories.Length.ToString()); // Not Null, but empty LogMessage(priceTaxLocales.Length.ToString()); // Not Null, but empty LogMessage(priceAmount.Length.ToString()); // Not Null, but empty LogMessage(taxLocaleId.Length.ToString()); // Shows the number of tax locales found for this order LogMessage(taxLocaleId[0].ToString()); // Sends a number value which corresponds to the tax rate row in the tax rates table excel file #endregion #region This section is where we set the tax rate based on several zipcodes entered by the user // Shows the section where we change the tax rate LogMessage($"* space *"); LogMessage($"* Tax Section *"); // Used to show where we change the tax rate LogMessage($"* space *"); // This section saves the user's shipping info to variables to use with calculating the tax rate to return // Listed in the same order as in the address book on the site var SFirstName = Storefront.GetValue("OrderField", "ShippingFirstName", OrderID); // This gets the first name that the user has on the shipping page var SLastName = Storefront.GetValue("OrderField", "ShippingLastName", OrderID); // This gets the last name that the user has on the shipping page var SAddress1 = Storefront.GetValue("OrderField", "ShippingAddress1", OrderID); // This gets the address field 1 that the user has on the shipping page var SAddress2 = Storefront.GetValue("OrderField", "ShippingAddress2", OrderID); // This gets the address field 2 that the user has on the shipping page var SCity = Storefront.GetValue("OrderField", "ShippingCity", OrderID); // This gets the city that the user has on the shipping page var SState = Storefront.GetValue("OrderField", "ShippingState", OrderID); // This gets the state that the user has on the shipping page var SPostalCode = Storefront.GetValue("OrderField", "ShippingPostalCode", OrderID); // This gets the zip code that the user has on the shipping page var SCountry = Storefront.GetValue("OrderField", "ShippingCountry", OrderID); // This gets the country that the user has on the shipping page // Log to show that we have retrieved the zipcode form the shipping page LogMessage($"Shipping FirstName: {SFirstName}"); // This gets the first name that the user has on the shipping page LogMessage($"Shipping LastName: {SLastName}"); // This gets the last name that the user has on the shipping page LogMessage($"Shipping Address1: {SAddress1}"); // This gets the address field 1 that the user has on the shipping page LogMessage($"Shipping Address2: {SAddress2}"); // This gets the address field 2 that the user has on the shipping page LogMessage($"Shipping City: {SCity}"); // This gets the city that the user has on the shipping page LogMessage($"Shipping State: {SState }"); // This gets the state that the user has on the shipping page LogMessage($"Shipping PostalCode: {SPostalCode}"); // This gets the zip code that the user has on the shipping page LogMessage($"Shipping Country: {SCountry}"); // This gets the country that the user has on the shipping page // Set the tax amount based on a few zipcodes and send it back to pageflex LogMessage(taxAmount[0].ToString()); // Shows the current tax amount (currently set to 0) // Check if we have a few certain zipcodes to set the value to or just to use the default value if (SPostalCode == "37876") { // Set the new tax amount taxAmount[0] = 18.19; // Set our new tax rate to a value we choose (for testing) LogMessage($"The zipcode was 37876"); // Log message to inform we used this zipcode to get the amount returned LogMessage(taxAmount[0].ToString()); // Shows the tax amount after we changed it } else if (SPostalCode == "12345") { // Set the new tax amount taxAmount[0] = 23.40; LogMessage($"The zipcode was 12345"); LogMessage(taxAmount[0].ToString()); } else if (SPostalCode == "01752") { // Set the new tax amount taxAmount[0] = 3.43; LogMessage($"The zipcode was 01752"); LogMessage(taxAmount[0].ToString()); } else { // Set the new tax amount taxAmount[0] = 13.37; LogMessage($"Default tax was used"); LogMessage(taxAmount[0].ToString()); } // Send message saying we have completed this process LogMessage($"* space *"); LogMessage($"* end *"); LogMessage($"* space *"); // Further reading if needed // Look at pg 436 and 467 invlovling address books if need to use them for zipcodes #endregion #region Using this will tell the storefront to calculate it's own tax using the tax tables // Unused, but keeping as a sidenote //taxAmount = null; #endregion #region This section shows how to get the zipcode and other fields from the user's profile. /* * * //this gets the zip code from the user profile, but we need the zip from the shipping form... * var discountPercentageString = Storefront.GetValue("UserField", "UserProfilePricingDiscount", CurrentUserId); * var PostalCodeString = Storefront.GetValue("UserField", "UserProfilePostalCode", CurrentUserId); * * // Used to help to see where these mesages are in the Storefront logs page * LogMessage($"* space *"); // Adds a space for easier viewing * LogMessage($"* START *"); // Show when we start this process * LogMessage($"* space *"); * * // Log the information retrieved from the user's profile fields * LogMessage($"Current User Id: {CurrentUserId}"); // Return the user's id * LogMessage($"User Zipcode: {PostalCodeString}"); // Return the user's zipcode * * // Send message saying we have completed this process * LogMessage($"* space *"); * LogMessage($"* end *"); // Return a message saying this process is finished * LogMessage($"* space *"); * */ #endregion return(eSuccess); }
// This method is used to get adjust the tax rate for the user's order public override int CalculateTax2(string OrderID, double taxableAmount, string currencyCode, string[] priceCategories, string[] priceTaxLocales, double[] priceAmount, string[] taxLocaleId, ref double[] taxAmount) { #region |--This section of code shows what we have been passed if debug mode is "on"--| // Check if debug mode is turned on; If it is then we log these messages if ((string)ModuleData[_SADEBUGGINGMODE] == "true") { // Used to help to see where these mesages are in the Storefront logs page LogMessage($"* *"); // Adds a space for easier viewing LogMessage($"* START *"); // Show when we start this process LogMessage($"* *"); // Shows what values are passed at beginning LogMessage($"OrderID is: {OrderID}"); // Tells the id for the order being calculated LogMessage($"TaxableAmount is: {taxableAmount.ToString()}"); // Tells the amount to be taxed (currently set to 0) LogMessage($"CurrencyCode is: {currencyCode}"); // Tells the type of currency used LogMessage($"PriceCategories is: {priceCategories.Length.ToString()}"); // Not Null, but empty LogMessage($"PriceTaxLocales is: {priceTaxLocales.Length.ToString()}"); // Not Null, but empty LogMessage($"PriceAmount is: {priceAmount.Length.ToString()}"); // Not Null, but empty LogMessage($"TaxLocaleId is: {taxLocaleId.Length.ToString()}"); // Shows the number of tax locales found for this order LogMessage($"TaxLocaleId[0] is: {taxLocaleId[0].ToString()}"); // Sends a number value which corresponds to the tax rate row in the tax rates table excel file // These Log the messages to a log .txt file // The logs an be found in the Logs folder in the storefront's deployment LogMessageToFile($"* *"); // Adds a space for easier viewing LogMessageToFile($"* START *"); // Show when we start this process LogMessageToFile($"* *"); // Shows what values are passed at beginning in .txt file LogMessageToFile($"OrderID is: {OrderID}"); // Tells the id for the order being calculated LogMessageToFile($"TaxableAmount is: {taxableAmount.ToString()}"); // Tells the amount to be taxed (currently set to 0) LogMessageToFile($"CurrencyCode is: {currencyCode}"); // Tells the type of currency used LogMessageToFile($"PriceCategories is: {priceCategories.Length.ToString()}"); // Not Null, but empty LogMessageToFile($"PriceTaxLocales is: {priceTaxLocales.Length.ToString()}"); // Not Null, but empty LogMessageToFile($"PriceAmount is: {priceAmount.Length.ToString()}"); // Not Null, but empty LogMessageToFile($"TaxLocaleId is: {taxLocaleId.Length.ToString()}"); // Shows the number of tax locales found for this order LogMessageToFile($"TaxLocaleId[0] is: {taxLocaleId[0].ToString()}"); // Sends a number value which corresponds to the tax rate row in the tax rates table excel file } #endregion #region |--This section is where we get and set the values from the shipping page where the user has entered their address info--| // Check if debug mode is turned on; If it is then we log these messages if ((string)ModuleData[_SADEBUGGINGMODE] == "true") { // Shows the section where we get and display what has been added to the shipping page fields LogMessage($"* *"); LogMessage($"*Shipping Fields Section *"); LogMessage($"* *"); // Shows the section where we get and display what has been added to the shipping page fields in the .txt file LogMessageToFile($"* *"); LogMessageToFile($"*Shipping Fields Section *"); LogMessageToFile($"* *"); } // This section saves the user's shipping info to variables to use with calculating the tax rate to return // Listed in the same order as in the address book on the site var SFirstName = Storefront.GetValue("OrderField", "ShippingFirstName", OrderID); // This gets the first name that the user has on the shipping page var SLastName = Storefront.GetValue("OrderField", "ShippingLastName", OrderID); // This gets the last name that the user has on the shipping page var SAddress1 = Storefront.GetValue("OrderField", "ShippingAddress1", OrderID); // This gets the address field 1 that the user has on the shipping page var SAddress2 = Storefront.GetValue("OrderField", "ShippingAddress2", OrderID); // This gets the address field 2 that the user has on the shipping page var SCity = Storefront.GetValue("OrderField", "ShippingCity", OrderID); // This gets the city that the user has on the shipping page var SState = Storefront.GetValue("OrderField", "ShippingState", OrderID); // This gets the state that the user has on the shipping page var SPostalCode = Storefront.GetValue("OrderField", "ShippingPostalCode", OrderID); // This gets the zip code that the user has on the shipping page var SCountry = Storefront.GetValue("OrderField", "ShippingCountry", OrderID); // This gets the country that the user has on the shipping page // Get the handling charge to use with taxes var hCharge = Storefront.GetValue("OrderField", "HandlingCharge", OrderID); // This gets the handling charge for the order var sCharge = Storefront.GetValue("OrderField", "ShippingCharge", OrderID); // This gets the shipping charge for the order // Check if debug mode is turned on; If it is then we log these messages if ((string)ModuleData[_SADEBUGGINGMODE] == "true") { // Log to show that we have retrieved the zipcode form the shipping page LogMessage($"Shipping FirstName: {SFirstName}"); // This gets the first name that the user has on the shipping page LogMessage($"Shipping LastName: {SLastName}"); // This gets the last name that the user has on the shipping page LogMessage($"Shipping Address1: {SAddress1}"); // This gets the address field 1 that the user has on the shipping page LogMessage($"Shipping Address2: {SAddress2}"); // This gets the address field 2 that the user has on the shipping page LogMessage($"Shipping City: {SCity}"); // This gets the city that the user has on the shipping page LogMessage($"Shipping State: {SState}"); // This gets the state that the user has on the shipping page LogMessage($"Shipping PostalCode: {SPostalCode}"); // This gets the zip code that the user has on the shipping page LogMessage($"Shipping Country: {SCountry}"); // This gets the country that the user has on the shipping page LogMessage($"Handling Charge: {hCharge}"); // This gets the zip code that the user has on the shipping page LogMessage($"Shipping Charge: {sCharge}"); // This gets the country that the user has on the shipping page // Log to show that we have retrieved the zipcode form the shipping page in the .txt file LogMessageToFile($"Shipping FirstName: {SFirstName}"); // This gets the first name that the user has on the shipping page LogMessageToFile($"Shipping LastName: {SLastName}"); // This gets the last name that the user has on the shipping page LogMessageToFile($"Shipping Address1: {SAddress1}"); // This gets the address field 1 that the user has on the shipping page LogMessageToFile($"Shipping Address2: {SAddress2}"); // This gets the address field 2 that the user has on the shipping page LogMessageToFile($"Shipping City: {SCity}"); // This gets the city that the user has on the shipping page LogMessageToFile($"Shipping State: {SState}"); // This gets the state that the user has on the shipping page LogMessageToFile($"Shipping PostalCode: {SPostalCode}"); // This gets the zip code that the user has on the shipping page LogMessageToFile($"Shipping Country: {SCountry}"); // This gets the country that the user has on the shipping page LogMessageToFile($"Handling Charge: {hCharge}"); // This gets the zip code that the user has on the shipping page LogMessageToFile($"Shipping Charge: {sCharge}"); // This gets the country that the user has on the shipping page } #endregion #region |--This is the section that connects and pulls info from avalara--| // Check if debug mode is turned on; If it is then we log these messages if ((string)ModuleData[_SADEBUGGINGMODE] == "true") { // Shows the section where we change the tax rate LogMessage($"* *"); LogMessage($"* Tax Rates Section *"); LogMessage($"* *"); // Set the tax amount based on a few zipcodes and send it back to pageflex LogMessage($"Tax amount is: " + taxAmount[0].ToString() + " before we retrieve from Avalara"); // Shows the current tax amount (currently set to 0) // Shows the section where we change the tax rate in the .txt file LogMessageToFile($"* *"); LogMessageToFile($"* Tax Rates Section *"); LogMessageToFile($"* *"); // Set the tax amount based on a few zipcodes and send it back to pageflex in the .txt file LogMessageToFile($"Tax amount is: " + taxAmount[0].ToString() + " before we retrieve from Avalara"); // Shows the current tax amount (currently set to 0) } #region |--Database call to retrieve the subtotal should go here--| // TO DO: Database call to retrieve the subtotal should go here if can't get storefront access to work #endregion // Create a client and set up authentication var client = new AvaTaxClient("MyApp", "1.0", Environment.MachineName, AvaTaxEnvironment.Production) .WithSecurity("AvalaraUsername", "AvalaraPassword"); // Check if debug mode is turned on; If it is then we log these messages if ((string)ModuleData[_SADEBUGGINGMODE] == "true") { // Show user creation passed LogMessage("Client created"); // Show user creation passed in the .txt file LogMessageToFile("Client created"); } // This creates the transaction that reaches out to alavara and gets the amount of tax for the user based on info we send // send client we created above in code, the company on alavara I created, typoe of transaction, and the company code I set up for company var transaction = new TransactionBuilder(client, "AvalaraCompanyCode", DocumentType.SalesOrder, "AvalaraCustomerCode") // Pass the variables we pulled from pageflex in the address line .WithAddress(TransactionAddressType.SingleLocation, SAddress1, SAddress2, null, SCity, SState, SPostalCode, SCountry) // Pass the amount of money to calculate tax on (This should be a variable once figure out what it is) .WithLine(150.0m) #region |--Here is where we will send the total retrieved from db call--| // Here is where we will send the total retrieved from db call //.WithLine(REPLACE WITH VARIABLE CONTAING TOTAL FROM DB CALL) #endregion // Run transaction .Create(); // Check if debug mode is turned on; If it is then we log these messages if ((string)ModuleData[_SADEBUGGINGMODE] == "true") { // Log that we have created a transaction LogMessage("The transaction has been created"); // Log that we have created a transaction in the .txt file LogMessageToFile("The transaction has been created"); } // Retrieves the tax amount from Avalara and sets it to a variable // (It is returned as a decimal? so we havve to convert it to a decimal) // (The ?? 0 sets it to 0 if transaction.totalTax is null) decimal tax2 = transaction.totalTax ?? 0; // Check if debug mode is turned on; If it is then we log these messages if ((string)ModuleData[_SADEBUGGINGMODE] == "true") { //Log what is returned LogMessage($"Your calculated tax was: {tax2}"); //Log what is returned in the .txt file LogMessageToFile($"Your calculated tax was: {tax2}"); } //Set the tax amount on pageflex to the returned value from Avalara taxAmount[0] = decimal.ToDouble(tax2); // Set our new tax rate to a value we choose (for testing) // Check if debug mode is turned on; If it is then we log these messages if ((string)ModuleData[_SADEBUGGINGMODE] == "true") { LogMessage($"The zipcode was: " + SPostalCode); // Log message to inform we used this zipcode to get the amount returned LogMessage($"The new TaxAmount is: " + taxAmount[0].ToString()); // Shows the tax amount after we changed it // Send message saying we have completed this process LogMessage($"* *"); LogMessage($"* end *"); LogMessage($"* *"); // Log for .txt file LogMessageToFile($"The zipcode was: " + SPostalCode); // Log message to inform we used this zipcode to get the amount returned LogMessageToFile($"The new TaxAmount is: " + taxAmount[0].ToString()); // Shows the tax amount after we changed it // Send message saying we have completed this process in the .txt file LogMessageToFile($"* *"); LogMessageToFile($"* end *"); LogMessageToFile($"* *"); } // Kept for reference and future use // avalara logging doesn't work from inside extension // client.LogToFile("MySixthExtension\\avataxapi.log"); #endregion return(eSuccess); }
// This method sets the handling charge public override int CalculateHandlingCharge(string orderId, out double handlingCharge, out string isoCurrencyCode) { // Log messages to the store and to the .txt file to show the storefronts original handling charge // I had to use these to figure out that my variables for the flags were not being passed between methods because they were not static if ((string)ModuleData[_EH_DEBUGGING_MODE] == "true") { // Log messages to the storefront "Logs" page LogMessage($"-----------------------------------------------------"); LogMessage($"Step 3: Checking to See if We Need to Change Handling"); LogMessage($"Storefront Order ID: {orderId}"); LogMessage($"Storefront Handling Charge: {storeHandlingCharge}"); LogMessage($"Extension Yes Flag: {extensionYesFlag}"); LogMessage($"Extension No Flag: {extensionNoFlag}"); // Log messages to the .txt file LogMessageToFile($"-----------------------------------------------------"); LogMessageToFile($"Step 3: Checking to See if We Need to Change Handling"); LogMessageToFile($"Storefront Order ID: {orderId}"); LogMessageToFile($"Storefront Handling Charge: {storeHandlingCharge}"); LogMessageToFile($"Extension Yes Flag: {extensionYesFlag}"); LogMessageToFile($"Extension No Flag: {extensionNoFlag}"); } // Place in try catch to ensure we are alerted if something goes wrong try { // Check to see if the condition in which we will exclude handling is met // If the exclude handling Yes flag is set to Yes and the exclude handling No flag is set to No then we are good to exclude the handling if (extensionYesFlag.Equals("Yes") && extensionNoFlag.Equals("No")) { // Set the excluded handling charge to be zero and return the same currency code we are required to return as well handlingCharge = 0.00; isoCurrencyCode = Storefront.GetValue(FieldType.SystemProperty, "IsoCurrencyCode", orderId); // Log messages to the store and to the .txt file to show we have returned the isocurrentcycode correctly // and to tell that we have excluded the handling charge as well if ((string)ModuleData[_EH_DEBUGGING_MODE] == "true") { // Log messages to the storefront "Logs" page LogMessage($"Yes, We Need to Change the Handling Charge"); LogMessage($"V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V"); LogMessage($"-----------------------------------------------------"); LogMessage($"Show returned isoCurrencyCode: {isoCurrencyCode}"); LogMessage($"The Handling Was Excluded from the Order"); LogMessage($"-----------------------------------------------------"); LogMessage($"V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V"); // Log messages to the .txt file LogMessageToFile($"Yes, We Need to Change the Handling Charge"); LogMessageToFile($"V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V"); LogMessageToFile($"-----------------------------------------------------"); LogMessageToFile($"Show returned isoCurrencyCode: {isoCurrencyCode}"); LogMessageToFile($"The Handling Was Excluded from the Order"); LogMessageToFile($"-----------------------------------------------------"); LogMessageToFile($"V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V"); } // Send the new data back to the storefront for the handling charge return(eSuccess); } else { // We set the values back to what was already on the store before we started handlingCharge = storeHandlingCharge; isoCurrencyCode = Storefront.GetValue(FieldType.SystemProperty, "IsoCurrencyCode", orderId); // Log messages to the store and to the .txt file to show we have returned the isocurrentcycode correctly // and to tell that we have NOT excluded the handling charge as well if ((string)ModuleData[_EH_DEBUGGING_MODE] == "true") { // Log messages to the storefront "Logs" page LogMessage($"V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V"); LogMessage($"-----------------------------------------------------"); LogMessage($"Show returned isoCurrencyCode: {isoCurrencyCode}"); LogMessage($"Handling Was Not Excluded"); LogMessage($"-----------------------------------------------------"); LogMessage($"V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V"); // Log messages to the .txt file LogMessageToFile($"V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V"); LogMessageToFile($"-----------------------------------------------------"); LogMessageToFile($"Show returned isoCurrencyCode: {isoCurrencyCode}"); LogMessageToFile($"Handling Was Not Excluded"); LogMessageToFile($"-----------------------------------------------------"); LogMessageToFile($"V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V^V"); } // Send the new data back to the storefront for the handling charge return(eSuccess); } } catch { // We set the values back to what was already on the store before we started handlingCharge = storeHandlingCharge; isoCurrencyCode = Storefront.GetValue(FieldType.SystemProperty, "IsoCurrencyCode", orderId); // Log issue with storefront and to file regardless of whether in debug mode or not LogMessage("Error in CalculateHandlingCharge Method"); // This logs that there was an error in the CalculateHandlingCharge Method LogMessageToFile("Error in CalculateHandlingCharge Method"); // This logs that there was an error in the CalculateHandlingCharge Method // Get the storefront's name from storefront and Date and time stamps as desired string sfName = SF.GetValue(FieldType.SystemProperty, SystemProperty.STOREFRONT_NAME, null); string currentLogDate = DateTime.Now.ToString("MMddyyyy"); string currentLogTimeInsertMain = DateTime.Now.ToString("HH:mm:ss tt"); //Setup our date and time for error string ErrorDate = string.Format("Date: {0} Time: {1:G} <br>", currentLogDate, currentLogTimeInsertMain); // Setup our email body and message string subjectstring = "Storefront: \"" + sfName + "\" had an ERROR occur in the CalculateHandlingCharge Method"; string bodystring = "Storefront: \"" + sfName + "\" had an ERROR occur in the CalculateHandlingCharge Method <br>" + ErrorDate + "Extension: Exclude Handling Extension <br>" + "ERROR occured with User ID: " + ErrorUserID + "<br>" + "ERROR occured with Order ID: " + ErrorOrderID + "<br>"; // Call method to send our error as an email to developers maintaining sites EmailErrorNotify.CreateMessage(subjectstring, bodystring); // Log issue with storefront and to file regardless of whether in debug mode or not LogMessage($"Error in CalculateHandlingCharge Method send email method called"); // This logs that Error in CalculateHandlingCharge Method send email method called LogMessageToFile($"Error in CalculateHandlingCharge Method send email method called"); // This logs that Error in CalculateHandlingCharge Method send email method called LogMessage($"Email sent successfully: {EmailErrorNotify.checkFlag}"); // This logs Email sent successfully flag response LogMessageToFile($"Email sent successfully: {EmailErrorNotify.checkFlag}"); // This logs Email sent successfully flag response // Send the response validation is complete return(eSuccess); } }
// This is called when the user hits the "Proceed to Checkout" button on the storefront public override int CheckoutSteps_Before(string userID, string orderID, string[] docIds) { // Log messages to the store and to the .txt file to alert we are about to start this process if ((string)ModuleData[_EH_DEBUGGING_MODE] == "true") { // Log messages to the storefront "Logs" page LogMessage($"-----------------------------------------------------"); LogMessage($"Step 1: Try to get the storefront handling charge"); // Log messages to the .txt file LogMessageToFile($"-----------------------------------------------------"); LogMessageToFile($"Step 1: Try to get the storefront handling charge"); } // Place in try catch to ensure we are alerted if something goes wrong try { // Set our error values for catch blocks ErrorUserID = userID; ErrorOrderID = orderID; // Get the storefront handling charge to use to keep it the same if we don't need to override it storeHandlingCharge = Convert.ToDouble(Storefront.GetValue(FieldType.OrderProperty, "HandlingCharge", orderID)); // Log messages to the store and to the .txt file to show the storefronts original handling charge if ((string)ModuleData[_EH_DEBUGGING_MODE] == "true") { // Log messages to the storefront "Logs" page LogMessage($"Storefront Handling Charge: {storeHandlingCharge}"); LogMessageToFile($"Storefront Handling Charge: {storeHandlingCharge}"); // Log messages to the .txt file LogMessage($"Storefront Handling Charge: {storeHandlingCharge}"); LogMessageToFile($"Storefront Handling Charge: {storeHandlingCharge}"); } // Set These values to start as "No" extensionYesFlag = "No"; extensionNoFlag = "No"; // We need to check each item in the cart foreach (var docID in docIds) { // Call to check if this item has the flag set to yes or not ValidateDocument(docID, "check"); } // Log messages to the store and to the .txt file to show that the flags are still set here // I had to use these to figure out that my variables for the flags were not being passed between methods because they were not static if ((string)ModuleData[_EH_DEBUGGING_MODE] == "true") { // Log messages to the storefront "Logs" page LogMessage($"-----------------------------------------------------"); LogMessage($"Foreach Extension Yes Flag Set: {extensionYesFlag}"); LogMessage($"Foreach Extension No Flag Set: {extensionNoFlag}"); // Log messages to the .txt file LogMessageToFile($"-----------------------------------------------------"); LogMessageToFile($"Foreach Extension Yes Flag Set: {extensionYesFlag}"); LogMessageToFile($"Foreach Extension No Flag Set: {extensionNoFlag}"); } // Send the response that the steps before checkout have been completed return(eSuccess); } catch { // Log issue with storefront and to file regardless of whether in debug mode or not LogMessage("Error in CheckoutSteps_Before Method"); // This logs that there was an error in the CheckoutSteps_Before Method LogMessageToFile("Error in CheckoutSteps_Before Method"); // This logs that there was an error in the CheckoutSteps_Before Method // Get the storefront's name from storefront and Date and time stamps as desired string sfName = SF.GetValue(FieldType.SystemProperty, SystemProperty.STOREFRONT_NAME, null); string currentLogDate = DateTime.Now.ToString("MMddyyyy"); string currentLogTimeInsertMain = DateTime.Now.ToString("HH:mm:ss tt"); //Setup our date and time for error string ErrorDate = string.Format("Date: {0} Time: {1:G} <br>", currentLogDate, currentLogTimeInsertMain); // Setup our email body and message string subjectstring = "Storefront: \"" + sfName + "\" had an ERROR occur in the CheckoutSteps_Before Method"; string bodystring = "Storefront: \"" + sfName + "\" had an ERROR occur in the CheckoutSteps_Before Method <br>" + ErrorDate + "Extension: Exclude Handling Extension <br>" + "ERROR occured with User ID: " + ErrorUserID + "<br>" + "ERROR occured with Order ID: " + ErrorOrderID; // Call method to send our error as an email to developers maintaining sites EmailErrorNotify.CreateMessage(subjectstring, bodystring); // Log issue with storefront and to file regardless of whether in debug mode or not LogMessage($"Error in CheckoutSteps_Before Method send email method called"); // This logs that Error in ValidateDocument Method send email method called LogMessageToFile($"Error in CheckoutSteps_Before Method send email method called"); // This logs that Error in ValidateDocument Method send email method called LogMessage($"Email sent successfully: {EmailErrorNotify.checkFlag}"); // This logs Email sent successfully flag response LogMessageToFile($"Email sent successfully: {EmailErrorNotify.checkFlag}"); // This logs Email sent successfully flag response // Send the response validation is complete return(eSuccess); } }
// Step 1 and 2 are reversed because step 2 comes second, but is called in step 1 -- methods should be placed before they are called #region |--Step 2: Validate Document Section (Called to check what the items in the cart have their exclude handlig flags set to)--| // Checks each document (item in the shipping cart) to see if it has the flag to exclude handling set or not when called public int ValidateDocument(string docID, string action) { // Place in try catch to ensure we are alerted if something goes wrong try { // Set our error values for catch blocks ErrorDocID = docID; ErrorProductID = Storefront.GetValue(FieldType.DocumentProperty, DocumentProperty.PRODUCT_ID, ErrorDocID); ErrorProductName = Storefront.GetValue(FieldType.ProductProperty, ProductProperty.DISPLAY_NAME, ErrorProductID); ErrorProductSKU = Storefront.GetValue(FieldType.ProductField, "PRODUCT_SKU", ErrorProductID); ErrorStoreExcludeHandlingFlag = Storefront.GetValue(FieldType.ProductField, "excludeHandling", ErrorProductID); // Get the values from the storefront to use to see if our order needs to have the handling excluded or not var productID = Storefront.GetValue(FieldType.DocumentProperty, DocumentProperty.PRODUCT_ID, docID); var productName = Storefront.GetValue(FieldType.ProductProperty, ProductProperty.DISPLAY_NAME, productID); var productSKU = Storefront.GetValue(FieldType.ProductField, "PRODUCT_SKU", productID); var storeExcludeHandlingFlag = Storefront.GetValue(FieldType.ProductField, "excludeHandling", productID); // Log messages to the store and to the .txt file to show what we have retrieved if ((string)ModuleData[_EH_DEBUGGING_MODE] == "true") { // Log messages to the storefront "Logs" page LogMessage($"....................................................."); LogMessage($"-----------------------------------------------------"); LogMessage($"Step 2: Validating Document: {docID}"); LogMessage($"Product ID: {productID}"); LogMessage($"Product Name: {productName}"); LogMessage($"Product SKU: {productSKU}"); LogMessage($"Exclude Handling Flag: {storeExcludeHandlingFlag}"); // Log messages to the .txt file LogMessageToFile($"....................................................."); LogMessageToFile($"-----------------------------------------------------"); LogMessageToFile($"Step 2: Validating Document: {docID}"); LogMessageToFile($"Product ID: {productID}"); LogMessageToFile($"Product Name: {productName}"); LogMessageToFile($"Product SKU: {productSKU}"); LogMessageToFile($"Exclude Handling Flag: {storeExcludeHandlingFlag}"); } // Check to see if the storefront retrieved exclude handling fee flag is set to yes or no if (storeExcludeHandlingFlag.Equals("Yes")) { // If it is set to exclude the handling then we set our extension YES flag to be "Yes" extensionYesFlag = "Yes"; } else if (storeExcludeHandlingFlag.Equals("No")) { // If it is set to NOT exclude the handling then we set our extension NO flag to be "Yes" extensionNoFlag = "Yes"; } // Log messages to the store and to the .txt file to show what the flags have been set to if ((string)ModuleData[_EH_DEBUGGING_MODE] == "true") { // Log messages to the storefront "Logs" page LogMessage($"Validate Extension Yes Flag Set: {extensionYesFlag}"); LogMessage($"Validate Extension No Flag Set: {extensionNoFlag}"); // Log messages to the .txt file LogMessageToFile($"Validate Extension Yes Flag Set: {extensionYesFlag}"); LogMessageToFile($"Validate Extension No Flag Set: {extensionNoFlag}"); } // Send the response that this section is complete whether works or not so it doesn't crash return(eSuccess); } catch { // Log issue with storefront and to file regardless of whether in debug mode or not LogMessage("Error in ValidateDocument Method"); // This logs that there was an error in the ValidateDocument Method LogMessageToFile("Error in ValidateDocument Method"); // This logs that there was an error in the ValidateDocument Method // Get the storefront's name from storefront and Date and time stamps as desired string sfName = SF.GetValue(FieldType.SystemProperty, SystemProperty.STOREFRONT_NAME, null); string currentLogDate = DateTime.Now.ToString("MMddyyyy"); string currentLogTimeInsertMain = DateTime.Now.ToString("HH:mm:ss tt"); //Setup our date and time for error string ErrorDate = string.Format("Date: {0} Time: {1:G} <br>", currentLogDate, currentLogTimeInsertMain); // Setup our email body and message string subjectstring = "Storefront: \"" + sfName + "\" had an ERROR occur in the ValidateDocument Method"; string bodystring = "Storefront: \"" + sfName + "\" had an ERROR occur in the ValidateDocument Method <br>" + ErrorDate + "Extension: Exclude Handling Extension <br>" + "ERROR occured with User ID: " + ErrorUserID + "<br>" + "ERROR occured with Order ID: " + ErrorOrderID + "<br>" + "ERROR occured with Doc ID: " + ErrorDocID + "<br>" + "ERROR occured with Error Product ID: " + ErrorProductID + "<br>" + "ERROR occured with Error Product Name : " + ErrorProductName + "<br>" + "ERROR occured with Error Product SKU: " + ErrorProductSKU + "<br>" + "ERROR occured with Error Store Exclude Handling Flag: " + ErrorStoreExcludeHandlingFlag; // Call method to send our error as an email to developers maintaining sites EmailErrorNotify.CreateMessage(subjectstring, bodystring); // Log issue with storefront and to file regardless of whether in debug mode or not LogMessage($"Error in ValidateDocument Method send email method called"); // This logs that Error in ValidateDocument Method send email method called LogMessageToFile($"Error in ValidateDocument Method send email method called"); // This logs that Error in ValidateDocument Method send email method called LogMessage($"Email sent successfully: {EmailErrorNotify.checkFlag}"); // This logs Email sent successfully flag response LogMessageToFile($"Email sent successfully: {EmailErrorNotify.checkFlag}"); // This logs Email sent successfully flag response // Send the response validation is complete return(eSuccess); } }
// This method is used to get adjust the tax rate for the user's order public override int CalculateTax2(string OrderID, double taxableAmount, string currencyCode, string[] priceCategories, string[] priceTaxLocales, double[] priceAmount, string[] taxLocaleId, ref double[] taxAmount) { #region This section of code shows what we have been passed and changes the tax value to return // Used to help to see where these mesages are in the Storefront logs page LogMessage($"* space *"); // Adds a space for easier viewing LogMessage($"* START *"); // Show when we start this process LogMessage($"* space *"); // Shows what values are passed at beginning LogMessage(OrderID); // Tells the id for the order being calculated LogMessage(taxableAmount.ToString()); // Tells the amount to be taxed (currently set to 0) LogMessage(currencyCode); // Tells the type of currency used LogMessage(priceCategories.Length.ToString()); // Not Null, but empty LogMessage(priceTaxLocales.Length.ToString()); // Not Null, but empty LogMessage(priceAmount.Length.ToString()); // Not Null, but empty LogMessage(taxLocaleId.Length.ToString()); // Shows the number of tax locales found for this order LogMessage(taxLocaleId[0].ToString()); // Sends a number value which corresponds to the tax rate row in the tax rates table excel file // Shows the section where we change the tax rate LogMessage($"* space *"); LogMessage($"* Tax Section *"); // Used to show where we change the tax rate LogMessage($"* space *"); // Set the tax amount to send back to pageflex LogMessage(taxAmount[0].ToString()); // Shows the current tax amount (currently set to 0) taxAmount[0] = 23.40; // Set our new tax rate to a value we choose (for testing) LogMessage(taxAmount[0].ToString()); // Shows the tax amount after we changed it // Send message saying we have completed this process LogMessage($"* space *"); LogMessage($"* end *"); LogMessage($"* space *"); #endregion #region This section of code gets the zipcode the user has entered on the shipping page // This gets the zip code that the user has on the shipping page var PostalCode = Storefront.GetValue("OrderField", "ShippingPostalCode", OrderID); // Used to help to see where these mesages are in the Storefront logs page LogMessage($"* space *"); LogMessage($"* START *"); LogMessage($"* space *"); // Log to show that we have retrieved the zipcode form the shipping page LogMessage($"Shipping Zipcode: {PostalCode}"); // Send message saying we have completed this process LogMessage($"* space *"); LogMessage($"* end *"); LogMessage($"* space *"); // Further reading if needed // Look at pg 436 and 467 invlovling address books if need to use them for zipcodes #endregion #region Using this will tell the storefront to calculate it's own tax using the tax tables // Unused, but keeping as a sidenote //taxAmount = null; #endregion #region This section shows how to get the zipcode and other fields from the user's profile. /* * * //this gets the zip code from the user profile, but we need the zip from the shipping form... * var discountPercentageString = Storefront.GetValue("UserField", "UserProfilePricingDiscount", CurrentUserId); * var PostalCodeString = Storefront.GetValue("UserField", "UserProfilePostalCode", CurrentUserId); * * // Used to help to see where these mesages are in the Storefront logs page * LogMessage($"* space *"); // Adds a space for easier viewing * LogMessage($"* START *"); // Show when we start this process * LogMessage($"* space *"); * * // Log the information retrieved from the user's profile fields * LogMessage($"Current User Id: {CurrentUserId}"); // Return the user's id * LogMessage($"User Zipcode: {PostalCodeString}"); // Return the user's zipcode * * // Send message saying we have completed this process * LogMessage($"* space *"); * LogMessage($"* end *"); // Return a message saying this process is finished * LogMessage($"* space *"); * */ #endregion return(eSuccess); }
// This method is used to get adjust the tax rate for the user's order public override int CalculateTax2(string OrderID, double taxableAmount, string currencyCode, string[] priceCategories, string[] priceTaxLocales, double[] priceAmount, string[] taxLocaleId, ref double[] taxAmount) { #region This section of code shows what we have been passed // Used to help to see where these mesages are in the Storefront logs page LogMessage($"* space *"); // Adds a space for easier viewing LogMessage($"* START *"); // Show when we start this process LogMessage($"* space *"); // Shows what values are passed at beginning LogMessage(OrderID); // Tells the id for the order being calculated LogMessage(taxableAmount.ToString()); // Tells the amount to be taxed (currently set to 0) LogMessage(currencyCode); // Tells the type of currency used LogMessage(priceCategories.Length.ToString()); // Not Null, but empty LogMessage(priceTaxLocales.Length.ToString()); // Not Null, but empty LogMessage(priceAmount.Length.ToString()); // Not Null, but empty LogMessage(taxLocaleId.Length.ToString()); // Shows the number of tax locales found for this order LogMessage(taxLocaleId[0].ToString()); // Sends a number value which corresponds to the tax rate row in the tax rates table excel file #endregion #region This section is where we set the tax rate based on several zipcodes entered by the user // Shows the section where we change the tax rate LogMessage($"* space *"); LogMessage($"* Tax Section *"); // Used to show where we change the tax rate LogMessage($"* space *"); // This section saves the user's shipping info to variables to use with calculating the tax rate to return // Listed in the same order as in the address book on the site var SFirstName = Storefront.GetValue("OrderField", "ShippingFirstName", OrderID); // This gets the first name that the user has on the shipping page var SLastName = Storefront.GetValue("OrderField", "ShippingLastName", OrderID); // This gets the last name that the user has on the shipping page var SAddress1 = Storefront.GetValue("OrderField", "ShippingAddress1", OrderID); // This gets the address field 1 that the user has on the shipping page var SAddress2 = Storefront.GetValue("OrderField", "ShippingAddress2", OrderID); // This gets the address field 2 that the user has on the shipping page var SCity = Storefront.GetValue("OrderField", "ShippingCity", OrderID); // This gets the city that the user has on the shipping page var SState = Storefront.GetValue("OrderField", "ShippingState", OrderID); // This gets the state that the user has on the shipping page var SPostalCode = Storefront.GetValue("OrderField", "ShippingPostalCode", OrderID); // This gets the zip code that the user has on the shipping page var SCountry = Storefront.GetValue("OrderField", "ShippingCountry", OrderID); // This gets the country that the user has on the shipping page // Log to show that we have retrieved the zipcode form the shipping page LogMessage($"Shipping FirstName: {SFirstName}"); // This gets the first name that the user has on the shipping page LogMessage($"Shipping LastName: {SLastName}"); // This gets the last name that the user has on the shipping page LogMessage($"Shipping Address1: {SAddress1}"); // This gets the address field 1 that the user has on the shipping page LogMessage($"Shipping Address2: {SAddress2}"); // This gets the address field 2 that the user has on the shipping page LogMessage($"Shipping City: {SCity}"); // This gets the city that the user has on the shipping page LogMessage($"Shipping State: {SState}"); // This gets the state that the user has on the shipping page LogMessage($"Shipping PostalCode: {SPostalCode}"); // This gets the zip code that the user has on the shipping page LogMessage($"Shipping Country: {SCountry}"); // This gets the country that the user has on the shipping page // Set the tax amount based on a few zipcodes and send it back to pageflex LogMessage(taxAmount[0].ToString()); // Shows the current tax amount (currently set to 0) // Create a client and set up authentication var client = new AvaTaxClient("MyApp", "1.0", Environment.MachineName, AvaTaxEnvironment.Production) .WithSecurity("AvalaraUsername", "AvalaraPassword"); LogMessage("Client created"); client.LogToFile("MySixthExtension\\avataxapi.log"); var transaction = new TransactionBuilder(client, "AvalaraCompanyCode", DocumentType.SalesOrder, "AvalaraCustomerCode") .WithAddress(TransactionAddressType.SingleLocation, SAddress1, SAddress2, null, SCity, SState, SPostalCode, SCountry) .WithLine(150.0m) .Create(); //var tax = transaction.totalTax; decimal tax2 = transaction.totalTax ?? 0; LogMessage($"Your calculated tax was: {tax2}"); // Console.WriteLine("Your calculated tax was {0}", transaction.totalTax); taxAmount[0] = decimal.ToDouble(tax2); // Set our new tax rate to a value we choose (for testing) LogMessage($"The zipcode was " + SPostalCode); // Log message to inform we used this zipcode to get the amount returned LogMessage(taxAmount[0].ToString()); // Shows the tax amount after we changed it /* * // Check if we have a few certain zipcodes to set the value to or just to use the default value * if (SPostalCode == "37876") * { * // Set the new tax amount * taxAmount[0] = 18.19; // Set our new tax rate to a value we choose (for testing) * LogMessage($"The zipcode was 37876"); // Log message to inform we used this zipcode to get the amount returned * LogMessage(taxAmount[0].ToString()); // Shows the tax amount after we changed it * } * else if (SPostalCode == "12345") * { * // Set the new tax amount * taxAmount[0] = 23.40; * LogMessage($"The zipcode was 12345"); * LogMessage(taxAmount[0].ToString()); * } * else if (SPostalCode == "01752") * { * // Set the new tax amount * taxAmount[0] = 3.43; * LogMessage($"The zipcode was 01752"); * LogMessage(taxAmount[0].ToString()); * } * else * { * // Set the new tax amount * taxAmount[0] = 13.37; * LogMessage($"Default tax was used"); * LogMessage(taxAmount[0].ToString()); * } * * // Send message saying we have completed this process * LogMessage($"* space *"); * LogMessage($"* end *"); * LogMessage($"* space *"); */ // Further reading if needed // Look at pg 436 and 467 invlovling address books if need to use them for zipcodes #endregion #region Using this will tell the storefront to calculate it's own tax using the tax tables // Unused, but keeping as a sidenote //taxAmount = null; #endregion #region This section shows how to get the zipcode and other fields from the user's profile. /* * * //this gets the zip code from the user profile, but we need the zip from the shipping form... * var discountPercentageString = Storefront.GetValue("UserField", "UserProfilePricingDiscount", CurrentUserId); * var PostalCodeString = Storefront.GetValue("UserField", "UserProfilePostalCode", CurrentUserId); * * // Used to help to see where these mesages are in the Storefront logs page * LogMessage($"* space *"); // Adds a space for easier viewing * LogMessage($"* START *"); // Show when we start this process * LogMessage($"* space *"); * * // Log the information retrieved from the user's profile fields * LogMessage($"Current User Id: {CurrentUserId}"); // Return the user's id * LogMessage($"User Zipcode: {PostalCodeString}"); // Return the user's zipcode * * // Send message saying we have completed this process * LogMessage($"* space *"); * LogMessage($"* end *"); // Return a message saying this process is finished * LogMessage($"* space *"); * */ #endregion return(eSuccess); }