Esempio n. 1
0
	/**
	 * This public function makes a transaction status request
	 *
	 * @param string $transactionId	The transaction ID to query. (as returned from the TX request)
	 * @return An instance of AcquirerStatusResponse or FALSE on failure.
	 */
	function RequestTransactionStatus( $transactionId )
	{
		$this->clearError();

		$configCheck = $this->CheckConfig($this->config);

		if ($configCheck != "OK")
		{
			$errorResponse = new ErrorResponse();

			$errorResponse->setErrorCode("001");
			$errorResponse->setErrorMessage("Config error: ".$configCheck);
			$errorResponse->setConsumerMessage("");

			return $errorResponse;
		}

		//check TransactionId length
		$transactionIdOK = $this->LengthCheck("TransactionID", $transactionId, "16");
		if ($transactionIdOK != "ok")
		{
			return $this->getError();
		}


		if ( ! $this->verifyNotNull( $transactionId, "transactionId" ) )
		{
			$errorResponse = $this->getError();

			return $errorResponse;
		}

		// Build the status request XML.
		$xmlMsg = $this->getXMLHeader(
			"AcquirerStatusReq",
		null,
		null,
		$transactionId,
		null );

		if ( ! $xmlMsg ) {
			return false;
		}

		// Add transaction information.
		$xmlMsg .= "<Transaction>\n<transactionID>" . $transactionId . "</transactionID></Transaction>\n";
		$xmlMsg .= "</AcquirerStatusReq>\n";

		// Post the request to the server.
		$response = $this->PostXMLData( $xmlMsg );

		if ($this->parseFromXml( "errorCode", $response ) != "")
		{
			$errorResponse = new ErrorResponse();

			$errorResponse->setErrorCode($this->parseFromXml( "errorCode", $response ));
			$errorResponse->setErrorMessage($this->parseFromXml( "errorMessage", $response ));
			$errorResponse->setConsumerMessage($this->parseFromXml( "consumerMessage", $response ));

			return $errorResponse;
		}
		if ( ($this->parseFromXml( "acquirerID", $response ) == "") || (!$response ))
		{
			$errorResponse = new ErrorResponse();

			$errorResponse->setErrorCode("ING1001");
			$errorResponse->setErrorMessage("Status lookup mislukt (aquirer side)");
			$errorResponse->setConsumerMessage("");

			return $errorResponse;
		}


		// Build the status response object and pass the data into it.
		$res = new AcquirerStatusResponse();
		$creationTime = $this->parseFromXml( "createDateTimeStamp", $response );
		$res->setAcquirerID( $this->parseFromXml( "acquirerID", $response ) );
		$res->setConsumerName( $this->parseFromXml( "consumerName", $response ) );
		$res->setConsumerAccountNumber( $this->parseFromXml( "consumerAccountNumber", $response ) );
		$res->setConsumerCity( $this->parseFromXml( "consumerCity", $response ) );
		$res->setTransactionID( $this->parseFromXml( "transactionID", $response ) );

		// The initial status is INVALID, so that future modifications to
		// this or remote code will yield alarming conditions.
		$res->setStatus(IDEAL_TX_STATUS_INVALID );
		$status = $this->parseFromXml( "status", $response );

		// Determine status identifier (case-insensitive).
		if ( strcasecmp( $status, "success" ) == 0 ) {
			$res->setStatus( IDEAL_TX_STATUS_SUCCESS );
		} else if ( strcasecmp( $status, "Cancelled" ) == 0 ) {
			$res->setStatus( IDEAL_TX_STATUS_CANCELLED );
		} else if ( strcasecmp( $status, "Expired" ) == 0 ) {
			$res->setStatus( IDEAL_TX_STATUS_EXPIRED );
		} else if ( strcasecmp( $status, "Failure" ) == 0 ) {
			$res->setStatus( IDEAL_TX_STATUS_FAILURE );
		} else if ( strcasecmp( $status, "Open" ) == 0 ) {
			$res->setStatus( IDEAL_TX_STATUS_OPEN );
		}

		// The verification of the response starts here.
		// The message as per the reference guide instructions.
		$message = $creationTime . $res->getTransactionID() . $status . $res->getConsumerAccountNumber();
		$message = $this->strip( $message );

		// The signature value in the response contains the signed hash
		// (signed by the signing key on the server)
		$signature64 = $this->ParseFromXml( "signatureValue", $response );

		// The signed hash is base64 encoded and inserted into the XML as such
		$sig = base64_decode( $signature64 );

		// The fingerprint is used as the identifier of the public key certificate.
		// It is sent as part of the response XML.
		$fingerprint = $this->ParseFromXml( "fingerprint", $response );

		// The merchant should have the public certificate stored locally.
		$certfile = $this->getCertificateFileName( $fingerprint );
		if ( ! $certfile )
		{
			return false;
		}

		// Verify the message signature
		$valid = $this->verifyMessage( $certfile, $message, $sig );
		if ( ! $valid )
		{
			return false;
		}

		if (!$res)
		{
			return $response;
		}

		return $res;
	}