コード例 #1
0
        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);
                //
                ES.TaskManager.TaskParameters[SystemTaskParams.PARAM_CONTRACT]      = contract;
                ES.TaskManager.TaskParameters[SystemTaskParams.PARAM_INVOICE]       = invoice;
                ES.TaskManager.TaskParameters[SystemTaskParams.PARAM_INVOICE_LINES] = invoiceLines;
                ES.TaskManager.TaskParameters[SystemTaskParams.PARAM_EXTRA_ARGS]    = extraArgs;
                //
                return(result);
            }
            catch (Exception ex)
            {
                throw ES.TaskManager.WriteError(ex);
            }
            finally
            {
                ES.TaskManager.CompleteTask();
            }
        }
コード例 #2
0
        public GenericSvcResult ActivateInvoiceItem(InvoiceItem item)
        {
            GenericSvcResult svc_result = ActivateService(item.ServiceId, true, true);

            //
            if (svc_result.Succeed)
            {
                InvoiceController.SetInvoiceItemProcessed(item.InvoiceId, item.ItemId);
            }
            //
            return(svc_result);
        }
コード例 #3
0
        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);
                }
            }
        }
コード例 #4
0
 public override void ExecuteTrigger(TriggerEventArgs eventArgs)
 {
     //
     try
     {
         ActivatePaidInvoicesTask activator = new ActivatePaidInvoicesTask();
         // Load invoice items to activate
         List <InvoiceItem> items = InvoiceController.GetCustomerInvoiceItems(Convert.ToInt32(ReferenceId));
         //
         foreach (InvoiceItem item in items)
         {
             try
             {
                 ES.TaskManager.Write("Activating service");
                 // activating
                 GenericSvcResult result = activator.ActivateInvoiceItem(item);
                 // LOG ERROR
                 if (!result.Succeed)
                 {
                     ES.TaskManager.WriteError(result.Error);
                     if (!String.IsNullOrEmpty(result.ErrorCode))
                     {
                         ES.TaskManager.WriteParameter("Error code", result.ErrorCode);
                     }
                     ES.TaskManager.WriteParameter("Result code", result.ResultCode);
                     // go to next item
                     continue;
                 }
                 //
                 ES.TaskManager.Write("Activated");
             }
             catch (Exception ex)
             {
                 ES.TaskManager.WriteError(ex);
             }
         }
     }
     catch (Exception ex)
     {
         TriggerStatus = "ERROR";
         ES.TaskManager.WriteError(ex);
     }
 }
コード例 #5
0
        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");
                }
            }
        }
コード例 #6
0
        public void ActivatePaidServices()
        {
            // load paid invoice items
            List <InvoiceItem> items = InvoiceController.GetInvoicesItemsToActivate(SecurityContext.User.UserId);

            // TRACE
            TaskManager.Write("Activate paid services");
            TaskManager.WriteParameter("Items found", items.Count);
            // iterate
            foreach (InvoiceItem item in items)
            {
                try
                {
                    TaskManager.Write("Activating service");
                    // activating
                    GenericSvcResult result = ActivateInvoiceItem(item);
                    // 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("Activated");
                }
                catch (Exception ex)
                {
                    TaskManager.WriteError(ex);
                }
            }
        }
コード例 #7
0
        public void SuspendOverdueServices()
        {
            // lookup for today's overdue invoices
            List <InvoiceItem> items = InvoiceController.GetInvoicesItemsOverdue(SecurityContext.User.UserId, DateTime.Now);

            // TRACE
            TaskManager.Write("Suspend overdue services");
            TaskManager.WriteParameter("Items found", items.Count);
            //
            foreach (InvoiceItem item in items)
            {
                try
                {
                    TaskManager.Write("Suspending service");
                    // suspending
                    GenericSvcResult result = SuspendService(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("Suspended");
                }
                catch (Exception ex)
                {
                    TaskManager.WriteError(ex);
                }
            }
        }
コード例 #8
0
        public static CheckoutFormParams GetCheckoutFormParams(string contractId, int invoiceId,
                                                               string methodName, KeyValueBunch options)
        {
            Contract contractInfo = ContractSystem.ContractController.GetContract(contractId);

            // Impersonate
            ContractSystem.ContractController.ImpersonateAsContractReseller(contractInfo);
            //
            SupportedPlugin pmPlugin = GetResellerPMPlugin(contractInfo.ResellerId, methodName);

            //
            if (pmPlugin == null)
            {
                throw new Exception("Incorrect payment method has been specified");
            }
            // create instance of plugin
            IInteractivePaymentGatewayProvider provider = (IInteractivePaymentGatewayProvider)
                                                          SystemPluginController.GetSystemPluginInstance(contractInfo, pmPlugin, true);
            //
            Invoice userInvoice = InvoiceController.GetCustomerInvoiceInternally(invoiceId);
            //
            List <InvoiceItem> invoiceLines = InvoiceController.GetCustomerInvoiceItems(invoiceId);
            // load contract account
            ContractAccount account = ContractSystem.ContractController.GetContractAccountSettings(contractId);

            // build form parameters
            FormParameters formParams = new FormParameters();

            // copy reseller id
            formParams[FormParameters.CONTRACT] = userInvoice.ContractId;
            // copy invoice number
            formParams[FormParameters.INVOICE] = userInvoice.InvoiceId.ToString();
            // copy invoice amount
            formParams[FormParameters.AMOUNT] = userInvoice.Total.ToString("0.00");
            // copy invoice tax amount
            formParams[FormParameters.TAX_AMOUNT] = userInvoice.TaxAmount.ToString("0.00");
            // copy invoice currency
            formParams[FormParameters.CURRENCY] = userInvoice.Currency;

            // copy first name
            formParams[FormParameters.FIRST_NAME] = account[ContractAccount.FIRST_NAME];
            // copy last name
            formParams[FormParameters.LAST_NAME] = account[ContractAccount.LAST_NAME];
            // copy email
            formParams[FormParameters.EMAIL] = account[ContractAccount.EMAIL];
            // copy address
            formParams[FormParameters.ADDRESS] = account[ContractAccount.ADDRESS];
            // copy country
            formParams[FormParameters.COUNTRY] = account[ContractAccount.COUNTRY];
            // copy phone number
            formParams[FormParameters.PHONE] = account[ContractAccount.PHONE_NUMBER];
            // copy city
            formParams[FormParameters.CITY] = account[ContractAccount.CITY];
            // copy state
            formParams[FormParameters.STATE] = account[ContractAccount.STATE];
            // copy zip
            formParams[FormParameters.ZIP] = account[ContractAccount.ZIP];
            // copy options if any
            if (options != null)
            {
                foreach (string keyName in options.GetAllKeys())
                {
                    formParams[keyName] = options[keyName];
                }
            }

            // return result
            return(provider.GetCheckoutFormParams(formParams, invoiceLines.ToArray()));
        }
コード例 #9
0
 public void VoidCustomerInvoice(int invoiceId)
 {
     InvoiceController.VoidCustomerInvoice(invoiceId);
 }
コード例 #10
0
 public Invoice GetCustomerInvoice(int invoiceId)
 {
     return(InvoiceController.GetCustomerInvoiceInternally(invoiceId));
 }
コード例 #11
0
 public string GetCustomerInvoiceFormatted(int invoiceId, string cultureName)
 {
     return(InvoiceController.GetCustomerInvoiceFormattedInternally(invoiceId, cultureName));
 }
コード例 #12
0
        /// <summary>
        /// Performs checkout operation
        /// </summary>
        /// <param name="spaceId">Space.</param>
        /// <param name="gatewayId">Gateway.</param>
        /// <param name="invoiceId">Invoice.</param>
        /// <param name="details">Array of parameters.</param>
        /// <returns>Checkout result object.</returns>
        public static CheckoutResult CheckOut(string contractId, int invoiceId, string methodName,
                                              CheckoutDetails details)
        {
            CheckoutResult result = new CheckoutResult();

            try
            {
                Contract contractInfo = ContractSystem.ContractController.GetContract(contractId);
                // impersonate
                ContractSystem.ContractController.ImpersonateAsContractReseller(contractInfo);
                // TRACE
                ES.TaskManager.StartTask(TASK_SOURCE, CHECKOUT_TASK, methodName);
                ES.TaskManager.Write("Start accepting payment for invoice");
                ES.TaskManager.WriteParameter("ContractID", contractId);
                ES.TaskManager.WriteParameter("InvoiceID", invoiceId);

                // get user details
                ContractAccount account = ContractSystem.ContractController.GetContractAccountSettings(contractId);

                // try to load plugin type and throw an exception if type not found
                IPaymentGatewayProvider provider = (IPaymentGatewayProvider)SystemPluginController.GetContractPaymentMethod(
                    contractInfo, methodName);

                // add invoice details
                Invoice invoice = InvoiceController.GetCustomerInvoiceInternally(invoiceId);

                // append information for the provider
                details[CheckoutKeys.ContractNumber] = contractId;
                details[CheckoutKeys.Amount]         = invoice.Total.ToString("0.00");
                details[CheckoutKeys.InvoiceNumber]  = invoice.InvoiceNumber;
                details[CheckoutKeys.Currency]       = invoice.Currency;

                ES.TaskManager.Write("Submitting payment transaction");
                // call checkout routine
                TransactionResult pgResult = provider.SubmitPaymentTransaction(details);
                // log provider response
                SystemPluginController.LogContractPayment(contractInfo, methodName, pgResult.RawResponse);
                // ERROR
                if (!pgResult.Succeed)
                {
                    result.Succeed    = false;
                    result.StatusCode = pgResult.StatusCode;
                    //
                    ES.TaskManager.WriteError("Transaction failed");
                    ES.TaskManager.WriteParameter("StatusCode", result.StatusCode);
                    ES.TaskManager.WriteParameter("RawResponse", pgResult.RawResponse);
                    // EXIT
                    return(result);
                }
                // OK
                ES.TaskManager.Write("Transaction is OK");

                // check whether the transaction already exists
                CustomerPayment tran = StorehouseController.LookupForTransaction(pgResult.TransactionId);

                // lookup for pending transaction
                if (tran == null)
                {
                    // add payment record
                    result.PaymentId = StorehouseController.AddCustomerPayment(contractId, invoice.InvoiceId,
                                                                               pgResult.TransactionId, invoice.Total, invoice.Currency, methodName,
                                                                               pgResult.TransactionStatus);
                    // ERROR
                    if (result.PaymentId < 1)
                    {
                        result.Succeed    = false;
                        result.StatusCode = result.PaymentId.ToString();
                        //
                        ES.TaskManager.WriteError("Could not add customer payment record to the db");
                        ES.TaskManager.WriteParameter("ResultCode", result.StatusCode);
                        // EXIT
                        return(result);
                    }
                }
                // if transaction is already submitted just update it's status
                if (tran != null)
                {
                    StorehouseController.UpdateTransactionStatus(tran.PaymentId, pgResult.TransactionStatus);
                }
                // OK
                result.Succeed = true;
                // ensure user requests to persist his payment details for credit card
                if (details.Persistent && methodName == PaymentMethod.CREDIT_CARD)
                {
                    StorehouseController.SetPaymentProfile(contractId, details);
                }
            }
            catch (Exception ex)
            {
                result.Succeed    = false;
                result.StatusCode = GENERAL_FAILURE;
                //
                ES.TaskManager.WriteError(ex);
            }
            finally
            {
                ES.TaskManager.CompleteTask();
            }
            // EXIT
            return(result);
        }
コード例 #13
0
        public static OrderResult SubmitCustomerOrder(string contractId, OrderItem[] orderItems, KeyValueBunch extraArgs)
        {
            //
            Contract contract = ContractSystem.ContractController.GetContract(contractId);

            // Impersonate
            ContractSystem.ContractController.ImpersonateAsContractReseller(contract);
            //
            OrderResult oResult = new OrderResult();
            // check account
            SecurityResult sResult = StorehouseController.CheckAccountActive();

            //
            if (!sResult.Success)
            {
                //
                oResult.Succeed = false;
                //
                oResult.ResultCode = sResult.ResultCode;
                //
                return(oResult);
            }
            // check order items not empty
            if (orderItems == null || orderItems.Length == 0)
            {
                //
                oResult.Succeed = false;
                //
                oResult.ResultCode = EMPTY_ORDER_ITEMS_CODE;
                //
                return(oResult);
            }
            //
            ES.TaskManager.StartTask("Storefront", "SUBMIT_CUSTOMER_ORDER");

            //
            try
            {
                string currency = StorehouseController.GetBaseCurrency(contract.ResellerId);
                // ordered services
                List <int> orderedSvcs = new List <int>();
                // build services to be ordered
                for (int i = 0; i < orderItems.Length; i++)
                {
                    //
                    OrderItem orderItem = orderItems[i];
                    //
                    int orderedSvcId = 0;
                    //
                    orderItem.ParentSvcId = (orderItem.ParentIndex > -1) ? orderedSvcs[orderItem.ParentIndex] : orderItem.ParentSvcId;
                    // load svc type
                    ProductType svcType = StorehouseController.GetProductType(orderItem.TypeId);
                    //
                    IServiceProvisioning controller = (IServiceProvisioning)Activator.CreateInstance(
                        Type.GetType(svcType.ProvisioningController));
                    // add service
                    orderedSvcId = controller.AddServiceInfo(contractId, currency, orderItem);
                    // check service controller result
                    if (orderedSvcId < 1)
                    {
                        // ROLLBACK HERE
                        StorehouseController.BulkServiceDelete(contractId, orderedSvcs.ToArray());
                        oResult.Succeed    = false;
                        oResult.ResultCode = orderedSvcId;
                        return(oResult);
                        // EXIT
                    }
                    //
                    orderedSvcs.Add(orderedSvcId);
                }
                // build invoice lines
                List <InvoiceItem> invoiceLines = InvoiceController.CalculateInvoiceLinesForServices(orderedSvcs);
                //
                int resultCode = InvoiceController.AddInvoice(contractId, invoiceLines, extraArgs);
                // ERROR
                if (resultCode < 1)
                {
                    // ROLLBACK HERE
                    StorehouseController.BulkServiceDelete(contractId, orderedSvcs.ToArray());
                    oResult.Succeed    = false;
                    oResult.ResultCode = resultCode;
                    return(oResult);
                }
                //
                oResult.OrderInvoice = resultCode;
                //
                oResult.Succeed = true;
            }
            catch (Exception ex)
            {
                //
                oResult.ResultCode = -1;
                //
                oResult.Succeed = false;
                //
                ES.TaskManager.WriteError(ex);
            }
            finally
            {
                //
                ES.TaskManager.CompleteTask();
            }
            //
            return(oResult);
        }
コード例 #14
0
 public static Invoice GetCustomerInvoice(int resellerId, int userId, int invoiceId, string sessionId)
 {
     return(InvoiceController.GetCustomerInvoiceInternally(invoiceId));
 }
コード例 #15
0
        public void InvoiceActiveServices()
        {
            DateTime dateTimeNow = DateTime.Now;
            // load store settings
            StoreSettings settings = StorehouseController.GetStoreSettings(SecurityContext.User.UserId,
                                                                           StoreSettings.SYSTEM_SETTINGS);
            //
            int threshold = Convert.ToInt32(settings["SvcInvoiceThreshold"]);
            // get expiring services today
            List <Service> services = ServiceController.GetServicesToInvoice(SecurityContext.User.UserId,
                                                                             dateTimeNow, threshold);
            // group services by users
            Dictionary <string, List <int> > usersServices = new Dictionary <string, List <int> >();

            // iterate
            foreach (Service service in services)
            {
                if (!usersServices.ContainsKey(service.ContractId))
                {
                    usersServices.Add(service.ContractId, new List <int>());
                }

                usersServices[service.ContractId].Add(service.ServiceId);
            }
            // generate invoice per contract
            foreach (string contractId in usersServices.Keys)
            {
                try
                {
                    TaskManager.Write("Creating invoice");
                    // TRACE
                    Contract        contract = ContractSystem.ContractController.GetContract(contractId);
                    ContractAccount account  = ContractSystem.ContractController.GetContractAccountSettings(contractId);
                    TaskManager.WriteParameter("ContractID", contractId);
                    TaskManager.WriteParameter("Username", account[ContractAccount.USERNAME]);
                    //
                    List <int> userSvcs = usersServices[contractId];
                    // build invoice items
                    List <InvoiceItem> invoiceLines = InvoiceController.CalculateInvoiceLinesForServices(userSvcs);
                    //
                    int resultCode = InvoiceController.AddInvoice(contractId, invoiceLines, null);
                    //
                    if (resultCode < 1)
                    {
                        TaskManager.WriteParameter("ResultCode", resultCode);
                        continue;
                    }
                    //
                    if (ServiceController.SetUsageRecordsClosed(userSvcs.ToArray()) != 0)
                    {
                        TaskManager.WriteWarning("Unable to close usage records automatically");
                    }
                    // TRACE
                    TaskManager.WriteParameter("InvoiceID", resultCode);
                    TaskManager.Write("Succeed");
                }
                catch (Exception ex)
                {
                    TaskManager.WriteError(ex);
                }
            }
        }
コード例 #16
0
        public static int SendNewInvoiceNotification(Invoice invoice)
        {
            List <InvoiceItem> invoiceLines = InvoiceController.GetCustomerInvoiceItems(invoice.InvoiceId);

            return(SendNewInvoiceNotification(invoice, invoiceLines, null));
        }