Exemple #1
0
 public function getDetail($orderid)
 {
     $credentials = $this->__get_credentials();
     $username = $this->name;
     $password = $this->password;
     $clientid = $this->company;
     $document = new XMLBuilder();
     $elements = array("Name" => $username, "Password" => $password, "ClientId" => $clientid, "Mode" => "P", "OrderId" => $orderid);
     $domElements = $document->createElementsWithTextNodes($elements);
     $document->appendListOfElementsToElement($document->root(), $domElements);
     $element = $document->createElement("Extra");
     $statusElement = $document->createElementWithTextNode("ORDERSTATUS", "SOR");
     $element->appendChild($statusElement);
     $document->root()->appendChild($element);
     $documentString = $document->saveXML();
     $this->raw_request = $documentString;
     /* After the XML request has been created, we should now set the HTTP request using curl library..   */
     $url = $this->__connect() . $this->credentials["detailOrderURL"];
     $curl = curl_init();
     $postData = urlencode("DATA") . urlencode("=") . urlencode($documentString);
     // Set the url..
     curl_setopt($curl, CURLOPT_URL, $url);
     // Set the HTTP method to POST..
     curl_setopt($curl, CURLOPT_POST, 1);
     // Set the HTTP response header to False not to get the response header..
     curl_setopt($curl, CURLOPT_HEADER, FALSE);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     // Add the HTTP POST body..
     curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
     // Set the HTTP request header..
     curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type" => "application/x-www-form-urlencoded"));
     // Execute the request and save the response inside a variable called 'raw_response'..
     $this->raw_response = curl_exec($curl);
     // Close the connection..
     curl_close($curl);
     // After we got the response, we should now parse it using xml library..
     $responseDomObject = new DOMDocument();
     $responseDomObject->loadXML($this->raw_response);
     // The result to be returned will be an array containing the response details..
     $result = array();
     $transid = XMLBuilder::get_data($responseDomObject, "TransId");
     $return_code = XMLBuilder::get_data($responseDomObject, "ProcReturnCode");
     $err_msg = XMLBuilder::get_data($responseDomObject, "ErrMsg");
     $host_ref_num = XMLBuilder::get_data($responseDomObject, "HOST_REF_NUM");
     $auth_code = XMLBuilder::get_data($responseDomObject, "AUTH_CODE");
     $charge_type = XMLBuilder::get_data($responseDomObject, "CHARGE_TYPE_CD");
     $details = XMLBuilder::get_data($responseDomObject, "ORDERSTATUS");
     $capture_amount = XMLBuilder::get_data($responseDomObject, "CAPTURE_AMT");
     $trx_date = XMLBuilder::get_data($responseDomObject, "CAPTURE_DTTM");
     $result["transid"] = $transid;
     $result["orderid"] = $orderid;
     $result["return_code"] = $return_code;
     $result["host_ref_num"] = $host_ref_num;
     $result["error_msg"] = $err_msg;
     $result["charge_type"] = $charge_type;
     $result["auth_code"] = $auth_code;
     $result["amount"] = "";
     $result["transaction_time"] = "";
     if ($trx_date) {
         try {
             $trx_date = explode(".", $trx_date);
             $trx_date = $trx_date[0];
             $trx_date = strptime($trx_date, "%Y-%m-%d %H:%M:%S");
             $result["transaction_time"] = $trx_date;
         } catch (Exception $e) {
         }
     }
     if ($capture_amount) {
         try {
             $capture_amount = intval($capture_amount) / 100.0;
             $result["amount"] = $capture_amount;
         } catch (Exception $e) {
         }
     }
     return $result;
 }