<?php
if(!defined('ABSPATH')){
    exit; // Exit if accessed directly
}
?>

<form method="post" action="options.php" id="" class="egps_paypal_options">

<?php settings_fields( 'egps_paypal_data' ); ?>
<?php do_settings_sections( 'egps_paypal_data' ); ?>

<h3>PayPal API settings</h3>

    <p>
        To sell your photos and get paid on PayPal for them, you have to connect your page to PayPal via API.
        Follow the steps bellow, to generate a token for the API.
        <br>You can find step-by-step instruction in the HELP menu.
    </p>

    <?php
        if( !Egps::egps_chk_lic() ){ 
            echo '<div class="btn btn-danger">Please insert a valid license key to sell photos.</div>';
        }
    ?>
    
    <table class="form-table" role="presentation">
        <tbody>
        <tr>
            <th scope="row">Sandbox (test) mode</th>
            <td>
                <div class="">

                    <div class="custom-control custom-switch">
                        <input 
                            type="checkbox" 
                            class="custom-control-input" 
                            id="customSwitch1" 
                            name="egps_paypal_options[paypal_sandbox]"
                            <?php 
                                $pp_sandboxmode = (EGPS_PP_SANDBOX == "on") ? "checked" : ""; 
                                echo esc_html($pp_sandboxmode);
                            ?>
                            >
                        <label class="custom-control-label" for="customSwitch1">Turn ON or OFF PayPal Sandbox (test) mode</label>
                    </div>

                </div>
            </td>
        </tr>
        <tr>
            <th scope="row">PayPal Client ID</th>
            <td>
                <div class="">
                    Enter your PayPal Client ID. You can get / create one from PayPal's 
                    <a href="https://developer.paypal.com/developer/applications/" target="_blank">API Manager</a>.
                    
                    <br><input 
                        type="text" 
                        class="egps_admin_fields_700 egps_remove_space" 
                        name="egps_paypal_options[paypal_client_id]" 
                        value="<?php echo esc_html(EGPS_PP_CLIENT); ?>">
                    
                </div><!-- section -->
            </td>
        </tr>
        <tr>
            <th scope="row">PayPal Client Secret</th>
            <td>
                <div class="">
                    Enter your PayPal Client Secret.
                    
                    <br><input 
                        type="text" 
                        class="egps_admin_fields_700 egps_remove_space" 
                        name="egps_paypal_options[paypal_client_secret]" 
                        value="<?php echo esc_html(EGPS_PP_SECRET); ?>">
                    
                </div><!-- photonic-section -->
            </td>
        </tr>
        <tr><td></td><td>
        <?php
            if(EGPS_PP_ACCESS_TOKEN == "" && EGPS_PP_SECRET != ""){
            ?>
                <div class="">
                    You first have to get an access token.<br>

                    <a 
                        class="button button-primary" 
                        href="<?php echo esc_html(site_url()) . "/wp-admin/admin.php?page=easy-photo-sell_settings&tab=paypal&getpptoken=1"; ?>"
                    >Step 1: Get PayPal token</a>

                </div>
                <div class="">
                    <br>Next, you have to save the form, with the token string.<br>
                </div>
            <?php
            }else if(EGPS_PP_ACCESS_TOKEN != ""){
                echo '<p class="notice notice-success">You already have a PayPal access token. </p>';
            }else{
                echo '<p class="notice notice-warning">You have to save credentials to obtain PayPal access access token. </p>';
            }

        ?>
        </td></tr>
        <tr>
            <th scope="row">PayPal Token</th>
            <td>
                <div class="">
                    To able to use PayPal payment method in the webshop, you have to get a valid token saved here. 
                    <br>
                    <?php

                    echo '<input 
                        type="text" 
                        class="egps_admin_fields_700 egps_remove_space" 
                        name="egps_paypal_options[paypal_access_token]" 
                        value="' . esc_html(EGPS_PP_ACCESS_TOKEN) . '">';
                                        
                    ?>
                </div><!-- /section -->
            </td>
        </tr>
        <tr>
        <td>  
        </td></tr>
        </tbody>
    </table>

    <?php submit_button(); ?>

</form>


