Пример #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;
    }
}
Пример #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
    }
}
Пример #3
0
function event_espresso_display_wepay_settings($need_to_reauthorize)
{
    $wepay_settings = get_option('event_espresso_wepay_settings');
    $uri = $_SERVER['REQUEST_URI'];
    $pos = strpos($uri, '&activate_wepay=true');
    if ($pos) {
        $uri = substr("{$uri}", 0, $pos);
    }
    $pos = strpos($uri, '&code');
    if ($pos) {
        $uri = substr("{$uri}", 0, $pos);
    }
    _e('Instructions:');
    ?>
	&nbsp;<a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=instructions"><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
/images/question-frame.png" width="16" height="16" /></a>
	<form method="post" action="<?php 
    echo $uri;
    ?>
#wepay">
		<table width="99%" border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td valign="top"><ul>
						<li>
							<label for="wepay_client_id">
	<?php 
    _e('WePay Client ID', 'event_espresso');
    ?>
							</label>
							<input type="text" name="wepay_client_id" size="35" value="<?php 
    echo $wepay_settings['wepay_client_id'];
    ?>
" />
						</li>
						<li>
							<label for="wepay_client_secret">
	<?php 
    _e('WePay Client Secret', 'event_espresso');
    ?>
							</label>
							<input type="text" name="wepay_client_secret" size="35" value="<?php 
    echo $wepay_settings['wepay_client_secret'];
    ?>
" />
						</li>
						<li>
							<label for="button_url">
	<?php 
    _e('Button Image URL', 'event_espresso');
    ?>
 <a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=button_image"><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
/images/question-frame.png" width="16" height="16" /></a>
							</label>
							<input type="text" name="button_url" size="34" value="<?php 
    echo $wepay_settings['button_url'] == '' ? '' : $wepay_settings['button_url'];
    ?>
" />
							<a href="media-upload.php?post_id=0&amp;type=image&amp;TB_iframe=true&amp;width=640&amp;height=580&amp;rel=button_url" id="add_image" class="thickbox" title="Add an Image"><img src="images/media-button-image.gif" alt="Add an Image"></a> </li>
						<li>
							<label for="account_id">
							<?php 
    _e('Select the Account to Use', 'event_espresso');
    ?>
 <a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=select_account"><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
/images/question-frame.png" width="16" height="16" /></a>
							</label>
							<?php 
    echo select_input('account_id', $wepay_settings['available_accounts'], $wepay_settings['account_id']);
    ?>
							</li>
					</ul></td>
				<td valign="top">
					<ul>
						<li>
							<label for="bypass_payment_page">
							<?php 
    _e('Bypass Payment Overview Page', 'event_espresso');
    ?>
 <a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=bypass_confirmation"><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
/images/question-frame.png" width="16" height="16" /></a>
							</label>
							<?php 
    $values = array(array('id' => 'N', 'text' => __('No', 'event_espresso')), array('id' => 'Y', 'text' => __('Yes', 'event_espresso')));
    echo select_input('bypass_payment_page', $values, $wepay_settings['bypass_payment_page']);
    ?>
							</li>
						<li>
							<label for="use_sandbox">
	<?php 
    _e('Turn on Debugging Using the', 'event_espresso');
    ?>
 <a href="https://developer.wepay.com/devscr?cmd=_home||https://cms.wepay.com/us/cgi-bin/?&amp;cmd=_render-content&amp;content_ID=developer/howto_testing_sandbox||https://cms.wepay.com/us/cgi-bin/?&amp;cmd=_render-content&amp;content_ID=developer/howto_testing_sandbox_get_started" title="WePay Sandbox Login||Sandbox Tutorial||Getting Started with WePay Sandbox" target="_blank"><?php 
    _e('WePay Sandbox', 'event_espresso');
    ?>
</a> <a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=wepay_sandbox_info"><img src="<?php 
    echo EVENT_ESPRESSO_PLUGINFULLURL;
    ?>
/images/question-frame.png" width="16" height="16" /></a>
							</label>
							<input name="use_sandbox" type="checkbox" value="1" <?php 
    echo $wepay_settings['use_sandbox'] ? 'checked="checked"' : '';
    ?>
 />
							<br />
						</li>
						<?php 
    if (espresso_check_ssl() == TRUE || isset($wepay_settings['force_ssl_return']) && $wepay_settings['force_ssl_return'] == 1) {
        ?>
						<li>
							<label for="force_ssl_return">
	<?php 
        _e('Force HTTPS on Return URL', 'event_espresso');
        ?>
								<a class="thickbox" href="#TB_inline?height=300&width=400&inlineId=force_ssl_return"><img src="<?php 
        echo EVENT_ESPRESSO_PLUGINFULLURL;
        ?>
/images/question-frame.png" width="16" height="16" /></a>
							</label>
							<input name="force_ssl_return" type="checkbox" value="1" <?php 
        echo $wepay_settings['force_ssl_return'] ? 'checked="checked"' : '';
        ?>
 /></li>
							<?php 
    }
    ?>
						<li>
							<?php 
    _e('Current Button Image', 'event_espresso');
    ?>
							<br />
	<?php 
    echo $wepay_settings['button_url'] == '' ? '<img src="' . $button_url . '" />' : '<img src="' . $wepay_settings['button_url'] . '" />';
    ?>
</li>
					</ul>
				</td>
			</tr>
		</table>
		<p>
			<input type="hidden" name="update_wepay" value="update_wepay">
			<input class="button-primary" type="submit" name="Submit" value="<?php 
    _e('Update WePay Settings', 'event_espresso');
    ?>
" id="save_wepay_settings" />
		</p>
	</form>
	<?php 
    if ($need_to_reauthorize) {
        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']);
        }
        $scope = Espresso_Wepay::$all_scopes;
        $redirect_uri = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
        set_transient('espresso_wepay_redirect_uri', $redirect_uri, 60 * 60);
        $uri = Espresso_Wepay::getAuthorizationUri($scope, $redirect_uri);
        ?>
			<a class="button-primary" href='<?php 
        echo $uri;
        ?>
'><?php 
        _e('Authorize Application', 'event_espresso');
        ?>
</a>
	<?php 
    }
    ?>
	<div id="wepay_sandbox_info" style="display:none">
		<h2><?php 
    _e('WePay Sandbox', 'event_espresso');
    ?>
</h2>
		<p><?php 
    _e('In addition to using the WePay Sandbox feature. The debugging feature will also output the form variables to the payment page, send an email to the admin that contains the all WePay variables.', 'event_espresso');
    ?>
</p>
		<hr />
		<p><?php 
    _e('The WePay Sandbox is a testing environment that is a duplicate of the live WePay site, except that no real money changes hands. The Sandbox allows you to test your entire integration before submitting transactions to the live WePay environment. Create and manage test accounts, and view emails and API credentials for those test accounts.', 'event_espresso');
    ?>
</p>
	</div>
	<div id="instructions" style="display:none">
		<h2><?php 
    _e('WePay Instructions', 'event_espresso');
    ?>
</h2>
	<?php 
    _e('To use WePay, follow these steps:');
    ?>
		<ol>
			<li>
	<?php 
    _e('At WePay.com (or stage.wepay.com for sandbox) sign up as a user and add an account to your user.');
    ?>
			</li>
			<li>
	<?php 
    _e('Register your instance of Event Espresso as an application in your WePay user profile.');
    ?>
			</li>
			<li>
	<?php 
    _e('Copy your client id and client secret from your application profile and paste them here.');
    ?>
			</li>
			<li>
	<?php 
    _e('Anytime you change your id and secret on this page and update your WePay settings, you will see a button to authorize your application.');
    ?>
			</li>
			<li>
	<?php 
    _e('Once your application is authorized, you will be able to select from your available accounts, and update your WePay settings.');
    ?>
			</li>
		</ol>
	</div>
	<div id="select_account" style="display: none">
		<h2><?php 
    _e('WePay Account', 'event_espresso');
    ?>
</h2>
		<p><?php 
    _e('The name of the account you want to use with Event Espresso.', 'event_espresso');
    ?>
</p>
	</div>
	<?php 
}