M2_AuthorizeNetARB

A class to send a request to the ARB XML API.

Defined (1)

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

/lib/authorize.net/lib/AuthorizeNetARB.php  
  1. class M2_AuthorizeNetARB extends M2_AuthorizeNetRequest 
  2. const LIVE_URL = "https://api2.authorize.net/xml/v1/request.api"; 
  3. const SANDBOX_URL = "https://apitest.authorize.net/xml/v1/request.api"; 
  4.  
  5. private $_request_type; 
  6. private $_request_payload; 
  7.  
  8. /** 
  9. * Optional. Used if the merchant wants to set a reference ID. 
  10. * @param string $refId 
  11. */ 
  12. public function setRefId($refId) 
  13. $this->_request_payload = ($refId ? "<refId>$refId</refId>" : ""); 
  14.  
  15. /** 
  16. * Create an ARB subscription 
  17. * @param AuthorizeNet_Subscription $subscription 
  18. * @return AuthorizeNetARB_Response 
  19. */ 
  20. public function createSubscription(M2_AuthorizeNet_Subscription $subscription) 
  21. $this->_request_type = "CreateSubscriptionRequest"; 
  22. $this->_request_payload .= $subscription->getXml(); 
  23. return $this->_sendRequest(); 
  24.  
  25. /** 
  26. * Update an ARB subscription 
  27. * @param int $subscriptionId 
  28. * @param AuthorizeNet_Subscription $subscription 
  29. * @return AuthorizeNetARB_Response 
  30. */ 
  31. public function updateSubscription($subscriptionId, M2_AuthorizeNet_Subscription $subscription) 
  32. $this->_request_type = "UpdateSubscriptionRequest"; 
  33. $this->_request_payload .= "<subscriptionId>$subscriptionId</subscriptionId>"; 
  34. $this->_request_payload .= $subscription->getXml(); 
  35. return $this->_sendRequest(); 
  36.  
  37. /** 
  38. * Get status of a subscription 
  39. * @param int $subscriptionId 
  40. * @return AuthorizeNetARB_Response 
  41. */ 
  42. public function getSubscriptionStatus($subscriptionId) 
  43. $this->_request_type = "GetSubscriptionStatusRequest"; 
  44. $this->_request_payload .= "<subscriptionId>$subscriptionId</subscriptionId>"; 
  45. return $this->_sendRequest(); 
  46.  
  47. /** 
  48. * Cancel a subscription 
  49. * @param int $subscriptionId 
  50. * @return AuthorizeNetARB_Response 
  51. */ 
  52. public function cancelSubscription($subscriptionId) 
  53. $this->_request_type = "CancelSubscriptionRequest"; 
  54. $this->_request_payload .= "<subscriptionId>$subscriptionId</subscriptionId>"; 
  55. return $this->_sendRequest(); 
  56.  
  57. /** 
  58. * Create an ARB subscription 
  59. * @param AuthorizeNet_Subscription $subscription 
  60. * @return AuthorizeNetARB_Response 
  61. */ 
  62. public function getSubscriptionList(M2_AuthorizeNetGetSubscriptionList $subscriptionList) 
  63. $this->_request_type = "GetSubscriptionListRequest"; 
  64. $this->_request_payload .= $subscriptionList->getXml(); 
  65. return $this->_sendRequest(); 
  66.  
  67. /** 
  68. * @param string $response 
  69. * @return AuthorizeNetARB_Response 
  70. */ 
  71. protected function _handleResponse($response) 
  72. return new M2_AuthorizeNetARB_Response($response); 
  73.  
  74. /** 
  75. * @return string 
  76. */ 
  77. protected function _getPostUrl() 
  78. return ($this->_sandbox ? self::SANDBOX_URL : self::LIVE_URL); 
  79.  
  80. /** 
  81. * Prepare the XML document for posting. 
  82. */ 
  83. protected function _setPostString() 
  84. $this->_post_string =<<<XML 
  85. <?xml version="1.0" encoding="utf-8"?> 
  86. <ARB{$this->_request_type} xmlns= "AnetApi/xml/v1/schema/AnetApiSchema.xsd"> 
  87. <merchantAuthentication> 
  88. <name>{$this->_api_login}</name> 
  89. <transactionKey>{$this->_transaction_key}</transactionKey> 
  90. </merchantAuthentication> 
  91. {$this->_request_payload} 
  92. </ARB{$this->_request_type}> 
  93. XML; 
  94.