├── .github └── workflows │ └── php.yml ├── .gitignore ├── LICENSE ├── README.md ├── composer.json ├── example.php └── src ├── Eskiz.php ├── client ├── Client.php └── ClientInterface.php ├── components └── NormalizerTrait.php ├── request ├── AbstractRequest.php ├── RequestInterface.php ├── auth │ ├── AuthInvalidateRequest.php │ ├── AuthLoginRequest.php │ ├── AuthRefreshRequest.php │ └── AuthUserRequest.php └── sms │ ├── SmsGetDispatchStatusRequest.php │ ├── SmsGetUserMessagesByDispatchRequest.php │ ├── SmsSendBatchRequest.php │ └── SmsSendRequest.php ├── response ├── AbstractResponse.php ├── ResponseInterface.php ├── auth │ ├── AuthInvalidateResponse.php │ ├── AuthLoginResponse.php │ ├── AuthRefreshResponse.php │ └── AuthUserResponse.php └── sms │ ├── SmsGetDispatchStatusDataItemResponse.php │ ├── SmsGetDispatchStatusResponse.php │ ├── SmsGetUserMessagesByDispatchDataItemResponse.php │ ├── SmsGetUserMessagesByDispatchLinksResponse.php │ ├── SmsGetUserMessagesByDispatchResponse.php │ ├── SmsSendBatchResponse.php │ └── SmsSendResponse.php └── types ├── TypeInterface.php ├── auth └── AuthLoginType.php └── sms ├── SmsBatchMessageType.php ├── SmsBatchSmsType.php ├── SmsGetDispatchStatusType.php ├── SmsGetUserMessagesByDispatchType.php └── SmsSingleSmsType.php /.github/workflows/php.yml: -------------------------------------------------------------------------------- 1 | name: PHP Composer 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | 9 | permissions: 10 | contents: read 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | 20 | - name: Validate composer.json and composer.lock 21 | run: composer validate --strict 22 | 23 | - name: Cache Composer packages 24 | id: composer-cache 25 | uses: actions/cache@v3 26 | with: 27 | path: vendor 28 | key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} 29 | restore-keys: | 30 | ${{ runner.os }}-php- 31 | 32 | - name: Install dependencies 33 | run: composer install --prefer-dist --no-progress 34 | 35 | # Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" 36 | # Docs: https://getcomposer.org/doc/articles/scripts.md 37 | 38 | # - name: Run test suite 39 | # run: composer run-script test 40 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | .idea 3 | .vscode 4 | .DS_Store 5 | 6 | composer.lock 7 | *.local.php -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Bahriddin Mo'minov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PHP Eskiz.uz 2 | ============ 3 | 4 | PHP Eskiz.uz SMS Gateway package 5 | 6 | ## Installation 7 | 8 | ```bash 9 | composer require mrmuminov/php-eskiz-uz "^2.0.0" 10 | ``` 11 | 12 | or add the following to your `composer.json` file: 13 | 14 | ```json 15 | { 16 | "require": { 17 | "mrmuminov/php-eskiz-uz": "^2.0.0" 18 | } 19 | } 20 | ``` 21 | > If you need version 5.6 of php, check out older versions. 22 | > For example [this](https://github.com/mrmuminov/php-eskiz-uz/tree/ab0ffc112dbdaccc8c114e647db16c8214621a7b) 23 | 24 | ## Usage 25 | 26 | --- 27 | 28 | Open [example.php](example.php) file 29 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mrmuminov/php-eskiz-uz", 3 | "description": "PHP Eskiz.uz SMS Gateway package", 4 | "type": "library", 5 | "keywords": [ 6 | "php", 7 | "sms", 8 | "shlyuz", 9 | "gateway", 10 | "eskiz" 11 | ], 12 | "license": "MIT", 13 | "authors": [ 14 | { 15 | "name": "Bahriddin Mo'minov", 16 | "email": "darkshadeuz@gmail.com" 17 | } 18 | ], 19 | "require": { 20 | "php": "^8.0", 21 | "ext-curl": "*", 22 | "ext-json": "*" 23 | }, 24 | "autoload": { 25 | "psr-4": { 26 | "mrmuminov\\eskizuz\\": "src" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /example.php: -------------------------------------------------------------------------------- 1 | '; 22 | $message = ''; 23 | $mobile_phone = ''; 24 | $user_sms_id = ''; 25 | $callback_url = ''; 26 | $dispatch_id = ''; 27 | $user_id = ''; 28 | 29 | /** 30 | * First, you need to create a new Eskiz object with email and password. 31 | */ 32 | $auth = $eskiz->requestAuthLogin(); 33 | 34 | /** 35 | * First, you need to create a new Eskiz object with email and password. 36 | * gateway-number is the number you want to send the SMS to. Default is 4649. 37 | */ 38 | $singleSmsType = new SmsSingleSmsType( 39 | from: $from, 40 | message: $message, 41 | mobile_phone: $mobile_phone, 42 | user_sms_id: $user_sms_id, 43 | callback_url: $callback_url, 44 | ); 45 | $sendSingleSms = $eskiz->requestSmsSend($singleSmsType); 46 | 47 | /** 48 | * First, you need to create a new Eskiz object with email and password. 49 | * gateway-number is the number you want to send the SMS to. Default is 4649. 50 | * your-message is special message to number. 51 | * your-message-to-all-numbers is special message to all numbers (if message is empty). 52 | */ 53 | $batchSmsType = new SmsBatchSmsType( 54 | from: $from, 55 | messages: [ 56 | new SmsBatchMessageType( 57 | to: $mobile_phone, 58 | message: $message, 59 | user_sms_id: $user_sms_id, 60 | ), 61 | ], 62 | dispatch_id: $dispatch_id 63 | ); 64 | $sendBatchSms = $eskiz->requestSmsSendBatch($batchSmsType); 65 | 66 | /** 67 | * First, you need to create a new Eskiz object with email and password. 68 | * gateway-number is the number you want to send the SMS to. Default is 4649. 69 | * dispatch-id is batch sms identity. 70 | * user-id Options, send user id. 71 | */ 72 | $getUserMessagesByDispatchType = new SmsGetUserMessagesByDispatchType( 73 | dispatch_id: $dispatch_id, 74 | user_id: $user_id, 75 | ); 76 | $getBatchSmsStatus = $eskiz->requestGetUserMessagesByDispatch($getUserMessagesByDispatchType); 77 | 78 | /** $firstPageResponse The first page of the response. One page contains 15 messages. */ 79 | $firstPageResponse = $getBatchSmsStatus->getResponse(); 80 | 81 | /** Fetching the next page of the response. */ 82 | $getBatchSmsStatus->fetchNextPage(); 83 | 84 | /** The second page of the response. One page contains 15 messages. */ 85 | $secondPageResponse = $getBatchSmsStatus->getResponse(); -------------------------------------------------------------------------------- /src/Eskiz.php: -------------------------------------------------------------------------------- 1 | clientClass)) { 74 | throw new RuntimeException('Client class not found'); 75 | } 76 | $this->client = new $this->clientClass( 77 | baseUrl: $this->baseUrl, 78 | ); 79 | $this->email = $email; 80 | $this->password = $password; 81 | } 82 | 83 | /** 84 | * @throws Exception 85 | */ 86 | public function requestAuthLogin(): AuthLoginRequest 87 | { 88 | $type = new AuthLoginType(); 89 | $type->email = $this->email; 90 | $type->password = $this->password; 91 | $request = new AuthLoginRequest($this->getClient(), $type->toArray()); 92 | if (empty($request->getResponse()->token)) { 93 | throw new Exception($request->getResponse()->message, 5); 94 | } 95 | $this->token = $request->getResponse()->token; 96 | return $request; 97 | } 98 | 99 | public function getClient(): ClientInterface 100 | { 101 | if (!$this->client) { 102 | if (!class_exists($this->clientClass)) { 103 | throw new RuntimeException('Client class not found'); 104 | } 105 | 106 | $this->client = new $this->clientClass($this->baseUrl); 107 | } 108 | return $this->client; 109 | } 110 | 111 | public function requestAuthInvalidate(): AuthInvalidateRequest 112 | { 113 | return new AuthInvalidateRequest($this->getClient(), [], [ 114 | 'Authorization' => 'Bearer ' . $this->getToken(), 115 | ]); 116 | } 117 | 118 | public function getToken(): string 119 | { 120 | if (!$this->token) { 121 | throw new RuntimeException('Token not found'); 122 | } 123 | return $this->token; 124 | } 125 | 126 | public function requestAuthRefresh(): AuthRefreshRequest 127 | { 128 | return new AuthRefreshRequest($this->getClient(), [], [ 129 | 'Authorization' => 'Bearer ' . $this->getToken(), 130 | ]); 131 | } 132 | 133 | public function requestAuthUser(): AuthUserRequest 134 | { 135 | return new AuthUserRequest($this->getClient(), [], [ 136 | 'Authorization' => 'Bearer ' . $this->getToken(), 137 | ]); 138 | } 139 | 140 | 141 | public function requestSmsSend(SmsSingleSmsType $type): SmsSendRequest 142 | { 143 | return new SmsSendRequest($this->getClient(), $type->toArray(), [ 144 | 'Authorization' => 'Bearer ' . $this->getToken(), 145 | ]); 146 | } 147 | 148 | public function requestSmsSendBatch(SmsBatchSmsType $type): SmsSendBatchRequest 149 | { 150 | return new SmsSendBatchRequest($this->getClient(), $type->toArray(), [ 151 | 'Authorization' => 'Bearer ' . $this->getToken(), 152 | 'Content-Type' => 'application/json', 153 | ]); 154 | } 155 | 156 | public function requestGetDispatchStatus(SmsGetDispatchStatusType $type): SmsGetDispatchStatusRequest 157 | { 158 | return new SmsGetDispatchStatusRequest($this->getClient(), $type->toArray(), [ 159 | 'Authorization' => 'Bearer ' . $this->getToken(), 160 | 'Content-Type' => 'multipart/form-data', 161 | ]); 162 | } 163 | 164 | public function requestGetUserMessagesByDispatch(SmsGetUserMessagesByDispatchType $type): SmsGetUserMessagesByDispatchRequest 165 | { 166 | return new SmsGetUserMessagesByDispatchRequest($this->getClient(), $type->toArray(), [ 167 | 'Authorization' => 'Bearer ' . $this->getToken(), 168 | 'Content-Type' => 'multipart/form-data', 169 | ]); 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /src/client/Client.php: -------------------------------------------------------------------------------- 1 | request($action, $params, 'DELETE', $headers); 23 | } 24 | 25 | public function get($action, array $headers = []): Client 26 | { 27 | return $this->request($action, [], 'GET', $headers); 28 | } 29 | 30 | public function request($action, $params, $method, array $headers = []): Client 31 | { 32 | $curl = curl_init(); 33 | $options = [ 34 | CURLOPT_URL => $this->baseUrl . $action, 35 | CURLOPT_RETURNTRANSFER => true, 36 | CURLOPT_ENCODING => '', 37 | CURLOPT_MAXREDIRS => 10, 38 | CURLOPT_TIMEOUT => 0, 39 | CURLOPT_FOLLOWLOCATION => true, 40 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 41 | CURLOPT_CUSTOMREQUEST => $method, 42 | CURLOPT_HTTPHEADER => array_map(static function($key, $value) { 43 | return $key . ': ' . $value; 44 | }, array_keys($headers), $headers), 45 | ]; 46 | if (in_array($method, ['POST', 'PUT', 'DELETE'])) { 47 | $options[CURLOPT_POSTFIELDS] = $params; 48 | } 49 | curl_setopt_array($curl, $options); 50 | 51 | $response = curl_exec($curl); 52 | try { 53 | $this->response = json_decode($response, false); 54 | } catch (Exception $e) { 55 | $this->response = $response; 56 | } 57 | $this->statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); 58 | curl_close($curl); 59 | return $this; 60 | } 61 | 62 | public function getResponse(): mixed 63 | { 64 | return $this->response; 65 | } 66 | 67 | public function getStatusCode(): int 68 | { 69 | return $this->statusCode; 70 | } 71 | 72 | public function patch($action, $params = [], array $headers = []): Client 73 | { 74 | return $this->request($action, $params, 'PATCH', $headers); 75 | } 76 | 77 | public function post($action, $params = [], array $headers = []): Client 78 | { 79 | return $this->request($action, $params, 'POST', $headers); 80 | } 81 | 82 | public function put($action, $params = [], array $headers = []): Client 83 | { 84 | return $this->request($action, $params, 'PUT', $headers); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/client/ClientInterface.php: -------------------------------------------------------------------------------- 1 | action; 17 | } 18 | 19 | public function setAction(string $action): void 20 | { 21 | $this->action = $action; 22 | } 23 | 24 | public function getResponse(): mixed 25 | { 26 | return $this->response; 27 | } 28 | 29 | public function setResponse(mixed $response): void 30 | { 31 | $this->response = $response; 32 | } 33 | 34 | public function getResponseClass(): string 35 | { 36 | return $this->responseClass; 37 | } 38 | 39 | public function setResponseClass(string $responseClass): void 40 | { 41 | $this->responseClass = $responseClass; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/request/RequestInterface.php: -------------------------------------------------------------------------------- 1 | delete($this->action, [], $headers); 22 | $this->setResponse(new $this->responseClass($request)); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/request/auth/AuthLoginRequest.php: -------------------------------------------------------------------------------- 1 | post($this->action, $type, $headers); 22 | $this->setResponse(new $this->responseClass($request)); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/request/auth/AuthRefreshRequest.php: -------------------------------------------------------------------------------- 1 | patch($this->action, [], $headers); 22 | $this->setResponse(new $this->responseClass($request)); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/request/auth/AuthUserRequest.php: -------------------------------------------------------------------------------- 1 | get($this->action, $headers); 22 | $this->setResponse(new $this->responseClass($request)); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/request/sms/SmsGetDispatchStatusRequest.php: -------------------------------------------------------------------------------- 1 | post($this->action, $type, $headers); 21 | $this->setResponse(new $this->responseClass($request)); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/request/sms/SmsGetUserMessagesByDispatchRequest.php: -------------------------------------------------------------------------------- 1 | "This is a first page", 24 | 'last_page' => "This is a last page", 25 | ]; 26 | 27 | public function __construct(ClientInterface $client, array $type, array $headers = []) 28 | { 29 | $this->client = $client; 30 | $this->type = $type; 31 | $this->headers = $headers; 32 | $request = $client->post($this->action, $this->type, $this->headers); 33 | $this->setResponse(new $this->responseClass($request)); 34 | } 35 | 36 | public function fetchFirstPage() 37 | { 38 | $request = $this->client->post($this->action . '?page=1', $this->type, $this->headers); 39 | $this->setResponse(new $this->responseClass($request)); 40 | } 41 | 42 | public function fetchLastPage() 43 | { 44 | $request = $this->client->post($this->action . '?page=' . $this->response->last_page, $this->type, $this->headers); 45 | $this->setResponse(new $this->responseClass($request)); 46 | } 47 | 48 | public function fetchNextPage() 49 | { 50 | if ($this->response->current_page < $this->response->total) { 51 | $next = $this->response->current_page + 1; 52 | $request = $this->client->post($this->action . '?page=' . $next, $this->type, $this->headers); 53 | $this->setResponse(new $this->responseClass($request)); 54 | } else { 55 | $response = $this->response; 56 | $response->clear($this->errorMessages['last_page']); 57 | $this->setResponse($response); 58 | } 59 | } 60 | 61 | public function fetchPrevPage() 62 | { 63 | if ($this->response->current_page > 1) { 64 | $prev = $this->response->current_page - 1; 65 | $request = $this->client->post($this->action . '?page=' . $prev, $this->type, $this->headers); 66 | $this->setResponse(new $this->responseClass($request)); 67 | } else { 68 | $response = $this->response; 69 | $response->clear($this->errorMessages['first_page']); 70 | $this->setResponse($response); 71 | } 72 | } 73 | 74 | public function fetchPage($page) 75 | { 76 | $request = $this->client->post($this->action . '?page=' . $page, $this->type, $this->headers); 77 | $this->setResponse(new $this->responseClass($request)); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/request/sms/SmsSendBatchRequest.php: -------------------------------------------------------------------------------- 1 | post($this->action, json_encode($type), $headers); 22 | $this->setResponse(new $this->responseClass($request)); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/request/sms/SmsSendRequest.php: -------------------------------------------------------------------------------- 1 | post($this->action, $type, $headers); 22 | $this->setResponse(new $this->responseClass($client)); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/response/AbstractResponse.php: -------------------------------------------------------------------------------- 1 | client = &$client; 20 | $this->message = $client->getResponse()->message; 21 | if ($client->getStatusCode() === 200) { 22 | $this->isSuccess = true; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/response/auth/AuthLoginResponse.php: -------------------------------------------------------------------------------- 1 | client = &$client; 22 | $this->message = $client->getResponse()->message; 23 | if ($client->getStatusCode() === 200) { 24 | $this->token = $client->getResponse()->data->token; 25 | $this->isSuccess = true; 26 | } 27 | } 28 | 29 | public function getToken(): string 30 | { 31 | return $this->token; 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /src/response/auth/AuthRefreshResponse.php: -------------------------------------------------------------------------------- 1 | client = &$client; 20 | $this->message = $client->getResponse()->message; 21 | if ($client->getStatusCode() === 200) { 22 | $this->isSuccess = true; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/response/auth/AuthUserResponse.php: -------------------------------------------------------------------------------- 1 | client = &$client; 33 | if ($client->getStatusCode() === 200) { 34 | $this->isSuccess = true; 35 | $this->id = $client->getResponse()->id; 36 | $this->name = $client->getResponse()->name; 37 | $this->email = $client->getResponse()->email; 38 | $this->role = $client->getResponse()->role; 39 | $this->api_token = $client->getResponse()->api_token; 40 | $this->status = $client->getResponse()->status; 41 | $this->sms_api_login = $client->getResponse()->sms_api_login; 42 | $this->sms_api_password = $client->getResponse()->sms_api_password; 43 | $this->uz_price = $client->getResponse()->uz_price; 44 | $this->balance = $client->getResponse()->balance; 45 | $this->is_vip = $client->getResponse()->is_vip; 46 | $this->host = $client->getResponse()->host; 47 | $this->created_at = $client->getResponse()->created_at; 48 | $this->updated_at = $client->getResponse()->updated_at; 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /src/response/sms/SmsGetDispatchStatusDataItemResponse.php: -------------------------------------------------------------------------------- 1 | getStatusCode() === 200 && $client->getResponse()->status === self::ESKIS_STATUS_SUCCESS) { 29 | $this->status = (string)$client->getResponse()->status; 30 | $this->unSerializeData($client->getResponse()->data); 31 | $this->isSuccess = true; 32 | } else { 33 | $this->isSuccess = false; 34 | } 35 | } 36 | 37 | /** 38 | * @param $data 39 | * @return void 40 | * @throws Exception 41 | */ 42 | public function unSerializeData($data): void 43 | { 44 | if (is_array($data)) { 45 | $this->data = []; 46 | foreach ($data as $i => $item) { 47 | $this->data[$i] = new SmsGetDispatchStatusDataItemResponse( 48 | total: $this->data[$i]['total'] ?? '', 49 | status: $this->data[$i]['status'] ?? '', 50 | ); 51 | } 52 | } 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /src/response/sms/SmsGetUserMessagesByDispatchDataItemResponse.php: -------------------------------------------------------------------------------- 1 | getStatusCode() === 200) { 52 | $this->isSuccess = true; 53 | $data = $client->getResponse()->data; 54 | $this->current_page = $data->current_page; 55 | $this->unSerializeData($data->data); 56 | $this->first_page_url = $data->first_page_url; 57 | $this->from = $data->from; 58 | $this->last_page = $data->last_page; 59 | $this->last_page_url = $data->last_page_url; 60 | $this->unSerializeLinks($data->links); 61 | $this->next_page_url = $data->next_page_url; 62 | $this->path = $data->path; 63 | $this->per_page = $data->per_page; 64 | $this->prev_page_url = $data->prev_page_url; 65 | $this->to = $data->to; 66 | $this->total = $data->total; 67 | } else { 68 | $this->isSuccess = false; 69 | $this->status = $client->getResponse()->status; 70 | $this->message = ""; 71 | foreach ($client->getResponse()->message as $messages) { 72 | $this->message .= implode("\n", $messages) . "\n"; 73 | } 74 | } 75 | } 76 | 77 | public function unSerializeData(array $data): void 78 | { 79 | $this->data = []; 80 | foreach ($data as $i => $item) { 81 | $this->data[$i] = new SmsGetUserMessagesByDispatchDataItemResponse( 82 | id: $item?->id ?? '', 83 | user_id: $item?->user_id ?? '', 84 | dispatch_id: $item?->dispatch_id ?? '', 85 | jasmin_id: $item?->jasmin_id ?? '', 86 | user_sms_id: $item?->user_sms_id ?? '', 87 | price: $item?->price ?? '', 88 | country_code: $item?->country_code ?? '', 89 | operator: $item?->operator ?? '', 90 | nickname: $item?->nickname ?? '', 91 | to: $item?->to ?? '', 92 | content: $item?->content ?? '', 93 | packets: $item?->packets ?? '', 94 | msg_type: $item?->msg_type ?? '', 95 | is_balanced: $item?->is_balanced ?? '', 96 | callback_url: $item?->callback_url ?? '', 97 | status: $item?->status ?? '', 98 | status_date: $item?->status_date ?? '', 99 | created_at: $item?->created_at ?? '', 100 | updated_at: $item?->updated_at ?? '', 101 | ); 102 | } 103 | } 104 | 105 | private function unSerializeLinks(array $data): void 106 | { 107 | $this->links = []; 108 | foreach ($data as $i => $item) { 109 | $this->links[$i] = new SmsGetUserMessagesByDispatchLinksResponse( 110 | url: $item?->url ?? '', 111 | label: $item?->label ?? '', 112 | active: $item?->active ?? false, 113 | ); 114 | } 115 | } 116 | 117 | public function clear(string $message = ''): void 118 | { 119 | $this->isSuccess = false; 120 | $this->current_page = null; 121 | $this->data = []; 122 | $this->first_page_url = null; 123 | $this->from = null; 124 | $this->last_page = null; 125 | $this->last_page_url = null; 126 | $this->links = []; 127 | $this->next_page_url = null; 128 | $this->path = null; 129 | $this->per_page = null; 130 | $this->prev_page_url = null; 131 | $this->to = null; 132 | $this->total = null; 133 | $this->message = $message; 134 | } 135 | } -------------------------------------------------------------------------------- /src/response/sms/SmsSendBatchResponse.php: -------------------------------------------------------------------------------- 1 | message = $client->getResponse()->message; 21 | if ($client->getStatusCode() === 200) { 22 | $this->status = (string)$client->getResponse()->status; 23 | $this->isSuccess = true; 24 | } 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /src/response/sms/SmsSendResponse.php: -------------------------------------------------------------------------------- 1 | message = $client->getResponse()->message; 22 | if ($client->getStatusCode() === 200) { 23 | $this->id = (string)$client->getResponse()->id; 24 | $this->status = $client->getResponse()->status; 25 | $this->isSuccess = true; 26 | } 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /src/types/TypeInterface.php: -------------------------------------------------------------------------------- 1 | validateArguments()) { 19 | return [ 20 | 'email' => $this->email, 21 | 'password' => $this->password, 22 | ]; 23 | } 24 | return false; 25 | } 26 | 27 | public function validateArguments(): bool 28 | { 29 | if (empty($this->email)) { 30 | throw new InvalidArgumentException('Email is required'); 31 | } 32 | if (empty($this->password)) { 33 | throw new InvalidArgumentException('Email is required'); 34 | } 35 | return true; 36 | } 37 | } -------------------------------------------------------------------------------- /src/types/sms/SmsBatchMessageType.php: -------------------------------------------------------------------------------- 1 | validateArguments()) { 28 | return [ 29 | 'text' => $this->message, 30 | 'user_sms_id' => $this->userSmsIdNormalize($this->user_sms_id), 31 | 'to' => $this->phoneNormalise($this->to), 32 | ]; 33 | } 34 | return false; 35 | } 36 | 37 | public function validateArguments(): bool 38 | { 39 | if (empty($this->to)) { 40 | throw new InvalidArgumentException("`to` is empty"); 41 | } 42 | if (empty($this->message)) { 43 | throw new InvalidArgumentException("`message` is empty"); 44 | } 45 | if (empty($this->user_sms_id)) { 46 | throw new InvalidArgumentException("`user_sms_id` is empty"); 47 | } 48 | return true; 49 | } 50 | } -------------------------------------------------------------------------------- /src/types/sms/SmsBatchSmsType.php: -------------------------------------------------------------------------------- 1 | validateArguments()) { 26 | $messages = []; 27 | foreach ($this->messages as $message) { 28 | /**@var SmsBatchMessageType $message */ 29 | $messages[] = $message->toArray(); 30 | } 31 | return [ 32 | 'from' => $this->from, 33 | 'messages' => $messages, 34 | 'dispatch_id' => $this->dispatch_id, 35 | ]; 36 | } 37 | return false; 38 | } 39 | 40 | public function validateArguments(): bool 41 | { 42 | if (empty($this->from)) { 43 | throw new InvalidArgumentException("`from` is empty"); 44 | } 45 | if (empty($this->messages)) { 46 | throw new InvalidArgumentException("`messages` is empty"); 47 | } 48 | if (empty($this->dispatch_id)) { 49 | throw new InvalidArgumentException("`dispatch_id` is empty"); 50 | } 51 | return true; 52 | } 53 | } -------------------------------------------------------------------------------- /src/types/sms/SmsGetDispatchStatusType.php: -------------------------------------------------------------------------------- 1 | validateArguments()) { 24 | $options = [ 25 | 'dispatch_id' => $this->dispatch_id, 26 | ]; 27 | if ($this->user_id) { 28 | $options['user_id'] = $this->user_id; 29 | } 30 | return $options; 31 | } 32 | return false; 33 | } 34 | 35 | public function validateArguments(): bool 36 | { 37 | if (empty($this->dispatch_id)) { 38 | throw new InvalidArgumentException("`dispatch_id` is empty"); 39 | } 40 | return true; 41 | } 42 | } -------------------------------------------------------------------------------- /src/types/sms/SmsGetUserMessagesByDispatchType.php: -------------------------------------------------------------------------------- 1 | validateArguments()) { 23 | $options = [ 24 | 'dispatch_id' => $this->dispatch_id, 25 | ]; 26 | if ($this->user_id) { 27 | $options['user_id'] = $this->user_id; 28 | } 29 | return $options; 30 | } 31 | return false; 32 | } 33 | 34 | public function validateArguments(): bool 35 | { 36 | if (empty($this->dispatch_id)) { 37 | throw new InvalidArgumentException("`dispatch_id` is empty"); 38 | } 39 | return true; 40 | } 41 | } -------------------------------------------------------------------------------- /src/types/sms/SmsSingleSmsType.php: -------------------------------------------------------------------------------- 1 | validateArguments()) { 30 | $options = [ 31 | 'from' => $this->from, 32 | 'message' => $this->message, 33 | 'user_sms_id' => $this->userSmsIdNormalize($this->user_sms_id), 34 | 'mobile_phone' => $this->phoneNormalise($this->mobile_phone), 35 | 'callback_url' => $this->callback_url, 36 | ]; 37 | if (empty($options['callback_url'])) { 38 | unset($options['callback_url']); 39 | } 40 | return $options; 41 | } 42 | return false; 43 | } 44 | 45 | public function validateArguments(): bool 46 | { 47 | if (empty($this->from)) { 48 | throw new InvalidArgumentException("`from` is empty"); 49 | } 50 | if (empty($this->message)) { 51 | throw new InvalidArgumentException("`message` is empty"); 52 | } 53 | if (empty($this->user_sms_id)) { 54 | throw new InvalidArgumentException("`user_sms_id` is empty"); 55 | } 56 | if (empty($this->mobile_phone)) { 57 | throw new InvalidArgumentException("`mobile_phone` is empty"); 58 | } 59 | return true; 60 | } 61 | } --------------------------------------------------------------------------------