CyberSourceSoapClient

CyberSource version of SoapClient.

Defined (1)

The class is defined in the following location(s).

/includes/lib/CyberSource/cyber_source_soap_client.php  
  1. class CyberSourceSoapClient extends SoapClient { 
  2.  
  3. /** 
  4. * Instance-specific array to contain CyberSource-specific configuration 
  5. * settings. 
  6. * @var array 
  7. * @access protected 
  8. */ 
  9. protected $_cyberSourceOptions = null; 
  10.  
  11. /** 
  12. * Constructor. 
  13. * The WSDL is generated by CyberSourceSource::_buildWsdl, in accordance with 
  14. * the DataSource settings. 
  15. * The CyberSource Options array should contain a 'merchantID' key and a 
  16. * 'transactionKey' key, with appropriate string values. 
  17. * The SOAP options array (the standard options array for PHP's SoapClient 
  18. * class) can be empty for CyberSource transactions. 
  19. * @param mixed $wsdl 
  20. * @param array $cyberSourceOptions 
  21. * @param array $soapOptions 
  22. * @access private 
  23. */ 
  24. public function __construct($wsdl, $cyberSourceOptions = null, $soapOptions = array()) { 
  25. parent::__construct($wsdl, $soapOptions); 
  26.  
  27. $this->_cyberSourceOptions = array_merge(array( 
  28. 'merchantID' => '',  
  29. 'transactionKey' => '',  
  30. ), is_array($cyberSourceOptions) ? $cyberSourceOptions : array()); 
  31.  
  32. /** 
  33. * Transport layer for SOAP request. 
  34. * This is a straightforward wrapper for the standard SoapClient::__doRequest 
  35. * method; its parameters are identical. 
  36. * @param string $request 
  37. * @param string $location 
  38. * @param string $action 
  39. * @param string $version 
  40. * @param integer $one_way 
  41. * @return string XML SOAP response 
  42. * @access private 
  43. */ 
  44. public function __doRequest($request, $location, $action, $version, $one_way = 0) { 
  45. $soapHeader = sprintf("<SOAP-ENV:Header xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"><wsse:Security SOAP-ENV:mustUnderstand=\"1\"><wsse:UsernameToken><wsse:Username>%s</wsse:Username><wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">%s</wsse:Password></wsse:UsernameToken></wsse:Security></SOAP-ENV:Header>", $this->_cyberSourceOptions['merchantID'], $this->_cyberSourceOptions['transactionKey']); 
  46.  
  47. $requestDOM = new DOMDocument('1.0'); 
  48. $soapHeaderDOM = new DOMDocument('1.0'); 
  49.  
  50. try { 
  51. $requestDOM->loadXML($request); 
  52. $soapHeaderDOM->loadXML($soapHeader); 
  53. $node = $requestDOM->importNode($soapHeaderDOM->firstChild, true); 
  54. $requestDOM->firstChild->insertBefore( 
  55. $node, $requestDOM->firstChild->firstChild); 
  56.  
  57. $request = $requestDOM->saveXML(); 
  58. } catch (DOMException $e) { 
  59. trigger_error("CybserSource Error: Couldn't add token: " . $e->code, E_USER_WARNING); 
  60.  
  61. return parent::__doRequest($request, $location, $action, $version); 
  62.