Conditions | 3 |
Paths | 3 |
Total Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 3 |
Changes | 0 |
Metric | Value |
---|---|
dl | 0 |
loc | 11 |
ccs | 8 |
cts | 8 |
cp | 1 |
rs | 9.9 |
c | 0 |
b | 0 |
f | 0 |
cc | 3 |
nc | 3 |
nop | 0 |
crap | 3 |
1 | <?php |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /** |
||
0 ignored issues
–
show
|
|||
6 | * This file is part of the AuthnetJSON package. |
||
7 | * |
||
8 | * (c) John Conde <[email protected]> |
||
9 | * |
||
10 | * For the full copyright and license information, please view the LICENSE |
||
11 | * file that was distributed with this source code. |
||
12 | */ |
||
13 | |||
14 | namespace JohnConde\Authnet; |
||
15 | |||
16 | use \Curl\Curl; |
||
17 | |||
18 | /** |
||
19 | * Creates a request to the Authorize.Net JSON endpoints. |
||
20 | * |
||
21 | * @package AuthnetJSON |
||
0 ignored issues
–
show
|
|||
22 | * @author John Conde <[email protected]> |
||
0 ignored issues
–
show
|
|||
23 | * @copyright John Conde <[email protected]> |
||
0 ignored issues
–
show
|
|||
24 | * @license http://www.apache.org/licenses/LICENSE-2.0.html Apache License, Version 2.0 |
||
0 ignored issues
–
show
|
|||
25 | * @link https://github.com/stymiee/authnetjson |
||
0 ignored issues
–
show
|
|||
26 | * @see https://developer.authorize.net/api/reference/ |
||
0 ignored issues
–
show
|
|||
27 | * |
||
28 | * @method AuthnetJsonResponse createTransactionRequest(array $array) process a payment |
||
0 ignored issues
–
show
|
|||
29 | * @method AuthnetJsonResponse sendCustomerTransactionReceiptRequest(array $array) get a list of unsettled transactions |
||
0 ignored issues
–
show
|
|||
30 | * @method AuthnetJsonResponse ARBCancelSubscriptionRequest(array $array) cancel a subscription |
||
0 ignored issues
–
show
|
|||
31 | * @method AuthnetJsonResponse ARBCreateSubscriptionRequest(array $array) create a subscription |
||
0 ignored issues
–
show
|
|||
32 | * @method AuthnetJsonResponse ARBGetSubscriptionStatusRequest(array $array) get a subscription's status |
||
0 ignored issues
–
show
|
|||
33 | * @method AuthnetJsonResponse ARBUpdateSubscriptionRequest(array $array) update a subscription |
||
0 ignored issues
–
show
|
|||
34 | * @method AuthnetJsonResponse createCustomerPaymentProfileRequest(array $array) create a payment profile |
||
0 ignored issues
–
show
|
|||
35 | * @method AuthnetJsonResponse createCustomerProfileRequest(array $array) create a customer profile |
||
0 ignored issues
–
show
|
|||
36 | * @method AuthnetJsonResponse createCustomerProfileTransactionRequest_authCapture(array $array) process an Authorization and Capture transaction (Sale) |
||
0 ignored issues
–
show
|
|||
37 | * @method AuthnetJsonResponse createCustomerProfileTransactionRequest_authOnly(array $array) process an Authorization Only transaction |
||
0 ignored issues
–
show
|
|||
38 | * @method AuthnetJsonResponse createCustomerProfileTransactionRequest_captureOnly(array $array) process a Capture Only transaction |
||
0 ignored issues
–
show
|
|||
39 | * @method AuthnetJsonResponse createCustomerProfileTransactionRequest_priorAuthCapture(array $array) process a Prior Authorization Capture transaction |
||
0 ignored issues
–
show
|
|||
40 | * @method AuthnetJsonResponse createCustomerProfileTransactionRequest_refund(array $array) process a Refund (credit) |
||
0 ignored issues
–
show
|
|||
41 | * @method AuthnetJsonResponse createCustomerProfileTransactionRequest_void(array $array) void a transaction |
||
0 ignored issues
–
show
|
|||
42 | * @method AuthnetJsonResponse createCustomerShippingAddressRequest(array $array) create a shipping profile |
||
0 ignored issues
–
show
|
|||
43 | * @method AuthnetJsonResponse deleteCustomerPaymentProfileRequest(array $array) delete a payment profile |
||
0 ignored issues
–
show
|
|||
44 | * @method AuthnetJsonResponse deleteCustomerProfileRequest(array $array) delete a customer profile |
||
0 ignored issues
–
show
|
|||
45 | * @method AuthnetJsonResponse deleteCustomerShippingAddressRequest(array $array) delete a shipping profile |
||
0 ignored issues
–
show
|
|||
46 | * @method AuthnetJsonResponse getCustomerPaymentProfileRequest(array $array) retrieve a payment profile |
||
0 ignored issues
–
show
|
|||
47 | * @method AuthnetJsonResponse getCustomerProfileIdsRequest(array $array) retrieve a list of profile IDs |
||
0 ignored issues
–
show
|
|||
48 | * @method AuthnetJsonResponse getCustomerProfileRequest(array $array) retrieve a customer profile |
||
0 ignored issues
–
show
|
|||
49 | * @method AuthnetJsonResponse getCustomerShippingAddressRequest(array $array) retrieve a shipping address |
||
0 ignored issues
–
show
|
|||
50 | * @method AuthnetJsonResponse getHostedProfilePageRequest(array $array) retrieve a hosted payment page token |
||
0 ignored issues
–
show
|
|||
51 | * @method AuthnetJsonResponse updateCustomerPaymentProfileRequest(array $array) update a customer profile |
||
0 ignored issues
–
show
|
|||
52 | * @method AuthnetJsonResponse updateCustomerProfileRequest(array $array) update a customer profile |
||
0 ignored issues
–
show
|
|||
53 | * @method AuthnetJsonResponse updateCustomerShippingAddressRequest(array $array) update a shipping address |
||
0 ignored issues
–
show
|
|||
54 | * @method AuthnetJsonResponse updateSplitTenderGroupRequest(array $array) update a split tender transaction |
||
0 ignored issues
–
show
|
|||
55 | * @method AuthnetJsonResponse validateCustomerPaymentProfileRequest(array $array) validate a payment profile |
||
0 ignored issues
–
show
|
|||
56 | * @method AuthnetJsonResponse getBatchStatisticsRequest(array $array) get a summary of a settled batch |
||
0 ignored issues
–
show
|
|||
57 | * @method AuthnetJsonResponse getSettledBatchListRequest(array $array) get a list of settled batches |
||
0 ignored issues
–
show
|
|||
58 | * @method AuthnetJsonResponse getTransactionDetailsRequest(array $array) get the details of a transaction |
||
0 ignored issues
–
show
|
|||
59 | * @method AuthnetJsonResponse getTransactionListRequest(array $array) get a list of transaction in a batch |
||
0 ignored issues
–
show
|
|||
60 | * @method AuthnetJsonResponse getUnsettledTransactionListRequest(array $array) get a list of unsettled transactions |
||
0 ignored issues
–
show
|
|||
61 | */ |
||
62 | class AuthnetJsonRequest |
||
63 | { |
||
0 ignored issues
–
show
|
|||
64 | /** |
||
0 ignored issues
–
show
|
|||
65 | * @var int Maximum number of retires making HTTP request before failure |
||
0 ignored issues
–
show
|
|||
66 | */ |
||
67 | private const MAX_RETRIES = 3; |
||
68 | |||
69 | /** |
||
0 ignored issues
–
show
|
|||
70 | * @var string Authorize.Net API login ID |
||
0 ignored issues
–
show
|
|||
71 | */ |
||
72 | private $login; |
||
0 ignored issues
–
show
|
|||
73 | |||
74 | /** |
||
0 ignored issues
–
show
|
|||
75 | * @var string Authorize.Net API Transaction Key |
||
0 ignored issues
–
show
|
|||
76 | */ |
||
77 | private $transactionKey; |
||
0 ignored issues
–
show
|
|||
78 | |||
79 | /** |
||
0 ignored issues
–
show
|
|||
80 | * @var string URL endpoint for processing a transaction |
||
0 ignored issues
–
show
|
|||
81 | */ |
||
82 | private $url; |
||
0 ignored issues
–
show
|
|||
83 | |||
84 | /** |
||
0 ignored issues
–
show
|
|||
85 | * @var string JSON formatted API request |
||
0 ignored issues
–
show
|
|||
86 | */ |
||
87 | private $requestJson; |
||
0 ignored issues
–
show
|
|||
88 | |||
89 | /** |
||
0 ignored issues
–
show
|
|||
90 | * @var object Wrapper object representing an endpoint |
||
0 ignored issues
–
show
|
|||
91 | */ |
||
92 | private $processor; |
||
0 ignored issues
–
show
|
|||
93 | |||
94 | /** |
||
0 ignored issues
–
show
|
|||
95 | * @var int Number of attempts to make an HTTP request |
||
0 ignored issues
–
show
|
|||
96 | */ |
||
97 | private $retries; |
||
0 ignored issues
–
show
|
|||
98 | |||
99 | /** |
||
100 | * Creates the request object by setting the Authorize.Net credentials and URL of the endpoint to be used |
||
0 ignored issues
–
show
|
|||
101 | * for the API call. |
||
102 | * |
||
103 | * @param string $login Authorize.Net API login ID |
||
0 ignored issues
–
show
|
|||
104 | * @param string $transactionKey Authorize.Net API Transaction Key |
||
0 ignored issues
–
show
|
|||
105 | * @param string $api_url URL endpoint for processing a transaction |
||
0 ignored issues
–
show
|
|||
106 | */ |
||
107 | 1 | public function __construct(string $login, string $transactionKey, string $api_url) |
|
0 ignored issues
–
show
$api_url does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$ ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() |
|||
108 | { |
||
0 ignored issues
–
show
|
|||
109 | 1 | $this->login = $login; |
|
110 | 1 | $this->transactionKey = $transactionKey; |
|
111 | 1 | $this->url = $api_url; |
|
0 ignored issues
–
show
$api_url does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$ ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() |
|||
112 | 1 | } |
|
0 ignored issues
–
show
|
|||
113 | |||
114 | /** |
||
115 | * Outputs the account credentials, endpoint URL, and request JSON in a human readable format |
||
116 | * |
||
117 | * @return string HTML table containing debugging information |
||
0 ignored issues
–
show
|
|||
118 | */ |
||
119 | 1 | public function __toString() |
|
120 | { |
||
0 ignored issues
–
show
|
|||
121 | 1 | $output = '<table id="authnet-request">'."\n"; |
|
0 ignored issues
–
show
|
|||
122 | 1 | $output .= '<caption>Authorize.Net Request</caption>'."\n"; |
|
0 ignored issues
–
show
|
|||
123 | 1 | $output .= '<tr><th colspan="2"><b>Class Parameters</b></th></tr>'."\n"; |
|
0 ignored issues
–
show
|
|||
124 | 1 | $output .= '<tr><td><b>API Login ID</b></td><td>'.$this->login.'</td></tr>'."\n"; |
|
0 ignored issues
–
show
|
|||
125 | 1 | $output .= '<tr><td><b>Transaction Key</b></td><td>'.$this->transactionKey.'</td></tr>'."\n"; |
|
0 ignored issues
–
show
|
|||
126 | 1 | $output .= '<tr><td><b>Authnet Server URL</b></td><td>'.$this->url.'</td></tr>'."\n"; |
|
0 ignored issues
–
show
|
|||
127 | 1 | $output .= '<tr><th colspan="2"><b>Request JSON</b></th></tr>'."\n"; |
|
0 ignored issues
–
show
|
|||
128 | 1 | if (!empty($this->requestJson)) { |
|
0 ignored issues
–
show
|
|||
129 | 1 | $output .= '<tr><td colspan="2"><pre>'."\n"; |
|
0 ignored issues
–
show
|
|||
130 | 1 | $output .= $this->requestJson."\n"; |
|
0 ignored issues
–
show
|
|||
131 | 1 | $output .= '</pre></td></tr>'."\n"; |
|
0 ignored issues
–
show
|
|||
132 | } |
||
0 ignored issues
–
show
|
|||
133 | 1 | $output .= '</table>'; |
|
134 | |||
135 | 1 | return $output; |
|
136 | } |
||
0 ignored issues
–
show
|
|||
137 | |||
138 | /** |
||
139 | * The __set() method should never be used as all values to be made in the APi call must be passed as an array |
||
0 ignored issues
–
show
|
|||
140 | * |
||
141 | * @param string $name unused |
||
0 ignored issues
–
show
|
|||
142 | * @param mixed $value unused |
||
0 ignored issues
–
show
|
|||
143 | * @throws AuthnetCannotSetParamsException |
||
0 ignored issues
–
show
|
|||
144 | */ |
||
0 ignored issues
–
show
|
|||
145 | 2 | public function __set($name, $value) |
|
0 ignored issues
–
show
|
|||
146 | { |
||
0 ignored issues
–
show
|
|||
147 | 2 | throw new AuthnetCannotSetParamsException(sprintf('You cannot set parameters directly in %s.', __CLASS__)); |
|
0 ignored issues
–
show
|
|||
148 | } |
||
0 ignored issues
–
show
|
|||
149 | |||
150 | /** |
||
151 | * Magic method that dynamically creates our API call based on the name of the method in the client code and |
||
0 ignored issues
–
show
|
|||
152 | * the array passed as its parameter. |
||
153 | * |
||
154 | * @param string $api_call name of the API call to be made |
||
0 ignored issues
–
show
|
|||
155 | * @param array $args the array to be passed to the API |
||
0 ignored issues
–
show
|
|||
156 | * @return AuthnetJsonResponse |
||
0 ignored issues
–
show
|
|||
157 | * @throws AuthnetCurlException |
||
0 ignored issues
–
show
|
|||
158 | * @throws AuthnetInvalidJsonException |
||
0 ignored issues
–
show
|
|||
159 | */ |
||
160 | 1 | public function __call($api_call, Array $args) |
|
0 ignored issues
–
show
$api_call does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$ ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() |
|||
161 | { |
||
0 ignored issues
–
show
|
|||
162 | $authentication = [ |
||
163 | 'merchantAuthentication' => [ |
||
0 ignored issues
–
show
|
|||
164 | 1 | 'name' => $this->login, |
|
0 ignored issues
–
show
|
|||
165 | 1 | 'transactionKey' => $this->transactionKey, |
|
0 ignored issues
–
show
|
|||
166 | ] |
||
0 ignored issues
–
show
|
|||
167 | ]; |
||
0 ignored issues
–
show
|
|||
168 | 1 | $call = []; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
169 | 1 | if (count($args)) { |
|
170 | 1 | $call = $args[0]; |
|
171 | } |
||
0 ignored issues
–
show
|
|||
172 | $parameters = [ |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
173 | 1 | $api_call => $authentication + $call |
|
0 ignored issues
–
show
$api_call does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$ ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() |
|||
174 | ]; |
||
0 ignored issues
–
show
|
|||
175 | 1 | $this->requestJson = json_encode($parameters); |
|
176 | |||
177 | 1 | $response = $this->process(); |
|
178 | 1 | return new AuthnetJsonResponse($response); |
|
179 | } |
||
0 ignored issues
–
show
|
|||
180 | |||
181 | /** |
||
182 | * Makes POST request with retry logic. |
||
183 | */ |
||
0 ignored issues
–
show
|
|||
184 | 2 | private function makeRequest() : void |
|
0 ignored issues
–
show
|
|||
185 | { |
||
0 ignored issues
–
show
|
|||
186 | 2 | $this->retries = 0; |
|
187 | 2 | while ($this->retries < self::MAX_RETRIES) { |
|
188 | 2 | $this->processor->post($this->url, $this->requestJson); |
|
189 | 2 | if (!$this->processor->error) { |
|
0 ignored issues
–
show
|
|||
190 | 1 | break; |
|
191 | } |
||
0 ignored issues
–
show
|
|||
192 | 1 | $this->retries++; |
|
193 | } |
||
194 | 2 | } |
|
0 ignored issues
–
show
|
|||
195 | |||
196 | /** |
||
197 | * Tells the handler to make the API call to Authorize.Net. |
||
198 | * |
||
199 | * @return string JSON string containing API response |
||
0 ignored issues
–
show
|
|||
200 | * @throws AuthnetCurlException |
||
0 ignored issues
–
show
|
|||
201 | */ |
||
202 | 72 | private function process() : string |
|
0 ignored issues
–
show
|
|||
203 | { |
||
0 ignored issues
–
show
|
|||
204 | 72 | $this->makeRequest(); |
|
205 | 72 | if (!$this->processor->error && isset($this->processor->response)) { |
|
0 ignored issues
–
show
|
|||
206 | 70 | return $this->processor->response; |
|
207 | } |
||
0 ignored issues
–
show
|
|||
208 | 2 | $error_message = null; |
|
0 ignored issues
–
show
$error_message does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$ ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() |
|||
209 | 2 | $error_code = null; |
|
0 ignored issues
–
show
$error_code does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$ ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() |
|||
210 | 2 | if ($this->processor->error_code || $this->processor->error_message) { |
|
211 | 1 | $error_message = $this->processor->error_message; |
|
0 ignored issues
–
show
$error_message does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$ ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() |
|||
212 | 1 | $error_code = $this->processor->error_code; |
|
0 ignored issues
–
show
$error_code does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$ ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() |
|||
213 | } |
||
0 ignored issues
–
show
|
|||
214 | 2 | throw new AuthnetCurlException(sprintf('Connection error: %s (%s)', $error_message, $error_code)); |
|
0 ignored issues
–
show
$error_message does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$ ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() |
|||
215 | } |
||
0 ignored issues
–
show
|
|||
216 | |||
217 | /** |
||
218 | * Sets the handler to be used to handle our API call. Mainly used for unit testing as Curl is used by default. |
||
0 ignored issues
–
show
|
|||
219 | * |
||
220 | * @param Curl $processor |
||
0 ignored issues
–
show
|
|||
221 | */ |
||
0 ignored issues
–
show
|
|||
222 | 1 | public function setProcessHandler($processor) : void |
|
0 ignored issues
–
show
|
|||
223 | { |
||
0 ignored issues
–
show
|
|||
224 | 1 | $this->processor = $processor; |
|
225 | 1 | } |
|
0 ignored issues
–
show
|
|||
226 | |||
227 | /** |
||
228 | * Gets the request sent to Authorize.Net in JSON format for logging purposes. |
||
229 | * |
||
230 | * @return string transaction request sent to Authorize.Net in JSON format |
||
0 ignored issues
–
show
|
|||
231 | */ |
||
232 | 1 | public function getRawRequest() : string |
|
233 | { |
||
0 ignored issues
–
show
|
|||
234 | 1 | return $this->requestJson; |
|
235 | } |
||
0 ignored issues
–
show
|
|||
236 | } |
||
0 ignored issues
–
show
|
|||
237 |