function commerce_license_complete_checkout_ajax_callback in Commerce License 7
Ajax callback for the license completion message checkout pane.
Called once every $refresh_rate seconds (2s by default), until the synchronization is marked as successful / failed, or until it timeouts (60s by default).
1 string reference to 'commerce_license_complete_checkout_ajax_callback'
- commerce_license_menu in ./
commerce_license.module - Implements hook_menu().
File
- includes/
commerce_license.checkout_pane.inc, line 126 - Checkout pane callbacks.
Code
function commerce_license_complete_checkout_ajax_callback($license) {
$session_key = 'commerce_license_refresh_start_' . $license->license_id;
$current_time = commerce_license_get_time();
if (!isset($_SESSION[$session_key])) {
$_SESSION[$session_key] = $current_time;
}
// Check if the refresh has timed out.
$refresh_time = $current_time - $_SESSION[$session_key];
$refresh_timeout = variable_get('commerce_license_refresh_timeout', 60);
if ($refresh_time > $refresh_timeout) {
$license->wrapper->sync_status = COMMERCE_LICENSE_SYNC_FAILED;
$license
->save();
// Fire a rules event and a hook, allowing developers to respond
// to a failed synchronization.
rules_invoke_all('commerce_license_synchronize_failed', $license);
}
// Stop the refresh if synchronization has ended (succeeded, failed).
$refresh = TRUE;
$sync_status = $license->wrapper->sync_status
->value();
if ($sync_status != COMMERCE_LICENSE_NEEDS_SYNC) {
unset($_SESSION[$session_key]);
$refresh = FALSE;
}
// Get the message.
$message = commerce_license_checkout_competion_message($license, $refresh);
return array(
'#type' => 'ajax',
'#commands' => array(
ajax_command_replace('#commerce-license-checkout-pane-' . $license->license_id, $message),
),
);
}