// Path: src/main/java/com/twocheckout/model/AuthException.java
// public class AuthException {
//     private String errorMsg;
//     private String errorCode;
//     private String httpStatus;
// 
//     public String getMessage() {
//         return errorMsg;
//     }
//     public String getCode() {
//         return errorCode;
//     }
//     public String getStatus() { return httpStatus; }
// }
// 
// Path: src/main/java/com/twocheckout/model/AuthExceptions.java
// public class AuthExceptions {
//     private AuthException exception;
// 
//     public AuthException getAuthExceptions() {
//         return exception;
//     }
// }
// 
// Path: src/main/java/com/twocheckout/model/Error.java
// public class Error {
//     private String message;
//     private String code;
// 
//     public String getMessage() {
//         return message;
//     }
//     public void setMessage(String message) {
//         this.message = message;
//     }
//     public String getCode() {
//         return code;
//     }
//     public void setCode(String code) {
//         this.code = code;
//     }
// }
// 
// Path: src/main/java/com/twocheckout/model/Errors.java
// public class Errors {
//     private Error[] errors;
// 
//     public Error[] getErrors() {
//         return errors;
//     }
// 
//     public void setErrors(Error[] errors) {
//         this.errors = errors;
//     }
// }


import com.google.gson.Gson;
import com.twocheckout.model.AuthException;
import com.twocheckout.model.AuthExceptions;
import com.twocheckout.model.Error;
import com.twocheckout.model.Errors;
import org.apache.http.*;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.params.CookiePolicy;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.ContentType;
import javax.net.ssl.SSLContext;
import java.net.URI;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            String responseBody = EntityUtils.toString(entity);
            httpclient.getConnectionManager().shutdown();
            checkStatusCodeAuth(response, responseBody);

            if (responseBody != null) {
                return responseBody;
            }
        } catch (TwocheckoutException e) {
            throw new TwocheckoutException(e.getMessage(), e.getCode());
        } catch (Exception e) {
            throw new TwocheckoutException(e.getMessage());
        }

        return mainObject;
    }

    public static String addLocationToUrl(String url, List<NameValuePair> params){
        if(!url.endsWith("?"))
            url += "?";

        String paramString = URLEncodedUtils.format(params, "utf-8");
        url += paramString;
        return url;
    }

    private static void checkStatusCodeAdmin(HttpResponse response, String responseBody) throws TwocheckoutException {
        StatusLine status = response.getStatusLine();
        if (status.getStatusCode() != HttpStatus.SC_OK) {

// Path: src/main/java/com/twocheckout/model/AuthException.java
// public class AuthException {
//     private String errorMsg;
//     private String errorCode;
//     private String httpStatus;
// 
//     public String getMessage() {
//         return errorMsg;
//     }
//     public String getCode() {
//         return errorCode;
//     }
//     public String getStatus() { return httpStatus; }
// }
// 
// Path: src/main/java/com/twocheckout/model/AuthExceptions.java
// public class AuthExceptions {
//     private AuthException exception;
// 
//     public AuthException getAuthExceptions() {
//         return exception;
//     }
// }
// 
// Path: src/main/java/com/twocheckout/model/Error.java
// public class Error {
//     private String message;
//     private String code;
// 
//     public String getMessage() {
//         return message;
//     }
//     public void setMessage(String message) {
//         this.message = message;
//     }
//     public String getCode() {
//         return code;
//     }
//     public void setCode(String code) {
//         this.code = code;
//     }
// }
// 
// Path: src/main/java/com/twocheckout/model/Errors.java
// public class Errors {
//     private Error[] errors;
// 
//     public Error[] getErrors() {
//         return errors;
//     }
// 
//     public void setErrors(Error[] errors) {
//         this.errors = errors;
//     }
// }


// Path: src/main/java/com/twocheckout/TwocheckoutApi.java
import com.google.gson.Gson;
import com.twocheckout.model.AuthException;
import com.twocheckout.model.AuthExceptions;
import com.twocheckout.model.Error;
import com.twocheckout.model.Errors;
import org.apache.http.*;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.params.CookiePolicy;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.ContentType;
import javax.net.ssl.SSLContext;
import java.net.URI;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            String responseBody = EntityUtils.toString(entity);
            httpclient.getConnectionManager().shutdown();
            checkStatusCodeAuth(response, responseBody);

            if (responseBody != null) {
                return responseBody;
            }
        } catch (TwocheckoutException e) {
            throw new TwocheckoutException(e.getMessage(), e.getCode());
        } catch (Exception e) {
            throw new TwocheckoutException(e.getMessage());
        }

        return mainObject;
    }

    public static String addLocationToUrl(String url, List<NameValuePair> params){
        if(!url.endsWith("?"))
            url += "?";

        String paramString = URLEncodedUtils.format(params, "utf-8");
        url += paramString;
        return url;
    }

    private static void checkStatusCodeAdmin(HttpResponse response, String responseBody) throws TwocheckoutException {
        StatusLine status = response.getStatusLine();
        if (status.getStatusCode() != HttpStatus.SC_OK) {

            Errors errors = new Gson().fromJson(responseBody, Errors.class);
