I did take a look (and reused some code for the plugin). Lets have a look at the callback here. From the Joomla plugin:
'callback' => JURI::root() . 'administrator'
Now, in general terms:
- Does the callback have to lead directly to the script wich called the authorisation on Mautic?
And, in my case I did actually set it up in a way that the callback redirects to self. From my plugin:
function edd_mautic_listener(){
if ( isset( $_GET['edd-listener'] ) && $_GET['edd-listener'] == 'mautic' ) {
do_action('edd_mautic_pingback');
}
}
add_action( 'init', 'edd_mautic_listener' );
This piece of code makes sure, that when the ?edd-listener=mautic
is added at the end of the URL of wordpress installation, the pingback is going to be processed. The pingback itself calls the authorise function, which is inspired by the Joomla plugin:
function edd_mautic_pingback($reauthorize = false) {
require(plugin_dir_path(__FILE__) . 'lib/eddToMauticApiHelper.php');
$apiHelper = new eddToMauticApiHelper();
$mauticBaseUrl = $apiHelper->getMauticBaseUrl();
$auth = $apiHelper->getMauticAuth($reauthorize);
try
{
if ($auth->validateAccessToken())
{
if ($auth->accessTokenUpdated())
{
$accessTokenData = $auth->getAccessTokenData();
update_option("mautic_options", $accessTokenData);
}
else
{
/** do nothing*/
}
}
}
catch (Exception $e)
{
echo "Exception: " .$e->getMessage();
exit;
/*$app->enqueueMessage($e->getMessage(), 'error');
$this->log($e->getMessage(), JLog::ERROR);*/
}
wp_redirect($apiHelper->getCallback());
}
and the piece where I ask for authorisation is above, vbut to be sure, lets repeat that:
public function getMauticAuth($clearAccessToken = false)
{
$settings = $this->getApiSettings();
if ($clearAccessToken)
{
unset($settings['accessToken']);
unset($settings['accessTokenSecret']);
unset($settings['accessTokenExpires']);
unset($settings['refreshToken']);
unset($_SESSION['OAuth1a']);
unset($_SESSION['OAuth2']);
unset($_SESSION['oauth']);
}
return MauticAuthApiAuth::initiate($settings);
}
As you can guess, the above is taken from Joomla plugin, I decided to use exactly the same approach.
public function getApiSettings()
{
$settings = array(
'baseUrl' => $this->getMauticBaseUrl(),
'version' => $this->mauticOptions['version'],
'clientKey' => $this->mauticOptions['clientKey'],
'clientSecret' => $this->mauticOptions['clientSecret'],
'callback' => "http://mywii.cz/?edd-listener=mautic"
);
if (!empty($this->mauticOptions['access_token']))
{
$settings['accessToken'] = $this->mauticOptions['access_token'];
$settings['accessTokenSecret'] = $this->mauticOptions['access_token_secret'];
$settings['accessTokenExpires'] = $this->mauticOptions['access_token_expires'];
//, $this->mauticOptions['expires']);
$settings['refreshToken'] = $this->mauticOptions['refresh_token'];
}
return $settings;
}
As you can see, I decided to hardcode the callback now. Triple checked, keypair is correct, and both Mautic installation and my plugin have the http://mywii.cz/?edd-listener=mautic
as callback.
Still, I am getting “callback is not valid” error.
Does Mautic have any extra logging options? Somewhere where I could see more reason what went wrong?