M2_AuthorizeNetSOAP

A simple wrapper for the SOAP API as well as a helper function to generate a documentation file from the WSDL.

Defined (1)

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

/lib/authorize.net/lib/AuthorizeNetSOAP.php  
  1. class M2_AuthorizeNetSOAP extends SoapClient 
  2. const WSDL_URL = "https://api2.authorize.net/soap/v1/Service.asmx?WSDL"; 
  3. const LIVE_URL = "https://api2.authorize.net/soap/v1/Service.asmx"; 
  4. const SANDBOX_URL = "https://apitest.authorize.net/soap/v1/Service.asmx"; 
  5.  
  6. public $sandbox; 
  7.  
  8. /** 
  9. * Constructor 
  10. */ 
  11. public function __construct() 
  12. parent::__construct(self::WSDL_URL); 
  13. $this->__setLocation(self::SANDBOX_URL); 
  14.  
  15. /** 
  16. * Switch between the sandbox or production gateway. 
  17. * @param bool 
  18. */ 
  19. public function setSandbox($bool) 
  20. $this->__setLocation(($bool ? self::SANDBOX_URL : self::LIVE_URL)); 
  21.  
  22. /** 
  23. * Get all types as PHP Code. 
  24. * @return string 
  25. */ 
  26. public function getSoapTypes() 
  27. $string = ""; 
  28. $types = $this->__getTypes(); 
  29. foreach ($types as $type) { 
  30. if (preg_match("/struct /", $type)) { 
  31. $type = preg_replace("/struct /", "class ", $type); 
  32. $type = preg_replace("/ (\w+) (\w+);/", " // $1\n public \$$2;", $type); 
  33. $string .= $type ."\n"; 
  34. return $string; 
  35.  
  36. /** 
  37. * Get all methods as PHP Code. 
  38. * @return string 
  39. */ 
  40. public function getSoapMethods() 
  41. $string = ""; 
  42. $functions = array(); 
  43. $methods = $this->__getFunctions(); 
  44. foreach ($methods as $index => $method) { 
  45. $sig = explode(" ", $method, 2); 
  46. if (!isset($functions[$sig[1]])) { 
  47. $string .= " /**\n * @return {$sig[0]}\n */\n public function {$sig[1]} {}\n\n"; 
  48. $functions[$sig[1]] = true; 
  49. return $string; 
  50.  
  51. /** 
  52. * Create a file from the WSDL for reference. 
  53. */ 
  54. public function saveSoapDocumentation($path) 
  55. $string = "<?php\n"; 
  56. $string .= "/**\n"; 
  57. $string .= " * Auto generated documentation for the M2_AuthorizeNetSOAP API.\n"; 
  58. $string .= " * Generated " . date("m/d/Y") . "\n"; 
  59. $string .= " */\n"; 
  60. $string .= "class M2_AuthorizeNetSOAP\n"; 
  61. $string .= "{\n" . $this->getSoapMethods() . "\n}\n\n" . $this->getSoapTypes() ."\n\n ?>"; 
  62. return file_put_contents($path, $string); 
  63.  
  64.  
  65.