package com.braintreegateway;

import java.util.Arrays;

/**
 * Indicates the environment of the Braintree Gateway with which to interact.
 */
public class Environment {
    /** For Braintree internal development. */
    public static final Environment DEVELOPMENT = new Environment("http://localhost:" + developmentPort(), "http://auth.venmo.dev:9292", new String[] {});

    /** For production. */
    public static final Environment PRODUCTION = new Environment("https://api.braintreegateway.com:443", "https://auth.venmo.com", new String[] {"ssl/api_braintreegateway_com.ca.crt"});

    /** For merchant's to use during their development and testing. */
    public static final Environment SANDBOX = new Environment("https://api.sandbox.braintreegateway.com:443", "https://auth.sandbox.venmo.com", new String[] {"ssl/api_braintreegateway_com.ca.crt"});

    public final String baseURL;
    public final String authURL;
    public final String[] certificateFilenames;

    public Environment(String baseURL, String authURL, String[] certificateFilenames) {
        this.baseURL = baseURL;
        this.authURL = authURL;
        this.certificateFilenames = Arrays.copyOf(certificateFilenames, certificateFilenames.length);
    }

    public static String developmentPort() {
        if (System.getenv().get("GATEWAY_PORT") != null) {
            return System.getenv().get("GATEWAY_PORT");
        } else {
            return "3000";
        }
    }
}

@@ -280,25 +280,32 @@
 ent(
-%22http://localhost
+developmentBaseURL() + %22
 :%22 +
@@ -1234,16 +1234,261 @@
 %0A    %7D%0A%0A
+    private static String developmentBaseURL() %7B%0A        if (System.getenv().get(%22GATEWAY_BASE_URL%22) != null) %7B%0A            return System.getenv().get(%22GATEWAY_BASE_URL%22);%0A        %7D else %7B%0A            return %22http://localhost%22;%0A        %7D%0A    %7D%0A%0A
     publ

Make it easier to development against different remote gateways.