Einzelnen Beitrag anzeigen
Ungelesen 22.03.14, 21:38   #1
nichdiemama
Stammi
 
Registriert seit: Jan 2010
Beiträge: 1.142
Bedankt: 1.440
nichdiemama leckt gerne myGully Deckel in der Kanalisation! | 61226698 Respekt Punktenichdiemama leckt gerne myGully Deckel in der Kanalisation! | 61226698 Respekt Punktenichdiemama leckt gerne myGully Deckel in der Kanalisation! | 61226698 Respekt Punktenichdiemama leckt gerne myGully Deckel in der Kanalisation! | 61226698 Respekt Punktenichdiemama leckt gerne myGully Deckel in der Kanalisation! | 61226698 Respekt Punktenichdiemama leckt gerne myGully Deckel in der Kanalisation! | 61226698 Respekt Punktenichdiemama leckt gerne myGully Deckel in der Kanalisation! | 61226698 Respekt Punktenichdiemama leckt gerne myGully Deckel in der Kanalisation! | 61226698 Respekt Punktenichdiemama leckt gerne myGully Deckel in der Kanalisation! | 61226698 Respekt Punktenichdiemama leckt gerne myGully Deckel in der Kanalisation! | 61226698 Respekt Punktenichdiemama leckt gerne myGully Deckel in der Kanalisation! | 61226698 Respekt Punkte
Standard mit php soap webservice nutzen

hi,

gibts hier leute mit erfahrung bezüglich php und soap?
ich möchte zu testzwecken die API eines Zahlungsdienstleisters ansprechen. Für den Verbindungsaufbau muss zum einen ein clientzertifikat genutzt werden, das vom anbieter geliefert wird, zusätzlich findet auth über username und passwort statt. ich habe aus dem grund auf cURL gesetzt, ist soweit alles auch kein problem. ich bin nur nicht wirklich zufrieden mit dem code den ich bisher habe und suche ansätze, wie man das eleganter lösen kann.

Code:
<?php
/* uncomment this 2 lines for debugging
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 'On');
*/
include 'constants.php';

if (!isset($_POST['submit'])) {} // if page is not submitted to itself echo the form
	else{
	$soaprequest = 
			'<?xml version="1.0" encoding="UTF-8"?>
			<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
				<SOAP-ENV:Header />
				<SOAP-ENV:Body>
					<ipgapi:IPGApiOrderRequest xmlns:v1="http://ipg-online.com/ipgapi/schemas/v1" xmlns:ipgapi="http://ipg-online.com/ipgapi/schemas/ipgapi">
						<v1:Transaction>
						<v1:CreditCardTxType>
							<v1:Type>sale</v1:Type>
						</v1:CreditCardTxType>
						<v1:CreditCardData>
							<v1:CardNumber>' . htmlspecialchars($_POST['CardNumber']) . '</v1:CardNumber>
							<v1:ExpMonth>' . htmlspecialchars($_POST['ExpMonth']) . '</v1:ExpMonth>
							<v1:ExpYear>' . htmlspecialchars($_POST['ExpYear']) . '</v1:ExpYear>
							<v1:CardCodeValue>' . htmlspecialchars($_POST['CardCodeValue']) . '</v1:CardCodeValue>
						</v1:CreditCardData>
						<v1:Payment>
							<v1:ChargeTotal>' . htmlspecialchars($_POST['ChargeTotal']) . '</v1:ChargeTotal>
							<v1:Currency>' . htmlspecialchars($_POST['Currency']) . '</v1:Currency>
						</v1:Payment>
						<v1:Billing>
							<v1:Name>' . htmlspecialchars($_POST['Name']) . '</v1:Name>
						</v1:Billing>  
						</v1:Transaction>
					</ipgapi:IPGApiOrderRequest>
				</SOAP-ENV:Body>
			</SOAP-ENV:Envelope>';
		$ch = curl_init($api_url);
/*
// write curl connection+request into curl.log . make sure the file exist and is set to CHMOD '666'
		$curl_log = fopen('curl.log', 'a+');    
        // settings for logging the curl request 
        curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
        curl_setopt($ch, CURLOPT_STDERR, $curl_log);
// end of curl logging options
*/		
		curl_setopt($ch, CURLOPT_POST, 1);	
		curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));	
		curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);	
		curl_setopt($ch, CURLOPT_USERPWD, $api_user . ':' . $api_user_pw);	
		curl_setopt($ch, CURLOPT_POSTFIELDS, $soaprequest);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
		curl_setopt($ch, CURLOPT_CAINFO, $api_cert_path . 'geotrust.pem');
		curl_setopt($ch, CURLOPT_SSLCERT, $api_cert_path . $storename . '/' . $api_user . '.pem');
		curl_setopt($ch, CURLOPT_SSLKEY,  $api_cert_path . $storename . '/' . $api_user . '.key');
		curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $api_cert_pw);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSLVERSION, 3); #needed to make sure that curl is not using TLS. If not set some configurations may throw "cURL-Error: SSL read: error:140920DF:SSL routines:SSL3_GET_SERVER_HELLO:parse tlsext, errno 0"
		$curl = curl_exec($ch);
		/* next 5 lines are for debugging purposes. uncomment them to print detailed information regarding the cURL request
		$ch_info = curl_getinfo($ch);
		echo 'it took ' . $ch_info['total_time'] . ' seconds to perform the request to ' . $ch_info['url'] . '<br/>';
		echo '<pre>';
			print_r ($ch_info);
		echo '</pre>';
		*/			
		
		if (curl_errno($ch)){
			echo '<br>cURL-Fehler: ' . curl_error($ch);}
		else{
			curl_close ($ch);
		// take out mixed namespaces
			$string = str_replace('ipgapi:', '', $curl);
			$string = str_replace('SOAP-ENV:', '', $string);
		//generate a simplexml object.
			$return = simplexml_load_string($string);
		/*next 3 lines are for debugging purposes. uncomment them to print out the result obhect.
			echo '<pre>';
				print_r ($return);
			echo '</pre>';
		*/	
			if ($return === false) {
				echo 'XML Error: Could not parse: '.$curl;}
			else {
				if ($return->Body->Fault->faultstring =='MerchantException') 
				{echo '<p>Error! <pre>'.$return->Body->Fault->detail.'</pre></p>';}
				else{
					if ($return->Body->IPGApiOrderResponse->TransactionResult == 'APPROVED')
					{echo '<p>APPROVED: '. $return->Body->IPGApiOrderResponse->ApprovalCode .'</p>';}
					else{
						if ($return->Body->Fault->faultstring =='ProcessingException')
						{echo '<p>DECLINED: '.$return->Body->Fault->detail->IPGApiOrderResponse->ErrorMessage . '</p>' ;}
						else {echo 'unknown error';}
					}
				}	
			}
		}
	}				
?>
</body>
</html>
in der includierten constants.php steht nur die URL an die der request geschickt wird und die userdaten, nix spannendes also. Die Kartendaten etc kommen aus 'nem formular, das hab ich auch mal weggelassen.

mich nervt schon, dass ich das komplette xml das ich schicken möchte, quasi statisch vorhalten muss. wenn ich weiter funktionen des webservice nutzen möchte, wird das ziemlich aufwändig und nicht wartbar.
hat jemand elegantere vorschläge?
__________________
Irgendwie komisch, dass das was wir gemeinhin als "unmenschlich" bezeichnen, ausschließlich Verhalten von Menschen beschreibt.
nichdiemama ist offline   Mit Zitat antworten