Ejemplo n.º 1
0
 public int SetPluginProperties(int userId, int pluginId, KeyValueBunch props)
 {
     return(SystemPluginController.SetPluginProperties(userId, pluginId, props));
 }
Ejemplo n.º 2
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()));
        }
Ejemplo n.º 3
0
 public KeyValueBunch GetPluginProperties(int userId, int pluginId)
 {
     return(SystemPluginController.GetPluginProperties(userId, pluginId));
 }
Ejemplo n.º 4
0
 public List <SupportedPlugin> GetSupportedPluginsByGroup(int userId, string groupName)
 {
     return(SystemPluginController.GetSupportedPluginsByGroup(groupName));
 }
        /// <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);
        }
Ejemplo n.º 6
0
        public GenericSvcResult ActivateService(ProvisioningContext context)
        {
            GenericSvcResult result = new GenericSvcResult();

            // remeber svc state
            SaveObjectState(SERVICE_INFO, context.ServiceInfo);

            // concretize service to be provisioned
            DomainNameSvc domainSvc = (DomainNameSvc)context.ServiceInfo;
            // concretize parent service
            HostingPackageSvc packageSvc = (HostingPackageSvc)context.ParentSvcInfo;

            try
            {
                // LOG INFO
                TaskManager.StartTask(SystemTasks.SOURCE_ECOMMERCE, SystemTasks.SVC_ACTIVATE);
                TaskManager.WriteParameter(CONTRACT_PARAM, domainSvc.ContractId);
                TaskManager.WriteParameter(SVC_PARAM, domainSvc.ServiceName);
                TaskManager.WriteParameter(SVC_ID_PARAM, domainSvc.ServiceId);

                // 0. Do security checks
                if (!CheckOperationClientPermissions(result))
                {
                    // LOG ERROR
                    TaskManager.WriteError(ERROR_CLIENT_OPERATION_PERMISSIONS);
                    TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);
                    // EXIT
                    return(result);
                }
                //
                if (!CheckOperationClientStatus(result))
                {
                    // LOG ERROR
                    TaskManager.WriteError(ERROR_CLIENT_OPERATION_STATUS);
                    TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);
                    // EXIT
                    return(result);
                }

                // error: hosting addon should have parent svc assigned
                if (packageSvc == null || packageSvc.PackageId == 0)
                {
                    result.Succeed = false;
                    //
                    result.Error = PARENT_SVC_NOT_FOUND_MSG;
                    //
                    result.ResultCode = EcommerceErrorCodes.ERROR_PARENT_SVC_NOT_FOUND;

                    // LOG ERROR
                    TaskManager.WriteError(result.Error);
                    TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);

                    // EXIT
                    return(result);
                }

                // first of all - create internal domain in WebsitePanel
                if (domainSvc.Status == ServiceStatus.Ordered)
                {
                    // create domain info object
                    DomainInfo domain = ServerController.GetDomain(domainSvc.Fqdn);
                    //
                    if (domain != null)
                    {
                        domainSvc.DomainId = domain.DomainId;
                    }
                    //
                    if (domain == null)
                    {
                        domain                = new DomainInfo();
                        domain.DomainName     = domainSvc.Fqdn;
                        domain.HostingAllowed = false;
                        domain.PackageId      = packageSvc.PackageId;
                        // add internal domain
                        domainSvc.DomainId = ServerController.AddDomain(domain);
                        // check API result
                        if (domainSvc.DomainId < 1)
                        {
                            // ASSEMBLE ERROR
                            result.Succeed = false;
                            // try to find corresponding error code->error message mapping
                            if (ApiErrorCodesMap.ContainsKey(domainSvc.DomainId))
                            {
                                result.Error = ApiErrorCodesMap[domainSvc.DomainId];
                            }
                            else
                            {
                                result.Error = ERROR_ADD_INTERNAL_DOMAIN;
                            }
                            // copy result code
                            result.ResultCode = domainSvc.DomainId;

                            // LOG ERROR
                            TaskManager.WriteError(result.Error);
                            TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);

                            // EXIT
                            return(result);
                        }
                    }
                }

                // update nameservers only
                if (domainSvc["SPF_ACTION"] == "UPDATE_NS")
                {
                    // remove service here...
                    ServiceController.DeleteCustomerService(domainSvc.ServiceId);
                    //
                    result.Succeed = true;
                    // EXIT
                    return(result);
                }

                // load registrar wrapper
                IDomainRegistrar registrar = (IDomainRegistrar)SystemPluginController.GetSystemPluginInstance(
                    domainSvc.ContractId, domainSvc.PluginId, true);

                #region Commented operations
                // prepare consumer account information

                /*CommandParams cmdParams = PrepeareAccountParams(context.ConsumerInfo);
                 * // copy svc properties
                 * foreach (string keyName in domainSvc.GetAllKeys())
                 *      cmdParams[keyName] = domainSvc[keyName];
                 *
                 * // check registrar requires sub-account to be created
                 * if (registrar.SubAccountRequired)
                 * {
                 *      // 1. Load user's settings
                 *      UserSettings userSettings = LoadUserSettings(context.ConsumerInfo.UserId, registrar.PluginName);
                 *      // 2. Ensure user has account on registrar's side
                 *      if (userSettings.SettingsArray == null || userSettings.SettingsArray.Length == 0)
                 *      {
                 *              // 3. Check account exists
                 *              bool exists = registrar.CheckSubAccountExists(context.ConsumerInfo.Username, context.ConsumerInfo.Email);
                 *              //
                 *              AccountResult accResult = null;
                 *              //
                 *              if (!exists)
                 *              {
                 *                      // 4. Create user account
                 *                      accResult = registrar.CreateSubAccount(cmdParams);
                 *                      // copy keys & values
                 *                      foreach (string keyName in accResult.AllKeys)
                 *                      {
                 *                              userSettings[keyName] = accResult[keyName];
                 *                      }
                 *              }
                 *              else
                 *              {
                 *                      // 4a. Get sub-account info
                 *                      accResult = registrar.GetSubAccount(context.ConsumerInfo.Username,
                 *                              context.ConsumerInfo.Email);
                 *                      //
                 *                      foreach (string keyName in accResult.AllKeys)
                 *                              userSettings[keyName] = accResult[keyName];
                 *              }
                 *              // 5. Update user settings
                 *              int apiResult = UserController.UpdateUserSettings(userSettings);
                 *              // check API result
                 *              if (apiResult < 0)
                 *              {
                 *                      // BUILD ERROR
                 *                      result.Error = ERROR_UPDATE_USR_SETTINGS_MSG;
                 *                      result.Succeed = false;
                 *                      result.ResultCode = apiResult;
                 *                      // LOG ERROR
                 *                      TaskManager.WriteError(result.Error);
                 *                      TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);
                 *                      // ROLLBACK
                 *                      RollbackOperation(domainSvc.DomainId);
                 *                      // EXIT
                 *                      return result;
                 *              }
                 *      }
                 *      // copy registrar-specific data
                 *      foreach (string[] pair in userSettings.SettingsArray)
                 *      {
                 *              // copy 2
                 *              cmdParams[pair[0]] = pair[1];
                 *      }
                 * }*/
                #endregion

                // load NS settings
                PackageSettings nsSettings = PackageController.GetPackageSettings(packageSvc.PackageId, PackageSettings.NAME_SERVERS);
                // build name servers array
                string[] nameServers = null;
                if (!String.IsNullOrEmpty(nsSettings[PackageSettings.NAME_SERVERS]))
                {
                    nameServers = nsSettings[PackageSettings.NAME_SERVERS].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                }

                // register or renew domain
                if (domainSvc.Status == ServiceStatus.Ordered)
                {
                    // try to register domain
                    registrar.RegisterDomain(domainSvc, context.ConsumerInfo, nameServers);
                }
                else
                {
                    // try to renew domain
                    registrar.RenewDomain(domainSvc, context.ConsumerInfo, nameServers);
                }

                // change svc status to active
                domainSvc.Status = ServiceStatus.Active;
                // update service info
                int updResult = UpdateServiceInfo(domainSvc);
                // check update result for errors
                if (updResult < 0)
                {
                    // BUILD ERROR
                    result.ResultCode = updResult;
                    result.Succeed    = false;
                    result.Error      = ERROR_SVC_UPDATE_MSG;
                    // LOG ERROR
                    TaskManager.WriteError(result.Error);
                    TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);
                    // ROLLBACK
                    RollbackOperation(domainSvc.DomainId);
                    // EXIT
                    return(result);
                }
                //
                result.Succeed = true;
                //
                SetOutboundParameters(context);
            }
            catch (Exception ex)
            {
                // LOG ERROR
                TaskManager.WriteError(ex);
                result.Succeed = false;
                // ROLLBACK
                RollbackOperation(result.ResultCode);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
            //
            return(result);
        }
Ejemplo n.º 7
0
 public CheckoutFormParams GetCheckoutFormParams(string contractId, int invoiceId,
                                                 string methodName, KeyValueBunch options)
 {
     return(SystemPluginController.GetCheckoutFormParams(contractId, invoiceId, methodName, options));
 }