Source of file SisowRequest.php
Size: 8,330 Bytes - Last Modified: 2021-12-24T06:50:50+00:00
/var/www/docs.ssmods.com/process/src/code/SisowRequest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 | <?php class SisowRequest { protected static $issuers; protected static $lastcheck; private $response; // Merchant data private $merchantId; private $merchantKey; // Transaction data public $payment; // empty=iDEAL; sofort=DIRECTebanking; mistercash=MisterCash; ... public $issuerId; // mandatory; sisow bank code public $purchaseId; // mandatory; max 16 alphanumeric public $entranceCode; // max 40 strict alphanumeric (letters and numbers only) public $description; // mandatory; max 32 alphanumeric public $amount; // mandatory; min 0.45 public $notifyUrl; public $returnUrl; // mandatory public $cancelUrl; public $callbackUrl; public $testmode; // Status data public $status; public $timeStamp; public $consumerAccount; public $consumerName; public $consumerCity; // Result/check data public $trxId; public $issuerUrl; // Error data public $errorCode; public $errorMessage; // Status const statusSuccess = "Success"; const statusCancelled = "Cancelled"; const statusExpired = "Expired"; const statusFailure = "Failure"; const statusOpen = "Open"; public function __construct($merchantid = null, $merchantkey = null) { $this->merchantId = $merchantid; $this->merchantKey = $merchantkey; } private function error() { $this->errorCode = $this->parse("errorcode"); $this->errorMessage = urldecode($this->parse("errormessage")); } private function parse($search, $xml = false) { if ($xml === false) { $xml = $this->response; } if (($start = strpos($xml, "<" . $search . ">")) === false) { return false; } $start += strlen($search) + 2; if (($end = strpos($xml, "</" . $search . ">", $start)) === false) { return false; } return substr($xml, $start, $end - $start); } private function send($method, array $keyvalue = NULL, $return = 1) { $url = "https://www.sisow.nl/Sisow/iDeal/RestHandler.ashx/" . $method; $options = array( CURLOPT_POST => 1, CURLOPT_HEADER => 0, CURLOPT_URL => $url, CURLOPT_FRESH_CONNECT => 1, CURLOPT_RETURNTRANSFER => $return, CURLOPT_FORBID_REUSE => 1, CURLOPT_TIMEOUT => 90, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_POSTFIELDS => $keyvalue == NULL ? "" : http_build_query($keyvalue, '', '&')); $ch = curl_init(); curl_setopt_array($ch, $options); $this->response = curl_exec($ch); curl_close($ch); if (!$this->response) { return false; } return true; } private function getDirectory() { $diff = 24 * 60 *60; if (self::$lastcheck) $diff = time() - self::$lastcheck; if ($diff < 24 *60 *60) return 0; if (!$this->send("DirectoryRequest")) return -1; $search = $this->parse("directory"); if (!$search) { $this->error(); return -2; } self::$issuers = array(); $iss = explode("<issuer>", str_replace("</issuer>", "", $search)); foreach ($iss as $k => $v) { $issuerid = $this->parse("issuerid", $v); $issuername = $this->parse("issuername", $v); if ($issuerid && $issuername) { self::$issuers[$issuerid] = $issuername; } } self::$lastcheck = time(); return 0; } // DirectoryRequest public function DirectoryRequest(&$output, $select = false, $test = false) { if ($test === true) { // kan ook via de gateway aangevraagd worden, maar is altijd hetzelfde if ($select === true) { $output = "<select id=\"sisowbank\" name=\"issuerid\">"; $output .= "<option value=\"99\">Sisow Bank (test)</option>"; $output .= "</select>"; } else { $output = array("99" => "Sisow Bank (test)"); } return 0; } $output = false; $ex = $this->getDirectory(); if ($ex < 0) { return $ex; } if ($select === true) { $output = "<select id=\"sisowbank\" name=\"issuerid\">"; } else { $output = array(); } foreach (self::$issuers as $k => $v) { if ($select === true) { $output .= "<option value=\"" . $k . "\">" . $v . "</option>"; } else { $output[$k] = $v; } } if ($select === true) { $output .= "</select>"; } return 0; } // TransactionRequest public function TransactionRequest($keyvalue = NULL) { $this->trxId = $this->issuerUrl = ""; if (!$this->merchantId) return -1; if (!$this->merchantKey) return -2; if (!$this->purchaseId) { $this->errorMessage = 'No purchase ID'; return -3; } if ($this->amount < 0.45) { $this->errorMessage = 'Amount < 0.45'; return -4; } if (!$this->description) { $this->errorMessage = 'No description'; return -5; } if (!$this->returnUrl) { $this->errorMessage = 'No return URL'; return -6; } if (!$this->entranceCode) $this->entranceCode = $this->purchaseId; $pars = array(); $pars["merchantid"] = $this->merchantId; $pars["payment"] = $this->payment; $pars["issuerid"] = $this->issuerId; $pars["purchaseid"] = $this->purchaseId; $pars["amount"] = round($this->amount * 100); $pars["description"] = $this->description; $pars["entrancecode"] = $this->entranceCode; $pars["returnurl"] = $this->returnUrl; $pars["cancelurl"] = $this->cancelUrl; $pars["callbackurl"] = $this->callbackUrl; $pars["notifyurl"] = $this->notifyUrl; $pars["testmode"] = $this->testmode; if (isset($this->billing_mail)){ $pars["billing_mail"] = $this->billing_mail; }else{ $pars["billing_mail"] = ''; } if (isset($this->billing_firstname)){ $pars["billing_firstname"] = $this->billing_firstname; }else{ $pars["billing_firstname"] = ''; } if (isset($this->billing_lastname)){ $pars["billing_lastname"] = $this->billing_lastname; }else{ $pars["billing_lastname"] = ''; } if (isset($this->including)){ $pars["including"] = $this->including; }else{ $pars["including"] = ''; } if (isset($this->days)){ $pars["days"] = $this->days; }else{ $pars["days"] = ''; } $pars["sha1"] = sha1($this->purchaseId . $this->entranceCode . round($this->amount * 100) . $this->merchantId . $this->merchantKey); if ($keyvalue) { foreach ($keyvalue as $k => $v) { if ($k != 'amount') { $pars[$k] = $v; } } } if (!$this->send("TransactionRequest", $pars)) return -8; $this->trxId = $this->parse("trxid"); $this->issuerUrl = urldecode($this->parse("issuerurl")); if (!$this->issuerUrl) { $this->error(); return -9; } return 0; } // StatusRequest public function StatusRequest($trxid = false) { if ($trxid === false) $trxid = $this->trxId; if (!$this->merchantId) return -1; if (!$this->merchantKey) return -2; if (!$trxid) { $this->errorMessage = 'No transaction ID'; return -3; } $this->trxId = $trxid; $pars = array(); $pars["merchantid"] = $this->merchantId; $pars["trxid"] = $this->trxId; $pars["sha1"] = sha1($this->trxId . $this->merchantId . $this->merchantKey); if (!$this->send("StatusRequest", $pars)) return -4; $this->status = $this->parse("status"); if (!$this->status) { $this->error(); return -5; } $this->timeStamp = $this->parse("timestamp"); $this->amount = $this->parse("amount") / 100.0; $this->consumerAccount = $this->parse("consumeraccount"); $this->consumerName = $this->parse("consumername"); $this->consumerCity = $this->parse("consumercity"); $this->purchaseId = $this->parse("purchaseid"); $this->description = $this->parse("description"); $this->entranceCode = $this->parse("entrancecode"); return 0; } public function isTestMode(){ $clientip = PaymentManagerTestIP::get()->filter('IpAddress', $_SERVER['REMOTE_ADDR'])->count(); if (PaymentManagerConfig::get()->First()->TestMode == 1 && $clientip > 0){ return true; }else{ return false; } } public function getIdealBanks() { if ($this->isTestMode() == true){ $test = "true"; }else{ $test = "false"; } $service = new RestfulService("https://www.sisow.nl/Sisow/iDeal/RestHandler.ashx", 0); $response = $service->request('/DirectoryRequest?test='.$test, 'GET'); $xml = simplexml_load_string($response->getBody()); $result = array(); foreach( $xml->directory->issuer as $node ) { $result[ $node->issuerid->__toString() ] = $node->issuername->__toString(); } return $result; } } ?> |