Nu loop ik alleen echt compleet vast met 3.3.1 en via de ticket support hulp vragen krijg je als reactie dat je maar iemand moet inhuren om het te laten doen. Beetje raar dus....!
Daarom hoop ik, dat iemand hier ervaring heeft met ideal 3.3.1 en weet waar onderstaande code allicht mis gaat of anders mij op weg kan helpen met voorbeeld code in PHP
Ik gebruik voor een directory request:
Code: Selecteer alles
<?
class idealRequest331 {
private $privateKey;
private $privateKeyFile;
private $privateCertFile;
private $privateCert;
private $publicKeyFile;
private $sMerchantId;
private $sSubId;
private $privateFingerprint;
private $TestMode = false;
private $URL;
private $CRLF = "\r\n";
function __construct() {
$this->sMerchantId = '***';
$this->sSubId = '***';
$this->URL = 'ssl://ideal' . ($this->TestMode ? 'test' : '') . '.rabobank.nl:443/ideal/iDealv3';
$this->timeStamp = gmdate('Y-m-d') . 'T' . gmdate('H:i:s') . '.000Z';
$this->privateKeyFile = 'ssl/private.key';
$this->privateCertFile = 'ssl/private.cer';
$this->publicKeyFile = 'ssl/rabobank.cer';
$fh = fopen($this->privateKeyFile,'r');
$this->privateKey = openssl_get_privatekey(fread($fh,8192),'****');
fclose($fh);
$fh = fopen($this->privateCertFile,'r');
$this->privateCert = openssl_x509_read(fread($fh,8192));
fclose($fh);
$this->privateFingerprint = $this->strToHex(sha1(base64_decode(str_replace('-----END CERTIFICATE-----', '', str_replace('-----BEGIN CERTIFICATE-----', '', $this->privateCert)))));
}
function strToHex($string) {
$hex='';
for ($i=0; $i < strlen($string); $i++)
{
$hex .= dechex(ord($string[$i]));
}
return $hex;
}
private function escapeXml($string) {
return utf8_encode(str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $string));
}
function postToHost($data, $timeout = 30) {
$idx = strrpos($this->URL, ':');
$host = substr($this->URL, 0, $idx);
$this->URL = substr($this->URL, $idx + 1);
$idx = strpos($this->URL, '/');
$port = substr($this->URL, 0, $idx);
$path = substr($this->URL, $idx);
$fsp = fsockopen($host, $port, $errno, $errstr, $timeout);
if($fsp) {
fputs($fsp, 'POST ' . $path . ' HTTP/1.0' . $this->CRLF);
fputs($fsp, 'Host: ' . substr($host, 6) . $this->CRLF);
fputs($fsp, 'Accept: text/html' . $this->CRLF);
fputs($fsp, 'Accept: charset=ISO-8859-1' . $this->CRLF);
fputs($fsp, 'Content-Length:' . strlen($data) . $this->CRLF);
fputs($fsp, 'Content-Type: text/html; charset=ISO-8859-1' . $this->CRLF . $this->CRLF);
fputs($fsp, $data, strlen($data));
while(!feof($fsp)) {
$res .= @fgets($fsp, 128);
}
fclose($fsp);
}
else $this->setError('Error while connecting to ' . $__url, false, __FILE__, __LINE__);
return $res;
}
function DirectoryRequest() {
$sXmlMessageBeforeDigest = '<?xml version="1.0" encoding="UTF-8" ?>' . $this->CRLF
. '<DirectoryReq xmlns="http://www.idealdesk.com/ideal/messages/mer-acq/3.3.1" version="3.3.1">' . $this->CRLF
. '<createDateTimestamp>' . $this->escapeXml($this->timeStamp) . '</createDateTimestamp>' . $this->CRLF
. '<Merchant>' . $this->CRLF
. '<merchantID>' . $this->escapeXml($this->sMerchantId) . '</merchantID>' . $this->CRLF
. '<subID>' . $this->escapeXml($this->sSubId) . '</subID>' . $this->CRLF
. '</Merchant>' . $this->CRLF
. '</DirectoryReq>';
$dom = new DOMDocument();
$dom->LoadXML($sXmlMessageBeforeDigest);
$canonicalized = $dom->C14N();
openssl_private_encrypt(hash("sha256",$canonicalized),$digestValue,$this->privateKey);
$signatureValue = base64_encode($digestValue);
$sXmlMessage = '<?xml version="1.0" encoding="UTF-8" ?>' . $this->CRLF
. '<DirectoryReq xmlns="http://www.idealdesk.com/ideal/messages/mer-acq/3.3.1" version="3.3.1">' . $this->CRLF
. '<createDateTimestamp>' . $this->escapeXml($this->timeStamp) . '</createDateTimestamp>' . $this->CRLF
. '<Merchant>' . $this->CRLF
. '<merchantID>' . $this->escapeXml($this->sMerchantId) . '</merchantID>' . $this->CRLF
. '<subID>' . $this->escapeXml($this->sSubId) . '</subID>' . $this->CRLF
. '</Merchant>' . $this->CRLF
. '<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">' . $this->CRLF
. '<SignedInfo>' . $this->CRLF
. '<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />' . $this->CRLF
. '<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />' . $this->CRLF
. '<Reference URI="">' . $this->CRLF
. '<Transforms>' . $this->CRLF
. '<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>' . $this->CRLF
. '</Transforms>' . $this->CRLF
. '<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />' . $this->CRLF
. '<DigestValue>' . hash("sha256",$canonicalized) . '</DigestValue>' . $this->CRLF
. '</Reference>' . $this->CRLF
. '</SignedInfo>' . $this->CRLF
. '<SignatureValue>' . $signatureValue . '</SignatureValue>' . $this->CRLF
. '<KeyInfo>' . $this->CRLF
. '<KeyName>' . $this->privateFingerprint . '</KeyName>' . $this->CRLF
. '</KeyInfo>' . $this->CRLF
. '</Signature>'
. '</DirectoryReq>';
$dom = new DOMDocument();
$dom->LoadXML($sXmlMessage);
$sXmlMessage = $dom->C14N();
//return $sXmlMessage;
return $this->postToHost($sXmlMessage);
}
}
$test = new idealRequest331();
print $test->DirectoryRequest();
Iemand een idee?