Ejemplo n.º 1
0
function espresso_process_wepay_callback($payment_data)
{
    $payment_data['txn_details'] = serialize($_REQUEST);
    $payment_data['txn_type'] = 'WePay';
    $wepay_settings = get_option('event_espresso_wepay_settings');
    include_once 'Wepay.php';
    if ($wepay_settings['use_sandbox']) {
        Espresso_Wepay::useStaging($wepay_settings['wepay_client_id'], $wepay_settings['wepay_client_secret']);
    } else {
        Espresso_Wepay::useProduction($wepay_settings['wepay_client_id'], $wepay_settings['wepay_client_secret']);
    }
    $wepay = new Espresso_Wepay($wepay_settings['access_token']);
    $raw = $wepay->request('checkout', array('checkout_id' => $_REQUEST['checkout_id']));
    if (!empty($raw)) {
        $payment_data['txn_details'] = serialize(get_object_vars($raw));
        $payment_data['txn_id'] = $raw->reference_id;
        $responsecode = $raw->state;
        if ($responsecode == 'cancelled' || $responsecode == 'failed') {
            $payment_data['payment_status'] = 'Incomplete';
            $subject = 'Problem with your WePay payment';
            $body = "WePay has informed us that your payment for " . $payment_data['event_link'] . " has moved to a status of " . $responsecode . ".\n";
            $body .= "We have changed your payment status for the event to 'Incomplete'.\n";
            $body .= "Please look into the cause in your account interface at wepay.com.\nThank You.\n";
            wp_mail($payment_data['email'], $subject, $body);
        }
        return $payment_data;
    }
}
Ejemplo n.º 2
0
function espresso_display_wepay($payment_data)
{
    extract($payment_data);
    // Setup class
    if (empty($event_name)) {
        $event_name = "Event number #" . $event_id;
    }
    include_once 'Wepay.php';
    echo '<!-- Event Espresso WePay Gateway Version ' . Espresso_Wepay::$version . '-->';
    $wepay_settings = get_option('event_espresso_wepay_settings');
    global $org_options;
    if ($wepay_settings['use_sandbox']) {
        Espresso_Wepay::useStaging($wepay_settings['wepay_client_id'], $wepay_settings['wepay_client_secret']);
    } else {
        Espresso_Wepay::useProduction($wepay_settings['wepay_client_id'], $wepay_settings['wepay_client_secret']);
    }
    $quantity = isset($quantity) && $quantity > 0 ? $quantity : espresso_count_attendees_for_registration($attendee_id);
    $fields['account_id'] = $wepay_settings['account_id'];
    $fields['short_description'] = stripslashes_deep($event_name);
    $fields['long_description'] = stripslashes_deep($event_name) . ' | ' . __('Name:', 'event_espresso') . ' ' . stripslashes_deep($fname . ' ' . $lname) . ' | ' . __('Registrant Email:', 'event_espresso') . ' ' . $attendee_email . ' | ' . __('Total Registrants:', 'event_espresso') . ' ' . $quantity;
    $fields['type'] = 'SERVICE';
    $fields['reference_id'] = $attendee_id;
    $fields['amount'] = number_format($event_cost, 2, '.', '');
    $fields['redirect_uri'] = add_query_arg(array('id' => $attendee_id, 'r_id' => $registration_id, 'event_id' => $event_id, 'attendee_action' => 'post_payment', 'form_action' => 'payment', 'type' => 'wepay'), get_permalink($org_options['return_url']));
    $fields['callback_uri'] = add_query_arg(array('id' => $attendee_id, 'r_id' => $registration_id, 'event_id' => $event_id, 'attendee_action' => 'post_payment', 'form_action' => 'payment', 'type' => 'wepay'), get_permalink($org_options['notify_url']));
    //	$fields['redirect_uri'] = $home . '/?page_id=' . $org_options['return_url'] . '&id=' . $attendee_id . '&r_id=' . $registration_id . '&event_id=' . $event_id . '&attendee_action=post_payment&form_action=payment&type=wepay';
    //	$fields['callback_uri'] = $home . '/?page_id=' . $org_options['notify_url'] . '&id=' . $attendee_id . '&r_id=' . $registration_id . '&event_id=' . $event_id . '&attendee_action=post_payment&form_action=payment&type=wepay';
    if ($wepay_settings['force_ssl_return']) {
        $fields['redirect_uri'] = str_replace("http://", "https://", $fields['redirect_uri']);
        $fields['callback_uri'] = str_replace("http://", "https://", $fields['callback_uri']);
    }
    if (empty($wepay_settings['access_token'])) {
        return;
    }
    try {
        $wepay = new Espresso_Wepay($wepay_settings['access_token']);
        $raw = $wepay->request('checkout/create', $fields);
    } catch (Exception $e) {
        printf(__("WePay seems to be misconfigured. Error: %s", "event_espresso"), $e->getMessage());
        return;
    }
    if (empty($raw->checkout_uri)) {
        return;
    }
    $uri = $raw->checkout_uri;
    if ($wepay_settings['bypass_payment_page'] == 'Y') {
        $wepay->submitPayment($uri);
        //Enable auto redirect to payment site
    } else {
        $wepay->submitButton($uri, $wepay_settings['button_url'], 'wepay');
        //Display payment button
        wp_deregister_script('jquery.validate.pack');
    }
    if ($wepay_settings['use_sandbox']) {
        echo '<h3 style="color:#ff0000;" title="Payments will not be processed">' . __('Debug Mode Is Turned On', 'event_espresso') . '</h3>';
        $wepay->dump_fields($fields);
        // for debugging, output a table of all the fields
    }
}
Ejemplo n.º 3
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 (!array_key_exists('access_token', $wepay_settings) || empty($wepay_settings['access_token'])) {
        $need_to_reauthorize = true;
    }
    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'];
            $wepay_settings['access_token'] = '';
            $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']) {
            Espresso_Wepay::useStaging($wepay_settings['wepay_client_id'], $wepay_settings['wepay_client_secret']);
        } else {
            Espresso_Wepay::useProduction($wepay_settings['wepay_client_id'], $wepay_settings['wepay_client_secret']);
        }
        $info = Espresso_Wepay::getToken($_GET['code'], get_transient('espresso_wepay_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 Espresso_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'];
                $need_to_reauthorize = false;
            } 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 
}