Support

Home Forums Event Espresso Premium Custom plugin using AHEE__EED_Thank_You_Page__init_end causes spinning dial icon

Custom plugin using AHEE__EED_Thank_You_Page__init_end causes spinning dial icon

Posted: July 11, 2023 at 8:50 am

Viewing 3 reply threads


Shon Smith

July 11, 2023 at 8:50 am

Hi am building a plugin to send ticket information to a third party after the attendee has completed the registration and completed the payment. Please see below the plugin code:
<?php
/*
Plugin Name: Prometric-gee-xelig
Description: Send eligibility XML information to Prometric
*/

/********************
* Includes
********************/
require_once ‘prometrics-token-generator.php’;

function nwif_send_xml_elig_gee() {
/* STS added for Prometric URL link */

EE_Registry::instance()->load_model(‘Transaction’);
$transaction = EE_Registry::instance()->load_model(‘Transaction’)->get_transaction_from_reg_url_link();

$registrations = $transaction->registrations();
foreach ($registrations as $registration) {
$full_name = $registration->attendee()->full_name(true);
$name_parts = explode(‘ ‘, $full_name);
$first_name = $name_parts[0];
$last_name = $name_parts[1];
$last_name =’zzdemo’;
ob_start();
$registration->e(‘REG_code’);
$reg_code = ob_get_clean();
$ticket_name .= $registration->ticket()->name() . ‘ ‘;
$ticket_name_parts = explode(‘ ‘, $ticket_name);
$ticket = $ticket_name_parts[0];

}

// Retrieve Prometrics token
$token = prometrics_get_token();

// Check if the token retrieval was successful
if (substr($token, 0, 5) === ‘Error’) {
// Handle the error
echo $token;
return;
}

// Prometrics API endpoint
$url = ‘https://gee.prometric.com/GEEWEBSR/geesr.asmx/SubmitXELIG&#8217;;

// XML data
$xml = ‘<XELIG version=”2.00″>
<client>ABMRS</client>
<eligibility>
<action>add</action>
<demographics>
<firstname>’ . $first_name . ‘</firstname>
<lastname>’ . $last_name . ‘</lastname>
</demographics>
<ids>
<candidateid1>’ . $reg_code . ‘</candidateid1>
</ids>
<events>
<event>
<exam programid=”ABMRS” examid=”‘ . $ticket . ‘” />
<eligibilityid1>’ . $reg_code . ‘</eligibilityid1>
</event>
</events>
</eligibility>
</XELIG>’;

echo $xml;

// Encode XML data as Base64
$xml_base64 = base64_encode($xml);

// URL parameters
$params = array(
‘strToken’ => $token,
‘strXELIG’ => $xml_base64,
);

// Build the URL with parameters
$url .= ‘?’ . http_build_query($params);

// Create a new cURL resource
$ch = curl_init();

// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Execute cURL request
$response = curl_exec($ch);

// Check for errors
if ($response === false) {
// Handle the error
$error = curl_error($ch);
echo ‘Error: ‘ . $error;
} else {
// Process the response
// …
echo ‘Response: ‘ . $response;
}

// Close cURL resource
curl_close($ch);
}

// Hook the function to the appropriate action
add_action(‘AHEE__EED_Thank_You_Page__init_end’, ‘nwif_send_xml_elig_gee’, 10, 3);

The only problem that I have is when this plugin is activated, the details at the bottom of the thank you page, Transaction, Registration, etc do not show up and I get the spinning dial icon. When I deactivate my plugin everything works as far as the Transaction, Registration, etc, so I know it is something that I am doing in the plugin. Is there a different AHEE action that I can use that will not cause this result?
Thank you for your time.
Shon


Tony

  • Support Staff

July 11, 2023 at 9:30 am

Hi Shon,

The above plugin echos the response to the page, if the response to the above is being output on the ajax request for the spinning icon then it will cause that response to fail.

Can you post a link to the thank you page of a test registration so I can view this?

Or an event I can register onto without making payment to view it?


Shon Smith

July 13, 2023 at 11:19 am

This reply has been marked as private.


Tony

  • Support Staff

July 14, 2023 at 8:07 am

Ok, so see this: https://monosnap.com/file/LMZuQ6Oe55SBWmLFgckYJNF9FLkxia

Thats being output on the ajax request.

The rest of the response is actually valid but because you are outputting details that Event Espresso has no idea how to deal with it breaks loading those details.

Do you need to echo the response? If so, why?

Viewing 3 reply threads

The support post ‘Custom plugin using AHEE__EED_Thank_You_Page__init_end causes spinning dial icon’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso