Пример #1
0
function event_espresso_wepay_payment_settings()
{
    global $espresso_premium, $active_gateways;
    if (!$espresso_premium) {
        return;
    }
    require_once dirname(__FILE__) . "/Wepay.php";
    $wepay_settings = get_option('event_espresso_wepay_settings');
    $need_to_reauthorize = false;
    if (isset($_POST['update_wepay'])) {
        if ($wepay_settings['wepay_client_id'] != $_POST['wepay_client_id'] || $wepay_settings['wepay_client_secret'] != $_POST['wepay_client_secret']) {
            $wepay_settings['wepay_client_id'] = $_POST['wepay_client_id'];
            $wepay_settings['wepay_client_secret'] = $_POST['wepay_client_secret'];
            $need_to_reauthorize = true;
        }
        $wepay_settings['use_sandbox'] = empty($_POST['use_sandbox']) ? false : true;
        $wepay_settings['force_ssl_return'] = empty($_POST['force_ssl_return']) ? false : true;
        $wepay_settings['bypass_payment_page'] = $_POST['bypass_payment_page'];
        $wepay_settings['button_url'] = $_POST['button_url'];
        $wepay_settings['account_id'] = $_POST['account_id'];
        update_option('event_espresso_wepay_settings', $wepay_settings);
        echo '<div id="message" class="updated fade"><p><strong>' . __('WePay settings saved.', 'event_espresso') . '</strong></p></div>';
    }
    if (isset($_GET['code'])) {
        if ($wepay_settings['use_sandbox']) {
            Wepay::useStaging($wepay_settings['wepay_client_id'], $wepay_settings['wepay_client_secret']);
        } else {
            Wepay::useProduction($wepay_settings['wepay_client_id'], $wepay_settings['wepay_client_secret']);
        }
        $info = Wepay::getToken($_GET['code'], $_SESSION['redirect_uri']);
        if ($info) {
            // Normally you'd integrate this into your existing auth system
            $wepay_settings['access_token'] = $info->access_token;
            $wepay_settings['user_id'] = $info->user_id;
            try {
                $wepay = new Wepay($info->access_token);
                $accounts = $wepay->request('account/find');
                foreach ($accounts as $account) {
                    $available_accounts[] = array('id' => $account->account_id, 'text' => $account->name);
                }
                $wepay_settings['available_accounts'] = $available_accounts;
                $wepay_settings['account_id'] = $available_accounts[0]['id'];
            } catch (WepayException $e) {
                // Something went wrong - normally you would log
                // this and give your user a more informative message
                echo $e->getMessage();
            }
            update_option('event_espresso_wepay_settings', $wepay_settings);
            echo '<div id="message" class="updated fade"><p><strong>' . __('WePay Access Token saved.', 'event_espresso') . '</strong></p></div>';
        } else {
            // Unable to obtain access token
            echo 'Unable to obtain access token from WePay.';
        }
    }
    if (empty($wepay_settings)) {
        if (file_exists(EVENT_ESPRESSO_GATEWAY_DIR . "/wepay/wepay-logo.png")) {
            $button_url = EVENT_ESPRESSO_GATEWAY_URL . "/wepay/wepay-logo.png";
        } else {
            $button_url = EVENT_ESPRESSO_PLUGINFULLURL . "gateways/wepay/wepay-logo.png";
        }
        $wepay_settings['wepay_client_id'] = '';
        $wepay_settings['wepay_client_secret'] = '';
        $wepay_settings['use_sandbox'] = false;
        $wepay_settings['bypass_payment_page'] = 'N';
        $wepay_settings['button_url'] = $button_url;
        $wepay_settings['available_accounts'] = array();
        $wepay_settings['account_id'] = '';
        $wepay_settings['force_ssl_return'] = false;
        if (add_option('event_espresso_wepay_settings', $wepay_settings, '', 'no') == false) {
            update_option('event_espresso_wepay_settings', $wepay_settings);
        }
    }
    //Open or close the postbox div
    if (empty($_REQUEST['deactivate_wepay']) && (!empty($_REQUEST['activate_wepay']) || array_key_exists('wepay', $active_gateways))) {
        $postbox_style = '';
    } else {
        $postbox_style = 'closed';
    }
    ?>
	<a name="wepay" id="wepay"></a>
	<div class="metabox-holder">
		<div class="postbox <?php 
    echo $postbox_style;
    ?>
">
			<div title="Click to toggle" class="handlediv"><br /></div>
			<h3 class="hndle">
				<?php 
    _e('WePay Settings', 'event_espresso');
    ?>
			</h3>
			<div class="inside">
				<div class="padding">
					<?php 
    if (!empty($_REQUEST['activate_wepay'])) {
        $active_gateways['wepay'] = dirname(__FILE__);
        update_option('event_espresso_active_gateways', $active_gateways);
    }
    if (!empty($_REQUEST['deactivate_wepay'])) {
        unset($active_gateways['wepay']);
        update_option('event_espresso_active_gateways', $active_gateways);
    }
    echo '<ul>';
    if (array_key_exists('wepay', $active_gateways)) {
        echo '<li id="deactivate_wepay" style="width:30%;" onclick="location.href=\'' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=payment_gateways&deactivate_wepay=true\';" class="red_alert pointer"><strong>' . __('Deactivate WePay IPN?', 'event_espresso') . '</strong></li>';
        event_espresso_display_wepay_settings($need_to_reauthorize);
    } else {
        echo '<li id="activate_wepay" style="width:30%;" onclick="location.href=\'' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=payment_gateways&activate_wepay=true#wepay\';" class="green_alert pointer"><strong>' . __('Activate WePay IPN?', 'event_espresso') . '</strong></li>';
    }
    echo '</ul>';
    ?>
				</div>
			</div>
		</div>
	</div>
	<?php 
}
Пример #2
0
function event_espresso_wepay_payment_settings()
{
    global $espresso_premium, $active_gateways;
    if (!$espresso_premium) {
        return;
    }
    require_once dirname(__FILE__) . "/Wepay.php";
    $wepay_settings = get_option('event_espresso_wepay_settings');
    if (isset($_POST['update_wepay'])) {
        $wepay_settings['wepay_client_id'] = $_POST['wepay_client_id'];
        $wepay_settings['wepay_client_secret'] = $_POST['wepay_client_secret'];
        $wepay_settings['access_token'] = $_POST['access_token'];
        $wepay_settings['use_sandbox'] = empty($_POST['use_sandbox']) ? false : true;
        $wepay_settings['force_ssl_return'] = empty($_POST['force_ssl_return']) ? false : true;
        $wepay_settings['bypass_payment_page'] = $_POST['bypass_payment_page'];
        $wepay_settings['button_url'] = $_POST['button_url'];
        $wepay_settings['account_id'] = $_POST['account_id'];
        update_option('event_espresso_wepay_settings', $wepay_settings);
        echo '<div id="message" class="updated fade"><p><strong>' . __('WePay settings saved.', 'event_espresso') . '</strong></p></div>';
    }
    if (empty($wepay_settings)) {
        if (file_exists(EVENT_ESPRESSO_GATEWAY_DIR . "/wepay/wepay-logo.png")) {
            $wepay_settings['button_url'] = EVENT_ESPRESSO_GATEWAY_URL . "/wepay/wepay-logo.png";
        } else {
            $wepay_settings['button_url'] = EVENT_ESPRESSO_PLUGINFULLURL . "gateways/wepay/wepay-logo.png";
        }
        $wepay_settings['wepay_client_id'] = '';
        $wepay_settings['wepay_client_secret'] = '';
        $wepay_settings['access_token'] = '';
        $wepay_settings['use_sandbox'] = false;
        $wepay_settings['bypass_payment_page'] = 'N';
        $wepay_settings['account_id'] = '';
        $wepay_settings['force_ssl_return'] = false;
        if (add_option('event_espresso_wepay_settings', $wepay_settings, '', 'no') == false) {
            update_option('event_espresso_wepay_settings', $wepay_settings);
        }
    }
    if (!isset($wepay_settings['button_url']) || !file_exists($wepay_settings['button_url'])) {
        $wepay_settings['button_url'] = EVENT_ESPRESSO_PLUGINFULLURL . "gateways/pay-by-credit-card.png";
    }
    //Open or close the postbox div
    if (empty($_REQUEST['deactivate_wepay']) && (!empty($_REQUEST['activate_wepay']) || array_key_exists('wepay', $active_gateways))) {
        $postbox_style = '';
    } else {
        $postbox_style = 'closed';
    }
    ?>
	<a name="wepay" id="wepay"></a>
	<div class="metabox-holder">
		<div class="postbox <?php 
    echo $postbox_style;
    ?>
">
			<div title="Click to toggle" class="handlediv"><br /></div>
			<h3 class="hndle">
				<?php 
    _e('WePay Settings', 'event_espresso');
    ?>
			</h3>
			<div class="inside">
				<div class="padding">
					<?php 
    if (!empty($_REQUEST['activate_wepay'])) {
        $active_gateways['wepay'] = dirname(__FILE__);
        update_option('event_espresso_active_gateways', $active_gateways);
    }
    if (!empty($_REQUEST['deactivate_wepay'])) {
        unset($active_gateways['wepay']);
        update_option('event_espresso_active_gateways', $active_gateways);
    }
    echo '<ul>';
    if (array_key_exists('wepay', $active_gateways)) {
        echo '<li id="deactivate_wepay" style="width:30%;" onclick="location.href=\'' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=payment_gateways&deactivate_wepay=true\';" class="red_alert pointer"><strong>' . __('Deactivate WePay IPN?', 'event_espresso') . '</strong></li>';
        event_espresso_display_wepay_settings();
    } else {
        echo '<li id="activate_wepay" style="width:30%;" onclick="location.href=\'' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=payment_gateways&activate_wepay=true#wepay\';" class="green_alert pointer"><strong>' . __('Activate WePay IPN?', 'event_espresso') . '</strong></li>';
    }
    echo '</ul>';
    ?>
				</div>
			</div>
		</div>
	</div>
	<?php 
}