@@ -10,144 +10,144 @@ |
||
| 10 | 10 | |
| 11 | 11 | class Trustalyze |
| 12 | 12 | { |
| 13 | - const API_URL = 'https://www.trustalyze.com/api/rbs/'; |
|
| 14 | - const WEB_URL = 'https://trustalyze.com/plans?ref=105'; |
|
| 13 | + const API_URL = 'https://www.trustalyze.com/api/rbs/'; |
|
| 14 | + const WEB_URL = 'https://trustalyze.com/plans?ref=105'; |
|
| 15 | 15 | |
| 16 | - public $message; |
|
| 17 | - public $response; |
|
| 18 | - public $success; |
|
| 16 | + public $message; |
|
| 17 | + public $response; |
|
| 18 | + public $success; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @return mixed |
|
| 22 | - */ |
|
| 23 | - public function __get($key) |
|
| 24 | - { |
|
| 25 | - return property_exists($this, $key) |
|
| 26 | - ? $this->$key |
|
| 27 | - : Arr::get($this->response, $key, null); |
|
| 28 | - } |
|
| 20 | + /** |
|
| 21 | + * @return mixed |
|
| 22 | + */ |
|
| 23 | + public function __get($key) |
|
| 24 | + { |
|
| 25 | + return property_exists($this, $key) |
|
| 26 | + ? $this->$key |
|
| 27 | + : Arr::get($this->response, $key, null); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @return self |
|
| 32 | - */ |
|
| 33 | - public function activateKey($apiKey = '', $email = '') |
|
| 34 | - { |
|
| 35 | - $this->send('api_key_activation.php', [ |
|
| 36 | - 'body' => [ |
|
| 37 | - 'apikey' => $apiKey ?: 0, |
|
| 38 | - 'domain' => get_home_url(), |
|
| 39 | - 'email' => $email ?: 0, |
|
| 40 | - ], |
|
| 41 | - ]); |
|
| 42 | - return $this; |
|
| 43 | - } |
|
| 30 | + /** |
|
| 31 | + * @return self |
|
| 32 | + */ |
|
| 33 | + public function activateKey($apiKey = '', $email = '') |
|
| 34 | + { |
|
| 35 | + $this->send('api_key_activation.php', [ |
|
| 36 | + 'body' => [ |
|
| 37 | + 'apikey' => $apiKey ?: 0, |
|
| 38 | + 'domain' => get_home_url(), |
|
| 39 | + 'email' => $email ?: 0, |
|
| 40 | + ], |
|
| 41 | + ]); |
|
| 42 | + return $this; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @return self |
|
| 47 | - */ |
|
| 48 | - public function reset() |
|
| 49 | - { |
|
| 50 | - $this->message = ''; |
|
| 51 | - $this->response = []; |
|
| 52 | - $this->success = false; |
|
| 53 | - return $this; |
|
| 54 | - } |
|
| 45 | + /** |
|
| 46 | + * @return self |
|
| 47 | + */ |
|
| 48 | + public function reset() |
|
| 49 | + { |
|
| 50 | + $this->message = ''; |
|
| 51 | + $this->response = []; |
|
| 52 | + $this->success = false; |
|
| 53 | + return $this; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @return self |
|
| 58 | - */ |
|
| 59 | - public function sendReview(Review $review) |
|
| 60 | - { |
|
| 61 | - $this->send('index.php', [ |
|
| 62 | - 'body' => $this->getBodyForReview($review), |
|
| 63 | - 'timeout' => 120, |
|
| 64 | - ]); |
|
| 65 | - return $this; |
|
| 66 | - } |
|
| 56 | + /** |
|
| 57 | + * @return self |
|
| 58 | + */ |
|
| 59 | + public function sendReview(Review $review) |
|
| 60 | + { |
|
| 61 | + $this->send('index.php', [ |
|
| 62 | + 'body' => $this->getBodyForReview($review), |
|
| 63 | + 'timeout' => 120, |
|
| 64 | + ]); |
|
| 65 | + return $this; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @return self |
|
| 70 | - */ |
|
| 71 | - public function sendReviewResponse(Review $review) |
|
| 72 | - { |
|
| 73 | - $this->send('fetch_customer_reply.php', [ |
|
| 74 | - 'body' => $this->getBodyForResponse($review), |
|
| 75 | - ]); |
|
| 76 | - return $this; |
|
| 77 | - } |
|
| 68 | + /** |
|
| 69 | + * @return self |
|
| 70 | + */ |
|
| 71 | + public function sendReviewResponse(Review $review) |
|
| 72 | + { |
|
| 73 | + $this->send('fetch_customer_reply.php', [ |
|
| 74 | + 'body' => $this->getBodyForResponse($review), |
|
| 75 | + ]); |
|
| 76 | + return $this; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * @return array |
|
| 81 | - */ |
|
| 82 | - protected function getBodyForResponse(Review $review) |
|
| 83 | - { |
|
| 84 | - $trustalyzeResponse = [ |
|
| 85 | - 'reply' => Str::truncate($review->response, 300), |
|
| 86 | - 'review_id' => glsr(Database::class)->get($review->ID, 'trustalyze'), // this is the trustalyze review ID |
|
| 87 | - 'review_transaction_id' => $review->review_id, |
|
| 88 | - 'type' => 'M', |
|
| 89 | - ]; |
|
| 90 | - return apply_filters('site-reviews/trustalyze/response', $trustalyzeResponse, $review); |
|
| 91 | - } |
|
| 79 | + /** |
|
| 80 | + * @return array |
|
| 81 | + */ |
|
| 82 | + protected function getBodyForResponse(Review $review) |
|
| 83 | + { |
|
| 84 | + $trustalyzeResponse = [ |
|
| 85 | + 'reply' => Str::truncate($review->response, 300), |
|
| 86 | + 'review_id' => glsr(Database::class)->get($review->ID, 'trustalyze'), // this is the trustalyze review ID |
|
| 87 | + 'review_transaction_id' => $review->review_id, |
|
| 88 | + 'type' => 'M', |
|
| 89 | + ]; |
|
| 90 | + return apply_filters('site-reviews/trustalyze/response', $trustalyzeResponse, $review); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * @return array |
|
| 95 | - */ |
|
| 96 | - protected function getBodyForReview(Review $review) |
|
| 97 | - { |
|
| 98 | - $trustalyzeReview = [ |
|
| 99 | - 'domain' => get_home_url(), |
|
| 100 | - 'firstname' => Str::truncate(Str::convertName($review->author, 'first'), 25), |
|
| 101 | - 'rate' => $review->rating, |
|
| 102 | - 'review_transaction_id' => $review->review_id, |
|
| 103 | - 'reviews' => Str::truncate($review->content, 280), |
|
| 104 | - 'sitereview_plugin' => 'yes', |
|
| 105 | - 'title' => Str::truncate($review->title, 35), |
|
| 106 | - 'transaction' => Application::ID, // woocommerce field, not needed for Site Reviews |
|
| 107 | - ]; |
|
| 108 | - return apply_filters('site-reviews/trustalyze/review', $trustalyzeReview, $review); |
|
| 109 | - } |
|
| 93 | + /** |
|
| 94 | + * @return array |
|
| 95 | + */ |
|
| 96 | + protected function getBodyForReview(Review $review) |
|
| 97 | + { |
|
| 98 | + $trustalyzeReview = [ |
|
| 99 | + 'domain' => get_home_url(), |
|
| 100 | + 'firstname' => Str::truncate(Str::convertName($review->author, 'first'), 25), |
|
| 101 | + 'rate' => $review->rating, |
|
| 102 | + 'review_transaction_id' => $review->review_id, |
|
| 103 | + 'reviews' => Str::truncate($review->content, 280), |
|
| 104 | + 'sitereview_plugin' => 'yes', |
|
| 105 | + 'title' => Str::truncate($review->title, 35), |
|
| 106 | + 'transaction' => Application::ID, // woocommerce field, not needed for Site Reviews |
|
| 107 | + ]; |
|
| 108 | + return apply_filters('site-reviews/trustalyze/review', $trustalyzeReview, $review); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * @param \WP_Error|array $response |
|
| 113 | - * @return void |
|
| 114 | - */ |
|
| 115 | - protected function handleResponse($response) |
|
| 116 | - { |
|
| 117 | - if (is_wp_error($response)) { |
|
| 118 | - $this->message = $response->get_error_message(); |
|
| 119 | - } else { |
|
| 120 | - $responseBody = wp_remote_retrieve_body($response); |
|
| 121 | - $responseCode = wp_remote_retrieve_response_code($response); |
|
| 122 | - $responseData = (array) json_decode($responseBody, true); |
|
| 123 | - $this->response = array_shift($responseData); |
|
| 124 | - $this->message = Arr::get($this->response, 'msg'); |
|
| 125 | - $this->success = 'success' === Arr::get($this->response, 'result') || 'yes' === Arr::get($this->response, 'success'); // @todo remove this ugly hack! |
|
| 126 | - if (200 !== $responseCode) { |
|
| 127 | - glsr_log()->error('Bad response code ['.$responseCode.']'); |
|
| 128 | - } |
|
| 129 | - if (!$this->success) { |
|
| 130 | - glsr_log()->error($this->message); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - } |
|
| 111 | + /** |
|
| 112 | + * @param \WP_Error|array $response |
|
| 113 | + * @return void |
|
| 114 | + */ |
|
| 115 | + protected function handleResponse($response) |
|
| 116 | + { |
|
| 117 | + if (is_wp_error($response)) { |
|
| 118 | + $this->message = $response->get_error_message(); |
|
| 119 | + } else { |
|
| 120 | + $responseBody = wp_remote_retrieve_body($response); |
|
| 121 | + $responseCode = wp_remote_retrieve_response_code($response); |
|
| 122 | + $responseData = (array) json_decode($responseBody, true); |
|
| 123 | + $this->response = array_shift($responseData); |
|
| 124 | + $this->message = Arr::get($this->response, 'msg'); |
|
| 125 | + $this->success = 'success' === Arr::get($this->response, 'result') || 'yes' === Arr::get($this->response, 'success'); // @todo remove this ugly hack! |
|
| 126 | + if (200 !== $responseCode) { |
|
| 127 | + glsr_log()->error('Bad response code ['.$responseCode.']'); |
|
| 128 | + } |
|
| 129 | + if (!$this->success) { |
|
| 130 | + glsr_log()->error($this->message); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * @param string $endpoint |
|
| 137 | - * @return void |
|
| 138 | - */ |
|
| 139 | - protected function send($endpoint, array $args = []) |
|
| 140 | - { |
|
| 141 | - $args = wp_parse_args($args, [ |
|
| 142 | - 'body' => null, |
|
| 143 | - 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'], |
|
| 144 | - 'redirection' => 5, |
|
| 145 | - 'sslverify' => false, |
|
| 146 | - 'timeout' => 5, |
|
| 147 | - ]); |
|
| 148 | - $this->reset(); |
|
| 149 | - $this->handleResponse( |
|
| 150 | - wp_remote_post(trailingslashit(static::API_URL).$endpoint, $args) |
|
| 151 | - ); |
|
| 152 | - } |
|
| 135 | + /** |
|
| 136 | + * @param string $endpoint |
|
| 137 | + * @return void |
|
| 138 | + */ |
|
| 139 | + protected function send($endpoint, array $args = []) |
|
| 140 | + { |
|
| 141 | + $args = wp_parse_args($args, [ |
|
| 142 | + 'body' => null, |
|
| 143 | + 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'], |
|
| 144 | + 'redirection' => 5, |
|
| 145 | + 'sslverify' => false, |
|
| 146 | + 'timeout' => 5, |
|
| 147 | + ]); |
|
| 148 | + $this->reset(); |
|
| 149 | + $this->handleResponse( |
|
| 150 | + wp_remote_post(trailingslashit(static::API_URL).$endpoint, $args) |
|
| 151 | + ); |
|
| 152 | + } |
|
| 153 | 153 | } |
@@ -20,25 +20,25 @@ discard block |
||
| 20 | 20 | /** |
| 21 | 21 | * @return mixed |
| 22 | 22 | */ |
| 23 | - public function __get($key) |
|
| 23 | + public function __get( $key ) |
|
| 24 | 24 | { |
| 25 | - return property_exists($this, $key) |
|
| 25 | + return property_exists( $this, $key ) |
|
| 26 | 26 | ? $this->$key |
| 27 | - : Arr::get($this->response, $key, null); |
|
| 27 | + : Arr::get( $this->response, $key, null ); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * @return self |
| 32 | 32 | */ |
| 33 | - public function activateKey($apiKey = '', $email = '') |
|
| 33 | + public function activateKey( $apiKey = '', $email = '' ) |
|
| 34 | 34 | { |
| 35 | - $this->send('api_key_activation.php', [ |
|
| 35 | + $this->send( 'api_key_activation.php', [ |
|
| 36 | 36 | 'body' => [ |
| 37 | 37 | 'apikey' => $apiKey ?: 0, |
| 38 | 38 | 'domain' => get_home_url(), |
| 39 | 39 | 'email' => $email ?: 0, |
| 40 | 40 | ], |
| 41 | - ]); |
|
| 41 | + ] ); |
|
| 42 | 42 | return $this; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -56,78 +56,78 @@ discard block |
||
| 56 | 56 | /** |
| 57 | 57 | * @return self |
| 58 | 58 | */ |
| 59 | - public function sendReview(Review $review) |
|
| 59 | + public function sendReview( Review $review ) |
|
| 60 | 60 | { |
| 61 | - $this->send('index.php', [ |
|
| 62 | - 'body' => $this->getBodyForReview($review), |
|
| 61 | + $this->send( 'index.php', [ |
|
| 62 | + 'body' => $this->getBodyForReview( $review ), |
|
| 63 | 63 | 'timeout' => 120, |
| 64 | - ]); |
|
| 64 | + ] ); |
|
| 65 | 65 | return $this; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * @return self |
| 70 | 70 | */ |
| 71 | - public function sendReviewResponse(Review $review) |
|
| 71 | + public function sendReviewResponse( Review $review ) |
|
| 72 | 72 | { |
| 73 | - $this->send('fetch_customer_reply.php', [ |
|
| 74 | - 'body' => $this->getBodyForResponse($review), |
|
| 75 | - ]); |
|
| 73 | + $this->send( 'fetch_customer_reply.php', [ |
|
| 74 | + 'body' => $this->getBodyForResponse( $review ), |
|
| 75 | + ] ); |
|
| 76 | 76 | return $this; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
| 80 | 80 | * @return array |
| 81 | 81 | */ |
| 82 | - protected function getBodyForResponse(Review $review) |
|
| 82 | + protected function getBodyForResponse( Review $review ) |
|
| 83 | 83 | { |
| 84 | 84 | $trustalyzeResponse = [ |
| 85 | - 'reply' => Str::truncate($review->response, 300), |
|
| 86 | - 'review_id' => glsr(Database::class)->get($review->ID, 'trustalyze'), // this is the trustalyze review ID |
|
| 85 | + 'reply' => Str::truncate( $review->response, 300 ), |
|
| 86 | + 'review_id' => glsr( Database::class )->get( $review->ID, 'trustalyze' ), // this is the trustalyze review ID |
|
| 87 | 87 | 'review_transaction_id' => $review->review_id, |
| 88 | 88 | 'type' => 'M', |
| 89 | 89 | ]; |
| 90 | - return apply_filters('site-reviews/trustalyze/response', $trustalyzeResponse, $review); |
|
| 90 | + return apply_filters( 'site-reviews/trustalyze/response', $trustalyzeResponse, $review ); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | 94 | * @return array |
| 95 | 95 | */ |
| 96 | - protected function getBodyForReview(Review $review) |
|
| 96 | + protected function getBodyForReview( Review $review ) |
|
| 97 | 97 | { |
| 98 | 98 | $trustalyzeReview = [ |
| 99 | 99 | 'domain' => get_home_url(), |
| 100 | - 'firstname' => Str::truncate(Str::convertName($review->author, 'first'), 25), |
|
| 100 | + 'firstname' => Str::truncate( Str::convertName( $review->author, 'first' ), 25 ), |
|
| 101 | 101 | 'rate' => $review->rating, |
| 102 | 102 | 'review_transaction_id' => $review->review_id, |
| 103 | - 'reviews' => Str::truncate($review->content, 280), |
|
| 103 | + 'reviews' => Str::truncate( $review->content, 280 ), |
|
| 104 | 104 | 'sitereview_plugin' => 'yes', |
| 105 | - 'title' => Str::truncate($review->title, 35), |
|
| 105 | + 'title' => Str::truncate( $review->title, 35 ), |
|
| 106 | 106 | 'transaction' => Application::ID, // woocommerce field, not needed for Site Reviews |
| 107 | 107 | ]; |
| 108 | - return apply_filters('site-reviews/trustalyze/review', $trustalyzeReview, $review); |
|
| 108 | + return apply_filters( 'site-reviews/trustalyze/review', $trustalyzeReview, $review ); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
| 112 | 112 | * @param \WP_Error|array $response |
| 113 | 113 | * @return void |
| 114 | 114 | */ |
| 115 | - protected function handleResponse($response) |
|
| 115 | + protected function handleResponse( $response ) |
|
| 116 | 116 | { |
| 117 | - if (is_wp_error($response)) { |
|
| 117 | + if( is_wp_error( $response ) ) { |
|
| 118 | 118 | $this->message = $response->get_error_message(); |
| 119 | 119 | } else { |
| 120 | - $responseBody = wp_remote_retrieve_body($response); |
|
| 121 | - $responseCode = wp_remote_retrieve_response_code($response); |
|
| 122 | - $responseData = (array) json_decode($responseBody, true); |
|
| 123 | - $this->response = array_shift($responseData); |
|
| 124 | - $this->message = Arr::get($this->response, 'msg'); |
|
| 125 | - $this->success = 'success' === Arr::get($this->response, 'result') || 'yes' === Arr::get($this->response, 'success'); // @todo remove this ugly hack! |
|
| 126 | - if (200 !== $responseCode) { |
|
| 127 | - glsr_log()->error('Bad response code ['.$responseCode.']'); |
|
| 120 | + $responseBody = wp_remote_retrieve_body( $response ); |
|
| 121 | + $responseCode = wp_remote_retrieve_response_code( $response ); |
|
| 122 | + $responseData = (array)json_decode( $responseBody, true ); |
|
| 123 | + $this->response = array_shift( $responseData ); |
|
| 124 | + $this->message = Arr::get( $this->response, 'msg' ); |
|
| 125 | + $this->success = 'success' === Arr::get( $this->response, 'result' ) || 'yes' === Arr::get( $this->response, 'success' ); // @todo remove this ugly hack! |
|
| 126 | + if( 200 !== $responseCode ) { |
|
| 127 | + glsr_log()->error( 'Bad response code ['.$responseCode.']' ); |
|
| 128 | 128 | } |
| 129 | - if (!$this->success) { |
|
| 130 | - glsr_log()->error($this->message); |
|
| 129 | + if( !$this->success ) { |
|
| 130 | + glsr_log()->error( $this->message ); |
|
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | } |
@@ -136,18 +136,18 @@ discard block |
||
| 136 | 136 | * @param string $endpoint |
| 137 | 137 | * @return void |
| 138 | 138 | */ |
| 139 | - protected function send($endpoint, array $args = []) |
|
| 139 | + protected function send( $endpoint, array $args = [] ) |
|
| 140 | 140 | { |
| 141 | - $args = wp_parse_args($args, [ |
|
| 141 | + $args = wp_parse_args( $args, [ |
|
| 142 | 142 | 'body' => null, |
| 143 | 143 | 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'], |
| 144 | 144 | 'redirection' => 5, |
| 145 | 145 | 'sslverify' => false, |
| 146 | 146 | 'timeout' => 5, |
| 147 | - ]); |
|
| 147 | + ] ); |
|
| 148 | 148 | $this->reset(); |
| 149 | 149 | $this->handleResponse( |
| 150 | - wp_remote_post(trailingslashit(static::API_URL).$endpoint, $args) |
|
| 150 | + wp_remote_post( trailingslashit( static::API_URL ).$endpoint, $args ) |
|
| 151 | 151 | ); |
| 152 | 152 | } |
| 153 | 153 | } |