public static int AddInvoice(string contractId, DateTime created, DateTime dueDate, int taxationId, decimal totalAmount, decimal subTotalAmount, decimal taxAmount, List <InvoiceItem> invoiceLines, KeyValueBunch extraArgs) { // try { Contract contract = ContractSystem.ContractController.GetContract(contractId); // ES.TaskManager.StartTask(SystemTasks.SOURCE_ECOMMERCE, SystemTasks.TASK_ADD_INVOICE); // build xml representation string invoiceLinesXml = BuildAddXmlForInvoiceItems(invoiceLines); // add invoice int result = EcommerceProvider.AddInvoice(contractId, created, dueDate, taxationId, totalAmount, subTotalAmount, taxAmount, invoiceLinesXml, StorehouseController.GetBaseCurrency(contract.ResellerId)); // check error if (result < 1) { return(result); // EXIT } // build invoice number Invoice invoice = GetCustomerInvoiceInternally(result); StoreSettings settings = StorehouseController.GetStoreSettings(contract.ResellerId, StoreSettings.SYSTEM_SETTINGS); if (!String.IsNullOrEmpty(settings["InvoiceNumberFormat"])) { Hashtable options = new Hashtable(); options["ID"] = result; invoice.InvoiceNumber = StorehouseController.ApplyStringCustomFormat( settings["InvoiceNumberFormat"], options); } else { invoice.InvoiceNumber = result.ToString(); } // update invoice InvoiceController.UpdateInvoice(invoice.InvoiceId, invoice.InvoiceNumber, invoice.DueDate, invoice.Total, invoice.SubTotal, invoice.TaxationId, invoice.TaxAmount, invoice.Currency); // Hashtable parameters = new Hashtable(); parameters.Add(SystemTaskParams.PARAM_CONTRACT, contract); parameters.Add(SystemTaskParams.PARAM_INVOICE, invoice); parameters.Add(SystemTaskParams.PARAM_INVOICE_LINES, invoiceLines); parameters.Add(SystemTaskParams.PARAM_EXTRA_ARGS, extraArgs); TaskManager.UpdateParams(parameters); // return(result); } catch (Exception ex) { throw ES.TaskManager.WriteError(ex); } finally { ES.TaskManager.CompleteTask(); } }
public int UpdateHostingPlan(int userId, int productId, string planName, string productSku, bool taxInclusive, int planId, int userRole, int initialStatus, int domainOption, bool enabled, string planDescription, HostingPlanCycle[] planCycles, string[] planHighlights, int[] planCategories) { return(StorehouseController.UpdateHostingPlan(userId, productId, planName, productSku, taxInclusive, planId, userRole, initialStatus, domainOption, enabled, planDescription, planCycles, planHighlights, planCategories)); }
public static int DeleteCustomerService(int serviceId) { SecurityResult result = StorehouseController.CheckAccountNotDemoAndActive(); // if (!result.Success) { return(result.ResultCode); } // return(EcommerceProvider.DeleteCustomerService(ES.SecurityContext.User.UserId, serviceId)); }
public int AddServiceInfo(string contractId, string currency, OrderItem orderItem) { // get hosting addon product HostingAddon addon = StorehouseController.GetHostingAddon(SecurityContext.User.UserId, orderItem.ProductId); // uncountable addons always have 1 for quantity int quantity = addon.Countable ? orderItem.Quantity : 1; // add hosting addon return(EcommerceProvider.AddHostingAddonSvc(contractId, orderItem.ParentSvcId, orderItem.ProductId, quantity, orderItem.ItemName, orderItem.BillingCycle, currency)); }
public static int SetPluginProperties(int userId, int pluginId, KeyValueBunch props) { string xmlText = String.Empty; string[][] pluginProps = null; SecurityResult result = StorehouseController.CheckAccountNotDemoAndActive(); // if (!result.Success) { return(result.ResultCode); } if (props != null) { // create system plugin SystemPluginBase pluginObj = GetSystemPluginInstance(userId, pluginId, false); // crypt sensitive data foreach (string keyName in props.GetAllKeys()) { // string keyValue = props[keyName]; // if (pluginObj.SecureSettings != null) { int indexOf = Array.IndexOf(pluginObj.SecureSettings, keyName); // crypt sensitive data if (indexOf > -1) { keyValue = CryptoUtils.Encrypt(keyValue); } } // props[keyName] = keyValue; } // load old properties KeyValueBunch oldProps = GetPluginPropertiesInternal(userId, pluginId, false, pluginObj.SecureSettings); // merge old props with new props foreach (string keyName in props.GetAllKeys()) { // copy oldProps[keyName] = props[keyName]; } // pluginProps = oldProps.KeyValueArray; } // build update xml xmlText = SettingsHelper.ConvertObjectSettings(pluginProps, "properties", "property"); // return(EcommerceProvider.SetPluginProperties(SecurityContext.User.UserId, userId, pluginId, xmlText)); }
public static int VoidCustomerInvoice(int invoiceId) { SecurityResult result = StorehouseController.CheckAccountIsAdminOrReseller(); if (!result.Success) { return(result.ResultCode); } // void EcommerceProvider.VoidCustomerInvoice(ES.SecurityContext.User.UserId, invoiceId); // return(0); }
public bool CheckOperationClientStatus(GenericSvcResult result) { // 2. Check account status SecurityResult secResult = StorehouseController.CheckAccountNotDemoAndActive(); // ERROR if (!secResult.Success) { result.Succeed = false; result.ResultCode = secResult.ResultCode; // return(false); } // return(true); }
public bool CheckOperationClientPermissions(GenericSvcResult result) { // 1. Do security checks SecurityResult secResult = StorehouseController.CheckAccountIsAdminOrReseller(); // ERROR if (!secResult.Success) { result.Succeed = false; result.ResultCode = secResult.ResultCode; // return(false); } // return(true); }
public static int DeleteCategory(int userId, int categoryId) { SecurityResult result = StorehouseController.CheckAccountNotDemoAndActive(); // if (!result.Success) { return(result.ResultCode); } return(EcommerceProvider.DeleteCategory( ES.SecurityContext.User.UserId, userId, categoryId )); }
public void CancelOverdueServices() { // load store settings StoreSettings settings = StorehouseController.GetStoreSettings(SecurityContext.User.UserId, StoreSettings.SYSTEM_SETTINGS); // int threshold = Convert.ToInt32(settings["SvcCancelThreshold"]); // TimeSpan ts = new TimeSpan(threshold, 0, 0, 0); // calculate actual suspend date DateTime dueDate = DateTime.Now.Subtract(ts); // lookup for overdue invoices List <InvoiceItem> items = InvoiceController.GetInvoicesItemsOverdue(SecurityContext.User.UserId, dueDate); // TRACE TaskManager.Write("Cancel overdue services"); TaskManager.WriteParameter("Items found", items.Count); // foreach (InvoiceItem item in items) { try { TaskManager.Write("Cancelling service"); // cancelling GenericSvcResult result = CancelService(item.ServiceId, true); // LOG ERROR if (!result.Succeed) { TaskManager.WriteError(result.Error); if (!String.IsNullOrEmpty(result.ErrorCode)) { TaskManager.WriteParameter("Error code", result.ErrorCode); } TaskManager.WriteParameter("Result code", result.ResultCode); // go to next item continue; } // TaskManager.Write("Cancelled"); } catch (Exception ex) { TaskManager.WriteError(ex); } } }
public void RunPaymentQueue() { int resellerId = SecurityContext.User.UserId; // 1. load unpaid invoices List <Invoice> invoices = InvoiceController.GetUnpaidInvoices(resellerId); // TRACE TaskManager.Write("Running payment queue"); TaskManager.WriteParameter("Items found", invoices.Count); // 2. load payment profile for each customer foreach (Invoice invoice in invoices) { try { // load payment profile CheckoutDetails details = StorehouseController.GetPaymentProfileInternally(invoice.ContractId); // if (details != null) { // TRACE TaskManager.Write("Trying to submit payment"); TaskManager.WriteParameter("InvoiceID", invoice.InvoiceId); // 3. submit payment for each invoice if profile exists CheckoutResult result = PaymentGatewayController.CheckOut(invoice.ContractId, invoice.InvoiceId, PaymentMethod.CREDIT_CARD, details); // ERROR if (!result.Succeed) { TaskManager.WriteError("Payment failed"); TaskManager.WriteParameter("Result code", result.StatusCode); continue; } // OK TaskManager.Write("Payment OK"); } } catch (Exception ex) { TaskManager.WriteError(ex, "Payment failed"); } } }
public static int AddCategory(int userId, string categoryName, string categorySku, int parentId, string shortDescription, string fullDescription) { SecurityResult result = StorehouseController.CheckAccountNotDemoAndActive(); // if (!result.Success) { return(result.ResultCode); } // return(EcommerceProvider.AddCategory( ES.SecurityContext.User.UserId, userId, categoryName, categorySku, parentId, shortDescription, fullDescription )); }
public static int SendNewInvoiceNotification(Invoice invoice, List <InvoiceItem> invoiceLines, KeyValueBunch extraArgs) { Contract contract = ContractSystem.ContractController.GetContract(invoice.ContractId); ContractAccount account = ContractSystem.ContractController.GetContractAccountSettings(invoice.ContractId); Dictionary <int, Service> invoiceServices = ServiceController.GetServicesDictionary(invoiceLines); Hashtable items = new Hashtable(); items["Invoice"] = invoice; items["InvoiceLines"] = invoiceLines; items["InvoiceServices"] = invoiceServices; items["Tax"] = StorehouseController.GetTaxation(contract.ResellerId, invoice.TaxationId); items["Customer"] = account; items["IsEmail"] = "1"; if (extraArgs != null) { items["ExtraArgs"] = extraArgs; } return(SendSystemNotification(StoreSettings.NEW_INVOICE, account, items, "HtmlBody", "TextBody")); }
protected static int SendSystemNotification(string settingsName, ContractAccount recipient, Hashtable items, string htmlKeyName, string textKeyName) { // load e-mail template StoreSettings settings = StorehouseController.GetStoreSettings(ES.SecurityContext.User.UserId, settingsName); // bool htmlMail = (recipient[ContractAccount.MAIL_FORMAT] == "HTML"); string email = recipient[ContractAccount.EMAIL]; // string messageBody = htmlMail ? settings[htmlKeyName] : settings[textKeyName]; Template tmp = new Template(messageBody); if (items != null) { foreach (string key in items.Keys) { tmp[key] = items[key]; } } StringWriter writer = new StringWriter(); try { tmp.Evaluate(writer); } catch (ParserException ex) { writer.WriteLine(String.Format("Error in template (Line {0}, Column {1}): {2}", ex.Line, ex.Column, ex.Message)); } // evaluate message body messageBody = writer.ToString(); return(ES.MailHelper.SendMessage(settings["From"], email, settings["CC"], settings["Subject"], messageBody, htmlMail)); }
public static int AddInvoice(string contractId, List <InvoiceItem> invoiceLines, KeyValueBunch extraArgs) { ContractAccount account = ContractSystem.ContractController.GetContractAccountSettings(contractId); // read customer tax Taxation tax = GetCustomerTaxation(contractId, account[ContractAccount.COUNTRY], account[ContractAccount.STATE]); int taxationId = (tax == null) ? -1 : tax.TaxationId; // Calculate invoice amounts decimal totalAmount = 0, subTotalAmount = 0, taxAmount = 0; CalculateInvoiceChargeAmounts(tax, invoiceLines, out totalAmount, out subTotalAmount, out taxAmount); // align svcs suspend date int[] svcs = new int[invoiceLines.Count]; for (int i = 0; i < invoiceLines.Count; i++) { svcs[i] = invoiceLines[i].ServiceId; } DateTime sdateAligned = ServiceController.GetSvcsSuspendDateAligned(svcs, DateTime.Now); // StoreSettings settings = StorehouseController.GetStoreSettings(ES.SecurityContext.User.UserId, StoreSettings.SYSTEM_SETTINGS); // get invoice grace period in days int gracePeriod = Common.Utils.Utils.ParseInt(settings["InvoiceGracePeriod"], 0); // if (gracePeriod < 0) { gracePeriod = 0; } // DateTime created = DateTime.Now; DateTime dueDate = sdateAligned.AddDays(gracePeriod); // return(AddInvoice(contractId, created, dueDate, taxationId, totalAmount, subTotalAmount, taxAmount, invoiceLines, extraArgs)); }
public int AddCustomerPayment(string contractId, int invoiceId, string transactionId, decimal amount, string currency, string methodName, TransactionStatus status) { return(StorehouseController.AddCustomerPayment(contractId, invoiceId, transactionId, amount, currency, methodName, status)); }
public List <Invoice> GetCustomersInvoicesPaged(int userId, bool isReseller, int maximumRows, int startRowIndex) { return(StorehouseController.GetCustomersInvoicesPaged(userId, isReseller, maximumRows, startRowIndex)); }
public int GetCustomersInvoicesCount(int userId, bool isReseller) { return(StorehouseController.GetCustomersInvoicesCount(userId, isReseller)); }
public int ChangeCustomerPaymentStatus(int paymentId, TransactionStatus status) { return(StorehouseController.ChangeCustomerPaymentStatus(paymentId, status)); }
public List <BillingCycle> GetBillingCyclesPaged(int userId, int maximumRows, int startRowIndex) { return(StorehouseController.GetBillingCyclesPaged(userId, maximumRows, startRowIndex)); }
public BillingCycle GetBillingCycle(int userId, int cycleId) { return(StorehouseController.GetBillingCycle(userId, cycleId)); }
public RoutineResult SetServiceSuspendedNotification(int userId, string fromEmail, string ccEmail, string subject, string htmlBody, string textBody) { return(StorehouseController.SetServiceSuspendedNotification(userId, fromEmail, ccEmail, subject, htmlBody, textBody)); }
public StoreSettings GetStoreSettings(int userId, string settingsName) { return(StorehouseController.GetStoreSettings(userId, settingsName)); }
public int UpdateBillingCycle(int userId, int cycleId, string cycleName, string billingPeriod, int periodLength) { return(StorehouseController.UpdateBillingCycle(userId, cycleId, cycleName, billingPeriod, periodLength)); }
public int DeleteBillingCycle(int userId, int cycleId) { return(StorehouseController.DeleteBillingCycle(userId, cycleId)); }
public bool IsSupportedPluginActive(int resellerId, int pluginId) { return(StorehouseController.IsSupportedPluginActive(resellerId, pluginId)); }
public int GetBillingCyclesCount(int userId) { return(StorehouseController.GetBillingCyclesCount(userId)); }
public bool IsInvoiceProcessed(int invoiceId) { return(StorehouseController.IsInvoiceProcessed(invoiceId)); }
public int SetStoreSettings(int userId, string settingsName, StoreSettings settings) { return(StorehouseController.SetStoreSettings(userId, settingsName, settings)); }
public int DeleteCustomerPayment(int paymentId) { return(StorehouseController.DeleteCustomerPayment(paymentId)); }