IDEAL

“;

$rtlo=111735;
$description=”Donatie transactie ICCW”;
//$amount=100;
$reporturl=”http://www.moskeewoerden.nl/public/ideal/”;
$returnurl=”http://www.moskeewoerden.nl/public/ideal/”;

// Bank has been selected, Now we start the transaction
if( isset ($_GET[‘bank’]) && $_GET[‘bank’]<>“” ){
$amount=$_GET[‘amount’]*100;
$url = StartTransaction($rtlo, $_GET[‘bank’], $description, $amount, $returnurl, $reporturl);
// echo “..”.$url.”
“;
echo ‘‘;
exit;

}

// The returnurl is called, now we check the transaction status
if( isset($_GET[‘ec’]) && isset($_GET[’trxid’])){
// 000000 OK means Status is successful. We deliver the product
if( ($status = CheckReturnurl( $rtlo, $_GET[’trxid’] )) == “000000 OK” ){
// Update the orderinfo to success
// Echo( “Uw donatie is succesvol overgemaakt…. Bedankt hiervoor!!”);

Echo (“Bedankt voor uw donatie!
“);
Echo(“We hebben uw donatie ontvangen! Moge Allah u rijkelijk belonen voor uw bijdrage aan Moskee Woerden.

“);
//exit;
}
//In all other cases do not delever(yet)
// Update the orderinfo to failed
else echo( “Banktransactie is helaas mislukt, Probeer u het nogmaals! [Status: “.$status. ” ]
” );
}

// The reporturl is called from the Targetpay server
if ( isset($_POST[‘rtlo’])&&isset($_POST[’trxid’])&& isset($_POST[‘status’])) {
HandleReporturl($_POST[‘rtlo’], $_POST[’trxid’], $_POST[‘status’] );
}

// Start with the bank selection
SelectBank();

// paragraph 2: Bank selection
function SelectBank(){
$url=”https://www.targetpay.com/ideal/getissuers.php”;
$strResponse = httpGetRequest($url);
// echo “strRsponse=”.$strResponse;
echo “

We zijn volop bezig met de voorbereidingen van de bouw van een nieuwe moskee. Alle hulp is daarbij hard nodig. Via Ideal kunt u direct via uw bank op een veilige manier een donatie doen.

“;

echo “

“;
Echo “

Bedrag: €

“;

echo “

Bank:

“;
echo “

“;
// echo ““;

}

// Paragraph 3. Request redirect URL to the bank
function StartTransaction( $rtlo, $bank, $description, $amount, $returnurl, $reporturl){
$url= “https://www.targetpay.com/ideal/start?”.
“rtlo=”.$rtlo.
“&bank=”.$bank.
“&description=”.urlencode($description).
“&amount=”.$amount.
“&language=nl”.
“&returnurl=”.urlencode($returnurl).
“&reporturl=”.urlencode($reporturl);

$strResponse = httpGetRequest($url);

$aResponse = explode(‘|’, $strResponse );
// Bad response
if ( !isset ( $aResponse[1] ) ) die(‘Error’ . $aResponse[0] );

$responsetype = explode ( ‘ ‘, $aResponse[0] );

$trxid = $responsetype[1];
// You may add the trxid to your orderinfo here

if( $responsetype[0] == “000000” ) return $aResponse[1];
else die($aResponse[0]);
}

// Paragraph 5. Request status in returnurl
function CheckReturnurl($rtlo, $trxid){
$once=1;
$test=0; // Set to 1 for testing as described in paragraph 1.3
$url= “https://www.targetpay.com/ideal/check?”.
“rtlo=”.$rtlo.
“&trxid=”.$trxid.
“&once=”.$once.
“&test=”.$test;
return httpGetRequest($url);
}
// Handler for the reporturl.
// Update your your orderstatus and deliver the product if $status = “000000 OK”
function HandleReporturl($rtlo, $trxid, $status ){
if( substr($_SERVER[‘REMOTE_ADDR’],0,10) == “89.184.168” ){
// Update your orderinfo status here.
//……

//reporturl should return OK to TargetPay.com
die( “OK” );
}else{
die(“IP address not correct… This call is not from Targetpay”);
}
}

/**
* Defines the function used to initial the cURL library.
*
* @param string $url To URL to which the request is being made
* @return string $response The response, if available; otherwise, null
*/
function curl( $url ) {

$curl = curl_init( $url );

curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_HEADER, 0 );
curl_setopt( $curl, CURLOPT_USERAGENT, ” );
curl_setopt( $curl, CURLOPT_TIMEOUT, 10 );

$response = curl_exec( $curl );
if( 0 !== curl_errno( $curl ) || 200 !== curl_getinfo( $curl, CURLINFO_HTTP_CODE ) ) {
$response = null;
} // end if
curl_close( $curl );

return $response;

} // end curl

/**
* Retrieves the response from the specified URL using one of PHP’s outbound request facilities.
*
* @params $url The URL of the feed to retrieve.
* @returns The response from the URL; null if empty.
*/
function httpGetRequest( $url )
{
$response = null;

// First, we try to use wp_remote_get
$response = wp_remote_get( $url );
if( is_wp_error( $response ) ) {

// If that doesn’t work, then we’ll try file_get_contents
$response = file_get_contents( $url );
if( false == $response ) {
// And if that doesn’t work, then we’ll try curl
$response = $this->curl( $url );
if( null == $response ) {
$response = 0;
} // end if/else

} // end if

} // end if

// If the response is an array, it’s coming from wp_remote_get,
// so we just want to capture to the body index for json_decode.
if( is_array( $response ) ) {
$response = $response[‘body’];
} // end if/else

return $response;

} // end get_response
?>