Ok, now we need to track the statuses (success, fail and cancelled).
For this we add the record id to every url back to our site:
"SuccessURL":'.json_encode(JURI::getInstance()->toString() . '&poli_return=true&poli_success=true') .'&record_id='.$this->record_id.',
"FailureURL":'.json_encode(JURI::getInstance()->toString() . '&poli_return=true&poli_success=false') .'&record_id='.$this->record_id.',
"CancellationURL":'.json_encode(JURI::getInstance()->toString() . '&poli_return=true&poli_cancel=true') .'&record_id='.$this->record_id.',
"NotificationURL":'.json_encode(JURI::getInstance()->toString() . '&poli_return=true&poli_notification=true') .'&record_id='.$this->record_id.'
Then in your form add a hidden input field called "status" (name and title, lowercase).
Then in form => advanced => more options => form pieces => before form => click "custom" and add this (make sure to add your auth code here, too):
if( JRequest::getVar('poli_return', '') == 'true' ){
if(JRequest::getVar('poli_success', '') == 'true'){
echo 'Your payment has been succeeded!';
}
else if(JRequest::getVar('poli_success', '') == 'false'){
echo 'Your payment has failed';
}
else if(JRequest::getVar('poli_cancel', '') == 'true'){
echo 'Your have cancelled the payment';
}
else if(JRequest::getVar('poli_notification', '') == 'true'){
// here we are receiving and storing the nudge
$token = JRequest::getVar('token','');
if($token != ''){
$auth = base64_encode('S61xxxxx:AuthCode1234');
$header = array();
$header[] = 'Authorization: Basic '.$auth;
$ch = curl_init("https://poliapi.apac.paywithpoli.com/api/v2/Transaction/GetTransaction?token=".urlencode($token));
//See the cURL documentation for more information: http://curl.haxx.se/docs/sslcerts.html
//We recommend using this bundle: https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt
//curl_setopt( $ch, CURLOPT_CAINFO, "ca-bundle.crt");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt( $ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_POST, 0);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 0);
//curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
ob_start();
curl_exec( $ch );
$response = ob_get_contents();
ob_end_clean();
curl_close ($ch);
// updating "status" in the record
$db = JFactory::getDbo();
$db->setQuery("Update #__facileforms_subrecords Set `value` = " . $db->quote($response) . " Where s.`status` And s.record = " . JRequest::getInt('record_id', 0));
$db->execute();
@ob_end_clean();
header("HTTP/1.1 200 OK");
exit;
}
}
}
So what basically happens here is an output for the user when he is transferred back.
But it also stores the final payment conclusion that Poli sends through the notification URL we passed previously in the end submit piece.
Regards,
Markus