/** * @param $requestType * @param $pathUrl * @param $data * @param $signature * @return mixed * @throws OpenPayU_Exception_Configuration * @throws OpenPayU_Exception_Network * @throws OpenPayU_Exception_Authorization */ public static function doRequest($requestType, $pathUrl, $data, $posId, $signatureKey) { if (empty($pathUrl)) { throw new OpenPayU_Exception_Configuration('The end point is empty'); } if (empty($posId)) { throw new OpenPayU_Exception_Configuration('PosId is empty'); } if (empty($signatureKey)) { throw new OpenPayU_Exception_Configuration('SignatureKey is empty'); } $userNameAndPassword = $posId . ":" . $signatureKey; $header = array(); if (OpenPayU_Configuration::getApiVersion() >= 2) { $header[] = 'Content-Type:application/json'; $header[] = 'Accept:application/json'; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $pathUrl); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $requestType); curl_setopt($ch, CURLOPT_ENCODING, 'gzip'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'OpenPayU_HttpCurl::readHeader'); curl_setopt($ch, CURLOPT_POSTFIELDS, OpenPayU_Configuration::getApiVersion() < 2 ? 'DOCUMENT=' . urlencode($data) : $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSLVERSION, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'TLSv1'); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $userNameAndPassword); $response = curl_exec($ch); $httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($response === false) { throw new OpenPayU_Exception_Network(curl_error($ch)); } curl_close($ch); return array('code' => $httpStatus, 'response' => trim($response)); }
/** * Function returns OrderRetrieveResponse Data * @access public * @param string $data * @return array $document */ public static function getOrderRetrieveResponse($data) { $response = OpenPayU::parseXmlDocument(stripslashes($data)); $document = $response['OpenPayU']['OrderDomainResponse']['OrderRetrieveResponse']; if (OpenPayU_Configuration::getApiVersion() >= 2) { $document = $response['OpenPayU']['OrderRetrieveResponse']; } return $document; }
/** * Function builds OpenPayU Xml Document * @access public * @param string $data * @param string $startElement * @param integer $request * @param string $xml_version * @param string $xml_encoding * @return string $xml */ public static function buildOpenPayUDocument($data, $startElement, $request = 1, $xml_version = '1.0', $xml_encoding = 'UTF-8') { if (!is_array($data)) { return false; } $xml = new XmlWriter(); $xml->openMemory(); $xml->startDocument($xml_version, $xml_encoding); if (OpenPayU_Configuration::getApiVersion() < 2) { $xml->startElementNS(null, 'OpenPayU', 'http://www.openpayu.com/openpayu.xsd'); $header = $request == 1 ? 'HeaderRequest' : 'HeaderResponse'; $xml->startElement($header); $xml->writeElement('Algorithm', OpenPayU_Configuration::getHashAlgorithm()); $xml->writeElement('SenderName', 'exampleSenderName'); $xml->writeElement('Version', $xml_version); $xml->endElement(); } else { $xml->startElementNS(null, 'OpenPayU', 'http://www.openpayu.com/20/openpayu.xsd'); } // domain level - open if (OpenPayU_Configuration::getApiVersion() < 2) { $xml->startElement(OpenPayUDomain::getDomain4Message($startElement)); } // message level - open $xml->startElement($startElement); OpenPayU_Util::convertArrayToXml($xml, $data); // message level - close $xml->endElement(); // domain level - close $xml->endElement(); // document level - close if (OpenPayU_Configuration::getApiVersion() < 2) { $xml->endElement(); } return $xml->outputMemory(true); }
public function testSetValidApiVersion() { OpenPayU_Configuration::setApiVersion(2); $this->assertEquals(2, OpenPayU_Configuration::getApiVersion()); }