Changeset 2014867
- Timestamp:
- 01/18/2019 02:01:49 PM (7 years ago)
- Location:
- woo-litego/trunk/includes
- Files:
-
- 2 edited
-
class-wc-gateway-litego.php (modified) (6 diffs)
-
class-wc-litego-api.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woo-litego/trunk/includes/class-wc-gateway-litego.php
r2014779 r2014867 188 188 $this->form_fields = require( dirname( __FILE__ ) . '/admin/litego-settings.php' ); 189 189 } 190 191 /** 192 * Reset auth_token/refresh_token if we change smth in the backend settings 193 * 194 * @return mixed 195 */ 196 public function process_admin_options() { 197 $this->init_settings(); 198 199 $this->settings['auth_token'] = ""; 200 $this->settings['refresh_token'] = ""; 201 202 $post_data = $this->get_post_data(); 203 204 foreach ( $this->get_form_fields() as $key => $field ) { 205 if ( 'title' !== $this->get_field_type( $field ) ) { 206 try { 207 $this->settings[ $key ] = $this->get_field_value( $key, $field, $post_data ); 208 } catch ( Exception $e ) { 209 $this->add_error( $e->getMessage() ); 210 } 211 } 212 } 213 214 return update_option( $this->get_option_key(), apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->settings ), 'yes' ); 215 } 190 216 191 217 /** … … 330 356 } 331 357 332 333 334 358 /** 335 359 * Send a charge creation request to Litego … … 347 371 ); 348 372 349 350 373 //reauthenticate first 351 if($result['error'] and $result['error_ message']=="Forbidden") {374 if($result['error'] and $result['error_name'] == "Forbidden") { 352 375 $auth = $this->litegoApi->reauthenticate($this->refresh_token, $this->merchant_id, $this->secret_key); 353 376 $this->updateTokens($auth); … … 363 386 if($result['error']) 364 387 { 365 $this->log("Error Response: " . print_r( $result['error_ message'], true));366 if ($result['error_ message'] == "SendCoinsError") {388 $this->log("Error Response: " . print_r( $result['error_name'] .": ". $result['error_message'], true)); 389 if ($result['error_name'] == "SendCoinsError") { 367 390 return new WP_Error('litego_error', __('Payment is too large, max payment allowed is 0.04294967 BTC', 'woo-litego')); 368 391 } else { 369 392 return new WP_Error('litego_error', __('There was a problem connecting to the payment gateway.', 'woo-litego')); 370 393 } 371 } 372 373 if (empty($result['payment_request'])) { 374 return new WP_Error('litego_error', __('There was a problem connecting to the payment gateway.', 'woo-litego')); 375 } else { 376 return $result; 377 } 394 395 } 396 397 return $result; 378 398 } 379 399 … … 403 423 404 424 //reauthenticate first 405 if($result['error'] and $result['error_ message']=="Forbidden") {425 if($result['error'] and $result['error_name'] == "Forbidden") { 406 426 $auth = $this->litegoApi->reauthenticate($this->refresh_token, $this->merchant_id, $this->secret_key); 407 427 $this->updateTokens($auth); … … 416 436 if($result['error']) 417 437 { 418 $this->log("Error Response: " . print_r( $result['error_ message'], true));438 $this->log("Error Response: " . print_r( $result['error_name'] .": ". $result['error_message'], true)); 419 439 return new WP_Error('litego_error', __('There was a problem connecting to the payment gateway.', 'woo-litego')); 420 421 } 422 423 424 if ( empty($result['payment_request']) ) { 425 return new WP_Error('litego_error', __('There was a problem connecting to the payment gateway.', 'woo-litego')); 426 } else { 427 return $result; 428 } 440 } 441 442 return $result; 429 443 } 430 444 -
woo-litego/trunk/includes/class-wc-litego-api.php
r2014779 r2014867 29 29 30 30 /** 31 * @var array Map of standard HTTP status code/reason phrases32 */33 private static $phrases = [34 100 => 'Continue',35 101 => 'Switching Protocols',36 102 => 'Processing',37 200 => 'OK',38 201 => 'Created',39 202 => 'Accepted',40 203 => 'Non-Authoritative Information',41 204 => 'No Content',42 205 => 'Reset Content',43 206 => 'Partial Content',44 207 => 'Multi-status',45 208 => 'Already Reported',46 300 => 'Multiple Choices',47 301 => 'Moved Permanently',48 302 => 'Found',49 303 => 'See Other',50 304 => 'Not Modified',51 305 => 'Use Proxy',52 306 => 'Switch Proxy',53 307 => 'Temporary Redirect',54 400 => 'Bad Request',55 401 => 'Unauthorized',56 402 => 'Payment Required',57 403 => 'Forbidden',58 404 => 'Not Found',59 405 => 'Method Not Allowed',60 406 => 'Not Acceptable',61 407 => 'Proxy Authentication Required',62 408 => 'Request Time-out',63 409 => 'Conflict',64 410 => 'Gone',65 411 => 'Length Required',66 412 => 'Precondition Failed',67 413 => 'Request Entity Too Large',68 414 => 'Request-URI Too Large',69 415 => 'Unsupported Media Type',70 416 => 'Requested range not satisfiable',71 417 => 'Expectation Failed',72 418 => 'I\'m a teapot',73 422 => 'Unprocessable Entity',74 423 => 'Locked',75 424 => 'Failed Dependency',76 425 => 'Unordered Collection',77 426 => 'Upgrade Required',78 428 => 'Precondition Required',79 429 => 'Too Many Requests',80 431 => 'Request Header Fields Too Large',81 451 => 'Unavailable For Legal Reasons',82 500 => 'Internal Server Error',83 501 => 'Not Implemented',84 502 => 'Bad Gateway',85 503 => 'Service Unavailable',86 504 => 'Gateway Time-out',87 505 => 'HTTP Version not supported',88 506 => 'Variant Also Negotiates',89 507 => 'Insufficient Storage',90 508 => 'Loop Detected',91 511 => 'Network Authentication Required',92 ];93 94 /**95 31 * @var string 96 32 */ … … 122 58 123 59 if ($result['error']) { 124 throw new Exception('Litego API: requestAuthenticate error');60 throw new Exception('Litego API: ' . $result['error_message']); 125 61 } 126 62 … … 135 71 $result = $this->refreshAuthToken($refreshToken, $timeout); 136 72 137 if ($result['error'] && $result['error_ message'] == "Forbidden") {73 if ($result['error'] && $result['error_name'] == "Forbidden") { 138 74 //try to get new auth and refresh token with secret key 139 75 return $this->reauthenticate("", $merchantId, $secretKey, $timeout); … … 141 77 142 78 if ($result['error']) { 143 //for display static error page without redirect (look class GeneralException) 144 throw new Exception('Litego API: requestRefreshAuthToken error'); 79 throw new Exception('Litego API: ' . $result['error_message']); 145 80 } 146 81 … … 183 118 'code' => $result['response_code'] ? $result['response_code'] : self::CODE_400, 184 119 'error' => 1, 185 'error_message' => $result['response_error'], 120 'error_name' => $result['response_result']['name'], 121 'error_message' => $result['response_result']['detail'], 186 122 ); 187 123 } … … 219 155 'code' => $result['response_code']?$result['response_code']:self::CODE_400, 220 156 'error' => 1, 221 'error_message' => $result['response_error'], 157 'error_name' => $result['response_result']['name'], 158 'error_message' => $result['response_result']['detail'], 222 159 ); 223 160 } … … 271 208 'code' => $result['response_code'] ? $result['response_code'] : self::CODE_400, 272 209 'error' => 1, 273 'error_message' => $result['response_result']['name'], 210 'error_name' => $result['response_result']['name'], 211 'error_message' => $result['response_result']['detail'], 274 212 ); 275 213 } … … 314 252 'code' => $result['response_code'] ? $result['response_code'] : self::CODE_400, 315 253 'error' => 1, 316 'error_message' => $result['response_error'], 254 'error_name' => $result['response_result']['name'], 255 'error_message' => $result['response_result']['detail'], 317 256 ); 318 257 } … … 388 327 'response_code' => $responseCode, 389 328 'response_result' => $responseContent, 390 'response_error' => $this->getReasonPhrase($responseCode)391 329 ); 392 330 … … 398 336 } 399 337 } 400 401 private function getReasonPhrase($httpCode) {402 return self::$phrases[$httpCode];403 }404 338 }
Note: See TracChangeset
for help on using the changeset viewer.