| 1 |
<?php |
| 2 |
|
| 3 |
namespace SyncBasalam\Services; |
| 4 |
|
| 5 |
use SyncBasalam\Config\Endpoints; |
| 6 |
use SyncBasalam\Logger\Logger; |
| 7 |
|
| 8 |
defined('ABSPATH') || exit; |
| 9 |
|
| 10 |
class BasalamAppStoreReview |
| 11 |
{ |
| 12 |
private string $BasalamAppReviewUrl; |
| 13 |
private $apiService; |
| 14 |
|
| 15 |
public function __construct() |
| 16 |
{ |
| 17 |
$this->BasalamAppReviewUrl = Endpoints::APP_REVIEW; |
| 18 |
$this->apiService = syncBasalamContainer()->get(ApiServiceManager::class); |
| 19 |
} |
| 20 |
|
| 21 |
public function createReview($comment, $rating = 5) |
| 22 |
{ |
| 23 |
$rating = intval($rating); |
| 24 |
if ($rating < 1) $rating = 1; |
| 25 |
if ($rating > 5) $rating = 5; |
| 26 |
|
| 27 |
$body = [ |
| 28 |
"comment" => $comment, |
| 29 |
"rating" => $rating, |
| 30 |
]; |
| 31 |
|
| 32 |
try { |
| 33 |
return $this->apiService->post($this->BasalamAppReviewUrl, $body); |
| 34 |
} catch (\Exception $e) { |
| 35 |
Logger::error('خطا در ثبت نظر افزونه: ' . $e->getMessage()); |
| 36 |
return [ |
| 37 |
'status_code' => 500, |
| 38 |
'body' => null, |
| 39 |
'error' => 'خطا در ثبت نظر: ' . $e->getMessage(), |
| 40 |
]; |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
|