Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace MyPage;
- // Disable SOAP WSDL Caching. Sometimes new wsdl structures aren't loaded as they should
- ini_set('soap.wsdl_cache_enabled', '0');
- ini_set('soap.wsdl_cache_ttl', '0');
- class WSSEAuth {
- private $Username;
- private $Password;
- function __construct($username, $password) {
- $this->Username=$username;
- $this->Password=$password;
- }
- }
- class WSSEToken {
- private $UsernameToken;
- function __construct ($innerVal){
- $this->UsernameToken = $innerVal;
- }
- }
- // Create SOAP client, this could maybe be a class instead of function
- class SoapClient {
- public $client;
- public function __construct() {
- $strWSSENS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
- $objSoapVarWSSEHeader;
- $objSoapVarUser = new \SoapVar(getenv("NS_USER"), XSD_STRING, NULL, $strWSSENS, NULL, $strWSSENS);
- $objSoapVarPass = new \SoapVar(getenv("NS_PASSWORD"), XSD_STRING, NULL, $strWSSENS, NULL, $strWSSENS);
- $objWSSEAuth = new WSSEAuth($objSoapVarUser, $objSoapVarPass);
- $objSoapVarWSSEAuth = new \SoapVar($objWSSEAuth, SOAP_ENC_OBJECT, NULL, $strWSSENS, getenv("NS_TOKEN"), $strWSSENS);
- $objWSSEToken = new WSSEToken($objSoapVarWSSEAuth);
- $objSoapVarWSSEToken = new \SoapVar($objWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS, getenv("NS_TOKEN"), $strWSSENS);
- $objSoapVarHeaderVal = new \SoapVar($objSoapVarWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'Security', $strWSSENS);
- $objSoapVarWSSEHeader = new \SoapHeader($strWSSENS, 'Security', $objSoapVarHeaderVal, true);
- $this->client = new \SoapClient(getenv("GATEWAY_URL"), array('trace' => 1));
- $this->client->__setSoapHeaders(array($objSoapVarWSSEHeader));
- }
- /**
- * Calls method with request.
- *
- * @param string $method The name of the method
- * @param array $request The data to send to the method
- *
- * @return stdClass The response from Gateway
- */
- public function call($method, $request) {
- try{
- // Log resopnse in development
- if(getenv("WP_ENV") == "development") {
- $t = new \Timer($method);
- $result = $this->client->$method($request);
- $response = $this->client->__getLastResponse();
- file_put_contents($_SERVER["DOCUMENT_ROOT"] . "/log/soap.xml", $response);
- unset($t);
- } else {
- $result = $this->client->$method($request);
- }
- return $result;
- } catch (SoapFault $exception) {
- throw $exception;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement