1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Easily interact with the Authorize.Net ARB XML API. |
4
|
|
|
* |
5
|
|
|
* @package AuthorizeNet |
6
|
|
|
* @subpackage AuthorizeNetARB |
7
|
|
|
* @link http://www.authorize.net/support/ARB_guide.pdf ARB Guide |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* A class to send a request to the ARB XML API. |
13
|
|
|
* |
14
|
|
|
* @package AuthorizeNet |
15
|
|
|
* @subpackage AuthorizeNetARB |
16
|
|
|
*/ |
17
|
|
|
class AuthorizeNetARB extends AuthorizeNetRequest |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
const LIVE_URL = "https://api2.authorize.net/xml/v1/request.api"; |
20
|
|
|
const SANDBOX_URL = "https://apitest.authorize.net/xml/v1/request.api"; |
21
|
|
|
|
22
|
|
|
private $_request_type; |
23
|
|
|
private $_request_payload; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Optional. Used if the merchant wants to set a reference ID. |
27
|
|
|
* |
28
|
|
|
* @param string $refId |
29
|
|
|
*/ |
30
|
3 |
|
public function setRefId($refId) |
31
|
|
|
{ |
32
|
3 |
|
$this->_request_payload = ($refId ? "<refId>$refId</refId>" : ""); |
33
|
3 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Create an ARB subscription |
37
|
|
|
* |
38
|
|
|
* @param AuthorizeNet_Subscription $subscription |
39
|
|
|
* |
40
|
|
|
* @return AuthorizeNetARB_Response |
41
|
|
|
*/ |
42
|
2 |
|
public function createSubscription(AuthorizeNet_Subscription $subscription) |
43
|
|
|
{ |
44
|
2 |
|
$this->_request_type = "CreateSubscriptionRequest"; |
45
|
2 |
|
$this->_request_payload .= $subscription->getXml(); |
46
|
2 |
|
return $this->_sendRequest(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Update an ARB subscription |
51
|
|
|
* |
52
|
|
|
* @param int $subscriptionId |
53
|
|
|
* @param AuthorizeNet_Subscription $subscription |
54
|
|
|
* |
55
|
|
|
* @return AuthorizeNetARB_Response |
56
|
|
|
*/ |
57
|
|
|
public function updateSubscription($subscriptionId, AuthorizeNet_Subscription $subscription) |
58
|
|
|
{ |
59
|
|
|
$this->_request_type = "UpdateSubscriptionRequest"; |
60
|
|
|
$this->_request_payload .= "<subscriptionId>$subscriptionId</subscriptionId>"; |
61
|
|
|
$this->_request_payload .= $subscription->getXml(); |
62
|
|
|
return $this->_sendRequest(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get status of a subscription |
67
|
|
|
* |
68
|
|
|
* @param int $subscriptionId |
69
|
|
|
* |
70
|
|
|
* @return AuthorizeNetARB_Response |
71
|
|
|
*/ |
72
|
|
|
public function getSubscriptionStatus($subscriptionId) |
73
|
|
|
{ |
74
|
|
|
$this->_request_type = "GetSubscriptionStatusRequest"; |
75
|
|
|
$this->_request_payload .= "<subscriptionId>$subscriptionId</subscriptionId>"; |
76
|
|
|
return $this->_sendRequest(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Cancel a subscription |
81
|
|
|
* |
82
|
|
|
* @param int $subscriptionId |
83
|
|
|
* |
84
|
|
|
* @return AuthorizeNetARB_Response |
85
|
|
|
*/ |
86
|
2 |
|
public function cancelSubscription($subscriptionId) |
87
|
|
|
{ |
88
|
2 |
|
$this->_request_type = "CancelSubscriptionRequest"; |
89
|
2 |
|
$this->_request_payload .= "<subscriptionId>$subscriptionId</subscriptionId>"; |
90
|
2 |
|
return $this->_sendRequest(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Create an ARB subscription |
95
|
|
|
* |
96
|
|
|
* @param AuthorizeNet_Subscription $subscription |
|
|
|
|
97
|
|
|
* |
98
|
|
|
* @return AuthorizeNetARB_Response |
99
|
|
|
*/ |
100
|
1 |
|
public function getSubscriptionList(AuthorizeNetGetSubscriptionList $subscriptionList) |
101
|
|
|
{ |
102
|
1 |
|
$this->_request_type = "GetSubscriptionListRequest"; |
103
|
1 |
|
$this->_request_payload .= $subscriptionList->getXml(); |
104
|
1 |
|
return $this->_sendRequest(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* |
109
|
|
|
* |
110
|
|
|
* @param string $response |
111
|
|
|
* |
112
|
|
|
* @return AuthorizeNetARB_Response |
113
|
|
|
*/ |
114
|
3 |
|
protected function _handleResponse($response) |
115
|
|
|
{ |
116
|
3 |
|
return new AuthorizeNetARB_Response($response); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return string |
121
|
|
|
*/ |
122
|
3 |
|
protected function _getPostUrl() |
123
|
|
|
{ |
124
|
3 |
|
return ($this->_sandbox ? self::SANDBOX_URL : self::LIVE_URL); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Prepare the XML document for posting. |
129
|
|
|
*/ |
130
|
3 |
|
protected function _setPostString() |
131
|
|
|
{ |
132
|
3 |
|
$this->_post_string =<<<XML |
133
|
|
|
<?xml version="1.0" encoding="utf-8"?> |
134
|
3 |
|
<ARB{$this->_request_type} xmlns= "AnetApi/xml/v1/schema/AnetApiSchema.xsd"> |
135
|
|
|
<merchantAuthentication> |
136
|
3 |
|
<name>{$this->_api_login}</name> |
137
|
3 |
|
<transactionKey>{$this->_transaction_key}</transactionKey> |
138
|
|
|
</merchantAuthentication> |
139
|
3 |
|
{$this->_request_payload} |
140
|
3 |
|
</ARB{$this->_request_type}> |
141
|
|
|
XML; |
142
|
3 |
|
} |
143
|
|
|
|
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* A class to parse a response from the ARB XML API. |
149
|
|
|
* |
150
|
|
|
* @package AuthorizeNet |
151
|
|
|
* @subpackage AuthorizeNetARB |
152
|
|
|
*/ |
153
|
|
|
class AuthorizeNetARB_Response extends AuthorizeNetXMLResponse |
|
|
|
|
154
|
|
|
{ |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @return int |
158
|
|
|
*/ |
159
|
2 |
|
public function getSubscriptionId() |
160
|
|
|
{ |
161
|
2 |
|
return $this->_getElementContents("subscriptionId"); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @return string |
166
|
|
|
*/ |
167
|
|
|
public function getSubscriptionStatus() |
168
|
|
|
{ |
169
|
|
|
return $this->_getElementContents("status"); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.