Ejemplo n.º 1
0
        public static string Geturl(ForteOptions createOptions)
        {
            if (string.IsNullOrEmpty(createOptions.Server))
            {
                serverName = "";
                switch (createOptions.Environment.ToString().ToUpper())
                {
                case "LIVE":
                    serverName = "https://api.forte.net/API/v2";
                    break;

                case "SANDBOX":
                    serverName = "https://sandbox.forte.net/API/v2";
                    break;

                default:
                    serverName = "https://sandbox.forte.net/API/v2";
                    break;
                }
            }
            else if ((createOptions.Server.ToLower().IndexOf("http") == 0))
            {
                serverName = createOptions.Server;
            }

            return(serverName);
        }
Ejemplo n.º 2
0
        public ForteCustomerService(ForteOptions createOptions)
        {
            createOptions.Resource = "customers";
            _serverName            = GetServerDetails.Geturl(createOptions);
            _strUser          = createOptions.UserId;
            _strPassword      = createOptions.Password;
            _strAuthAccountID = createOptions.AuthAccountId;
            var urlparam = ParameterBuilder.ApplyAllParameters(createOptions);

            _url = _serverName + urlparam;
        }
Ejemplo n.º 3
0
        public static string ApplyAllParameters(ForteOptions obj)
        {
            if (obj != null)
            {
                newUrl = "";
                foreach (var property in obj.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
                {
                    foreach (var attribute in property.GetCustomAttributes(false))
                    {
                        if (attribute.GetType() != typeof(JsonPropertyAttribute))
                        {
                            continue;
                        }

                        var JsonPropertyAttribute = (JsonPropertyAttribute)attribute;

                        var value = property.GetValue(obj, null);
                        if (value == null)
                        {
                            continue;
                        }
                        if (string.IsNullOrWhiteSpace(value.ToString()))
                        {
                            continue;
                        }

                        switch ((JsonPropertyAttribute.PropertyName).ToLower())
                        {
                        case "account_id":
                            newUrl = newUrl + "/accounts/" + (value.ToString().StartsWith("act_") ? value.ToString() : "act_" + value.ToString());
                            break;

                        case "location_id":
                            newUrl = newUrl + "/locations/" + (value.ToString().StartsWith("loc_") ? value.ToString() : "loc_" + value.ToString());
                            break;

                        case "customer_token":
                            newUrl = newUrl + "/customers/" + (value.ToString().StartsWith("cst_") ? value.ToString() : "cst_" + value.ToString());
                            break;

                        case "address_id":
                            newUrl = newUrl + "/addresses/" + (value.ToString().StartsWith("add_") ? value.ToString() : "add_" + value.ToString());
                            break;

                        case "paymethod_token":
                            newUrl = newUrl + "/paymethods/" + (value.ToString().StartsWith("pmt_") ? value.ToString() : "pmt_" + value.ToString());
                            break;

                        case "transaction_id":
                            newUrl = newUrl + "/transactions/" + (value.ToString().StartsWith("trn_") ? value.ToString() : "trn_" + value.ToString());
                            break;

                        case "schedule_id":
                            newUrl = newUrl + "/schedules/" + (value.ToString().StartsWith("sch_") ? value.ToString() : "sch_" + value.ToString());
                            break;

                        case "schedule_item_id":
                            newUrl = newUrl + "/scheduleitems/" + (value.ToString().StartsWith("sci_") ? value.ToString() : "sci_" + value.ToString());
                            break;

                        case "resource":
                            if (!newUrl.Contains(value.ToString()))
                            {
                                newUrl = newUrl + "/" + value.ToString() + "/";
                            }

                            break;

                        default:
                            break;
                        }
                    }
                }
                return(newUrl);
            }
            else
            {
                return("Error");
            }
        }