<?php

/**

 * 2007-2014 [PagSeguro Internet Ltda.]

 *

 * NOTICE OF LICENSE

 *

 *Licensed under the Apache License, Version 2.0 (the "License");

 *you may not use this file except in compliance with the License.

 *You may obtain a copy of the License at

 *

 *http://www.apache.org/licenses/LICENSE-2.0

 *

 *Unless required by applicable law or agreed to in writing, software

 *distributed under the License is distributed on an "AS IS" BASIS,

 *WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 *See the License for the specific language governing permissions and

 *limitations under the License.

 *

 *  @author    PagSeguro Internet Ltda.

 *  @copyright 2007-2014 PagSeguro Internet Ltda.

 *  @license   http://www.apache.org/licenses/LICENSE-2.0

 */



class PagSeguroConfigWrapper

{



    /**

     * production or sandbox

     */

    const PAGSEGURO_ENV = "sandbox";

    /**

     *

     */

    const PAGSEGURO_EMAIL = "darlanpb@gmail.com";

    /**

     *

     */

    const PAGSEGURO_TOKEN_PRODUCTION = "769FEFABC32C422FBDDC66C4CF8E83EE";

    /**

     *

     */

    const PAGSEGURO_TOKEN_SANDBOX = "9578735FF7B74243B78F7AA1A10CE276";

    /**

     *

     */

    const PAGSEGURO_APP_ID_PRODUCTION = "meupregao";

    /**

     *

     */

    const PAGSEGURO_APP_ID_SANDBOX = "app7726981930";

    /**

     *

     */

    const PAGSEGURO_APP_KEY_PRODUCTION = "D88477DCC9C9A044442CCF9A2F06881E";

    /**

     *

     */

    const PAGSEGURO_APP_KEY_SANDBOX = "C934F3180F0F96CAA46F7FA0A8F21212";

    /**

     * UTF-8, ISO-8859-1

     */

    const PAGSEGURO_CHARSET = "UTF-8";

    /**

     *

     */

    const PAGSEGURO_LOG_ACTIVE = false;

    /**

     * Informe o path completo (relativo ao path da lib) para o arquivo, ex.: ../PagSeguroLibrary/logs.txt

     */

    const PAGSEGURO_LOG_LOCATION = "";



    /**

     * @return array

     */

    public static function getConfig()

    {

        $PagSeguroConfig = array();



        $PagSeguroConfig = array_merge_recursive(

            self::getEnvironment(),

            self::getCredentials(),

            self::getApplicationEncoding(),

            self::getLogConfig()

        );



        return $PagSeguroConfig;

    }



    /**

     * @return mixed

     */

    private static function getEnvironment()

    {

        $PagSeguroConfig['environment'] = getenv('PAGSEGURO_ENV') ?: self::PAGSEGURO_ENV;



        return $PagSeguroConfig;

    }



    /**

     * @return mixed

     */

    private static function getCredentials()

    {

        $PagSeguroConfig['credentials'] = array();

        $PagSeguroConfig['credentials']['email'] = getenv('PAGSEGURO_EMAIL')

            ?: self::PAGSEGURO_EMAIL;

        $PagSeguroConfig['credentials']['token']['production'] = getenv('PAGSEGURO_TOKEN_PRODUCTION')

            ?: self::PAGSEGURO_TOKEN_PRODUCTION;

        $PagSeguroConfig['credentials']['token']['sandbox'] = getenv('PAGSEGURO_TOKEN_SANDBOX')

            ?: self::PAGSEGURO_TOKEN_SANDBOX;

        $PagSeguroConfig['credentials']['appId']['production'] = getenv('PAGSEGURO_APP_ID_PRODUCTION')

            ?: self::PAGSEGURO_APP_ID_PRODUCTION;

        $PagSeguroConfig['credentials']['appId']['sandbox'] = getenv('PAGSEGURO_APP_ID_SANDBOX')

            ?: self::PAGSEGURO_APP_ID_SANDBOX;

        $PagSeguroConfig['credentials']['appKey']['production'] = getenv('PAGSEGURO_APP_KEY_PRODUCTION')

            ?: self::PAGSEGURO_APP_KEY_PRODUCTION;

        $PagSeguroConfig['credentials']['appKey']['sandbox'] = getenv('PAGSEGURO_APP_KEY_SANDBOX')

            ?: self::PAGSEGURO_APP_KEY_SANDBOX;



        return $PagSeguroConfig;

    }



    /**

     * @return mixed

     */

    private static function getApplicationEncoding()

    {

        $PagSeguroConfig['application'] = array();

        $PagSeguroConfig['application']['charset'] = ( getenv('PAGSEGURO_CHARSET')

            && ( getenv('PAGSEGURO_CHARSET') == "UTF-8" || getenv('PAGSEGURO_CHARSET') == "ISO-8859-1") )

            ?: self::PAGSEGURO_CHARSET;



        return $PagSeguroConfig;

    }



    /**

     * @return mixed

     */

    private static function getLogConfig()

    {

        $PagSeguroConfig['log'] = array();

        $PagSeguroConfig['log']['active'] = ( getenv('PAGSEGURO_LOG_ACTIVE')

            && getenv('PAGSEGURO_LOG_ACTIVE') == 'true' ) ?: self::PAGSEGURO_LOG_ACTIVE;

        $PagSeguroConfig['log']['fileLocation'] = getenv('PAGSEGURO_LOG_LOCATION')

            ?: self::PAGSEGURO_LOG_LOCATION;



        return $PagSeguroConfig;

    }

}

