@@ -60,17 +60,17 @@ discard block |
||
60 | 60 | * @throws Exception |
61 | 61 | * @return TransactionResult |
62 | 62 | */ |
63 | - public function chargeAmount( $merchant_id, $terminal_id, $sale ) { |
|
64 | - if ( null == $sale ) { |
|
65 | - throw new \Exception( '$sale is null' ); |
|
63 | + public function chargeAmount($merchant_id, $terminal_id, $sale) { |
|
64 | + if (null == $sale) { |
|
65 | + throw new \Exception('$sale is null'); |
|
66 | 66 | } |
67 | 67 | |
68 | - $access_token = $this->getAccessToken( $this->client_id, $this->client_secret, $this->token_endpoint ); |
|
69 | - if ( null == $access_token ) { |
|
70 | - throw new \Exception( 'Could not authorize with gateway.' ); |
|
68 | + $access_token = $this->getAccessToken($this->client_id, $this->client_secret, $this->token_endpoint); |
|
69 | + if (null == $access_token) { |
|
70 | + throw new \Exception('Could not authorize with gateway.'); |
|
71 | 71 | } |
72 | 72 | |
73 | - return $this->makeSaleRequest( $access_token, $merchant_id, $terminal_id, $sale ); |
|
73 | + return $this->makeSaleRequest($access_token, $merchant_id, $terminal_id, $sale); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -81,17 +81,17 @@ discard block |
||
81 | 81 | * @throws Exception |
82 | 82 | * @return TransactionResult |
83 | 83 | */ |
84 | - public function voidTransaction( $transaction_id, $merchant_id, $terminal_id ) { |
|
85 | - if ( null == $transaction_id ) { |
|
86 | - throw new Exception( 'Transaction ID is null' ); |
|
84 | + public function voidTransaction($transaction_id, $merchant_id, $terminal_id) { |
|
85 | + if (null == $transaction_id) { |
|
86 | + throw new Exception('Transaction ID is null'); |
|
87 | 87 | } |
88 | 88 | |
89 | - $access_token = $this->getAccessToken( $this->client_id, $this->client_secret, $this->token_endpoint ); |
|
90 | - if ( null == $access_token ) { |
|
91 | - throw new Exception( 'Could not authorize with gateway.' ); |
|
89 | + $access_token = $this->getAccessToken($this->client_id, $this->client_secret, $this->token_endpoint); |
|
90 | + if (null == $access_token) { |
|
91 | + throw new Exception('Could not authorize with gateway.'); |
|
92 | 92 | } |
93 | 93 | |
94 | - return $this->makeVoidRequest( $access_token, $transaction_id, $merchant_id, $terminal_id ); |
|
94 | + return $this->makeVoidRequest($access_token, $transaction_id, $merchant_id, $terminal_id); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -104,17 +104,17 @@ discard block |
||
104 | 104 | * @return string |
105 | 105 | * @throws Exception |
106 | 106 | */ |
107 | - public function storeCard( $merchant_id, $terminal_id, $card ) { |
|
108 | - if ( null == $card ) { |
|
109 | - throw new Exception( 'Card is null' ); |
|
107 | + public function storeCard($merchant_id, $terminal_id, $card) { |
|
108 | + if (null == $card) { |
|
109 | + throw new Exception('Card is null'); |
|
110 | 110 | } |
111 | 111 | |
112 | - $access_token = $this->getAccessToken( $this->client_id, $this->client_secret, $this->token_endpoint ); |
|
113 | - if ( null == $access_token ) { |
|
114 | - throw new Exception( 'Could not store card with gateway.' ); |
|
112 | + $access_token = $this->getAccessToken($this->client_id, $this->client_secret, $this->token_endpoint); |
|
113 | + if (null == $access_token) { |
|
114 | + throw new Exception('Could not store card with gateway.'); |
|
115 | 115 | } |
116 | 116 | |
117 | - return $this->makeStoreCardRequest( $access_token, $merchant_id, $terminal_id, $card ); |
|
117 | + return $this->makeStoreCardRequest($access_token, $merchant_id, $terminal_id, $card); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -125,43 +125,43 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @return TransactionResult |
127 | 127 | */ |
128 | - private function makeSaleRequest( $access_token, $merchant_id, $terminal_id, $sale ) { |
|
128 | + private function makeSaleRequest($access_token, $merchant_id, $terminal_id, $sale) { |
|
129 | 129 | $sale_request = $sale->serialize($merchant_id, $terminal_id); |
130 | - $body = json_encode( $sale_request ); |
|
130 | + $body = json_encode($sale_request); |
|
131 | 131 | |
132 | - $this->logger->info("Starting transaction for $" . $sale->getTotal()); |
|
132 | + $this->logger->info("Starting transaction for $".$sale->getTotal()); |
|
133 | 133 | |
134 | - $request = new Request($this->gateway_url . 'api/v1/transactions/sale'); |
|
134 | + $request = new Request($this->gateway_url.'api/v1/transactions/sale'); |
|
135 | 135 | $request->getOptions() |
136 | 136 | ->set(CURLOPT_RETURNTRANSFER, true) |
137 | 137 | ->set(CURLOPT_POST, true) |
138 | 138 | ->set(CURLOPT_POSTFIELDS, $body) |
139 | 139 | ->set(CURLOPT_HTTPHEADER, array( |
140 | 140 | 'Content-Type: application/json', |
141 | - 'Content-Length: ' . strlen($body), |
|
141 | + 'Content-Length: '.strlen($body), |
|
142 | 142 | 'Accept: application/json', |
143 | - 'Authorization: Bearer ' . $access_token |
|
143 | + 'Authorization: Bearer '.$access_token |
|
144 | 144 | )); |
145 | 145 | $response = $request->send(); |
146 | 146 | |
147 | - $this->logger->debug( "Transaction completed" ); |
|
147 | + $this->logger->debug("Transaction completed"); |
|
148 | 148 | |
149 | - $sale_response = json_decode( $response->getContent() ); |
|
149 | + $sale_response = json_decode($response->getContent()); |
|
150 | 150 | |
151 | - if ( $sale_response->success ) { |
|
151 | + if ($sale_response->success) { |
|
152 | 152 | $transaction_id = $sale_response->result->transaction_id; |
153 | 153 | |
154 | - $this->logger->info( 'Payment completed. Transaction ID: ' . $transaction_id ); |
|
154 | + $this->logger->info('Payment completed. Transaction ID: '.$transaction_id); |
|
155 | 155 | |
156 | - return new TransactionResult( true, $transaction_id ); |
|
156 | + return new TransactionResult(true, $transaction_id); |
|
157 | 157 | } else { |
158 | 158 | $error_message = $sale_response->error->message; |
159 | 159 | $code = $sale_response->error->code; |
160 | 160 | |
161 | - $this->logger->debug( "Sale response: " . var_export( $sale_response, true ) ); |
|
162 | - $this->logger->error( "Payment failed." ); |
|
161 | + $this->logger->debug("Sale response: ".var_export($sale_response, true)); |
|
162 | + $this->logger->error("Payment failed."); |
|
163 | 163 | |
164 | - return new TransactionResult( false, null, $error_message, $code ); |
|
164 | + return new TransactionResult(false, null, $error_message, $code); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
@@ -175,45 +175,45 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @return TransactionResult |
177 | 177 | */ |
178 | - private function makeVoidRequest( $access_token, $transaction_id, $merchant_id, $terminal_id ) { |
|
178 | + private function makeVoidRequest($access_token, $transaction_id, $merchant_id, $terminal_id) { |
|
179 | 179 | $void = new V0id(TerminalType::$ECommerce, $transaction_id); |
180 | 180 | $void_request = $void->serialize($merchant_id, $terminal_id); |
181 | 181 | |
182 | - $body = json_encode( $void_request ); |
|
182 | + $body = json_encode($void_request); |
|
183 | 183 | |
184 | - $this->logger->info( "Starting void transaction for transaction# " . $transaction_id ); |
|
184 | + $this->logger->info("Starting void transaction for transaction# ".$transaction_id); |
|
185 | 185 | |
186 | - $request = new Request($this->gateway_url . 'api/v1/transactions/void'); |
|
186 | + $request = new Request($this->gateway_url.'api/v1/transactions/void'); |
|
187 | 187 | $request->getOptions() |
188 | 188 | ->set(CURLOPT_RETURNTRANSFER, true) |
189 | 189 | ->set(CURLOPT_POST, true) |
190 | 190 | ->set(CURLOPT_POSTFIELDS, $body) |
191 | 191 | ->set(CURLOPT_HTTPHEADER, array( |
192 | 192 | 'Content-Type: application/json', |
193 | - 'Content-Length: ' . strlen($body), |
|
193 | + 'Content-Length: '.strlen($body), |
|
194 | 194 | 'Accept: application/json', |
195 | - 'Authorization: Bearer ' . $access_token |
|
195 | + 'Authorization: Bearer '.$access_token |
|
196 | 196 | )); |
197 | 197 | $response = $request->send(); |
198 | 198 | |
199 | - $this->logger->debug( "Transaction completed" ); |
|
199 | + $this->logger->debug("Transaction completed"); |
|
200 | 200 | |
201 | - $void_response = json_decode( $response->getContent() ); |
|
201 | + $void_response = json_decode($response->getContent()); |
|
202 | 202 | |
203 | - if ( $void_response->success ) { |
|
203 | + if ($void_response->success) { |
|
204 | 204 | $transaction_id = $void_response->result->transaction_id; |
205 | 205 | |
206 | - $this->logger->info( 'Void completed. Transaction ID: ' . $transaction_id ); |
|
206 | + $this->logger->info('Void completed. Transaction ID: '.$transaction_id); |
|
207 | 207 | |
208 | - return new TransactionResult( true, $transaction_id ); |
|
208 | + return new TransactionResult(true, $transaction_id); |
|
209 | 209 | } else { |
210 | 210 | $error_message = $void_response->error->message; |
211 | 211 | $code = $void_response->error->code; |
212 | 212 | |
213 | - $this->logger->debug( "Void response: " . var_export( $void_response, true ) ); |
|
214 | - $this->logger->error( "Void failed." ); |
|
213 | + $this->logger->debug("Void response: ".var_export($void_response, true)); |
|
214 | + $this->logger->error("Void failed."); |
|
215 | 215 | |
216 | - return new TransactionResult( false, null, $error_message, $code ); |
|
216 | + return new TransactionResult(false, null, $error_message, $code); |
|
217 | 217 | } |
218 | 218 | } |
219 | 219 | |
@@ -227,39 +227,39 @@ discard block |
||
227 | 227 | * |
228 | 228 | * @return string |
229 | 229 | */ |
230 | - private function makeStoreCardRequest( $access_token, $merchant_id, $terminal_id, $card ) { |
|
230 | + private function makeStoreCardRequest($access_token, $merchant_id, $terminal_id, $card) { |
|
231 | 231 | $token_request = new TokenRequest($card, TerminalType::$ECommerce); |
232 | 232 | $token_request_string = $token_request->serialize($merchant_id, $terminal_id); |
233 | - $body = json_encode( $token_request_string ); |
|
233 | + $body = json_encode($token_request_string); |
|
234 | 234 | |
235 | - $this->logger->info( "Starting request for tokenization" ); |
|
235 | + $this->logger->info("Starting request for tokenization"); |
|
236 | 236 | |
237 | - $request = new Request($this->gateway_url . 'api/v1/transactions/tokenize'); |
|
237 | + $request = new Request($this->gateway_url.'api/v1/transactions/tokenize'); |
|
238 | 238 | $request->getOptions() |
239 | 239 | ->set(CURLOPT_RETURNTRANSFER, true) |
240 | 240 | ->set(CURLOPT_POST, true) |
241 | 241 | ->set(CURLOPT_POSTFIELDS, $body) |
242 | 242 | ->set(CURLOPT_HTTPHEADER, array( |
243 | 243 | 'Content-Type: application/json', |
244 | - 'Content-Length: ' . strlen($body), |
|
244 | + 'Content-Length: '.strlen($body), |
|
245 | 245 | 'Accept: application/json', |
246 | - 'Authorization: Bearer ' . $access_token |
|
246 | + 'Authorization: Bearer '.$access_token |
|
247 | 247 | )); |
248 | 248 | $response = $request->send(); |
249 | 249 | |
250 | - $this->logger->debug( "Transaction completed" ); |
|
250 | + $this->logger->debug("Transaction completed"); |
|
251 | 251 | |
252 | - $token_response = json_decode( $response->getContent() ); |
|
252 | + $token_response = json_decode($response->getContent()); |
|
253 | 253 | |
254 | - if ( $token_response->success ) { |
|
254 | + if ($token_response->success) { |
|
255 | 255 | $transaction_id = $token_response->result->transaction_id; |
256 | 256 | |
257 | - $this->logger->info( 'Tokenization completed. Transaction ID: ' . $transaction_id ); |
|
257 | + $this->logger->info('Tokenization completed. Transaction ID: '.$transaction_id); |
|
258 | 258 | |
259 | 259 | return $token_response->result->token; |
260 | 260 | } else { |
261 | - $this->logger->debug( "Tokenization response: " . var_export( $token_response, true ) ); |
|
262 | - $this->logger->error( "Tokenization failed." ); |
|
261 | + $this->logger->debug("Tokenization response: ".var_export($token_response, true)); |
|
262 | + $this->logger->error("Tokenization failed."); |
|
263 | 263 | |
264 | 264 | return ''; |
265 | 265 | } |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | * |
275 | 275 | * @return string |
276 | 276 | */ |
277 | - private function getAccessToken( $client_id, $client_secret, $token_url ) { |
|
277 | + private function getAccessToken($client_id, $client_secret, $token_url) { |
|
278 | 278 | $token_data = array( |
279 | 279 | 'client_id' => $client_id, |
280 | 280 | 'grant_type' => 'client_credentials', |
@@ -293,16 +293,16 @@ discard block |
||
293 | 293 | )); |
294 | 294 | $response = $request->send(); |
295 | 295 | |
296 | - if ( $response->hasError() ) { |
|
297 | - $this->logger->debug( 'Token response status code was ' . $response->getError()->getCode() ); |
|
298 | - $this->logger->debug( "Token request ended in failure: " . var_export( $response, true ) ); |
|
299 | - $this->logger->error( "Gateway authorization failed. Check credentials." ); |
|
296 | + if ($response->hasError()) { |
|
297 | + $this->logger->debug('Token response status code was '.$response->getError()->getCode()); |
|
298 | + $this->logger->debug("Token request ended in failure: ".var_export($response, true)); |
|
299 | + $this->logger->error("Gateway authorization failed. Check credentials."); |
|
300 | 300 | |
301 | 301 | return null; |
302 | 302 | } |
303 | 303 | |
304 | - $this->logger->debug( "Token request was a success: " . $response->getContent()); |
|
305 | - $token = json_decode( $response->getContent() ); |
|
304 | + $this->logger->debug("Token request was a success: ".$response->getContent()); |
|
305 | + $token = json_decode($response->getContent()); |
|
306 | 306 | |
307 | 307 | return $token->access_token; |
308 | 308 | } |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * |
317 | 317 | * @return array |
318 | 318 | */ |
319 | - private function generateTokenizationRequest( $merchant_id, $terminal_id, $card ) { |
|
319 | + private function generateTokenizationRequest($merchant_id, $terminal_id, $card) { |
|
320 | 320 | $token_request = array( |
321 | 321 | 'mid' => $merchant_id, |
322 | 322 | 'terminal' => array( |
@@ -14,7 +14,7 @@ |
||
14 | 14 | private $error_message; |
15 | 15 | private $code; |
16 | 16 | |
17 | - public function __construct( $success, $transaction_id = null, $error_message = null, $code = null ) { |
|
17 | + public function __construct($success, $transaction_id = null, $error_message = null, $code = null) { |
|
18 | 18 | $this->success = $success; |
19 | 19 | $this->transaction_id = $transaction_id; |
20 | 20 | $this->error_message = $error_message; |