|
1 | 1 | <img src="https://www.seven.io/wp-content/uploads/Logo.svg" width="250" /> |
2 | 2 |
|
3 | | -# Official PHP API Client |
| 3 | +# seven.io PHP SDK |
4 | 4 |
|
5 | | -## Installation |
| 5 | +[](https://packagist.org/packages/seven.io/api) |
| 6 | +[](https://packagist.org/packages/seven.io/api) |
| 7 | +[](LICENSE) |
| 8 | +[](https://packagist.org/packages/seven.io/api) |
6 | 9 |
|
7 | | -**Via Composer:** |
| 10 | +**The official PHP SDK for the seven.io SMS Gateway API** |
8 | 11 |
|
9 | | -```shell script |
| 12 | +[Documentation](https://www.seven.io/en/docs/gateway/http-api/) β’ [API Reference](/docs) β’ [Support](https://www.seven.io/en/company/contact/) β’ [Dashboard](https://app.seven.io/) |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +## π¦ Installation |
| 17 | + |
| 18 | +### Via Composer (recommended) |
| 19 | + |
| 20 | +```bash |
10 | 21 | composer require seven.io/api |
11 | 22 | ``` |
12 | 23 |
|
13 | | -Alternatively you |
14 | | -can [download as *.ZIP](https://github.com/seven-io/php-client/releases/latest "download as *.ZIP") |
15 | | -if you don't use Composer. |
| 24 | +### Manual Installation |
| 25 | + |
| 26 | +Download the latest release as [ZIP file](https://github.com/seven-io/php-client/releases/latest) and include it in your project. |
16 | 27 |
|
17 | | -### Usage |
| 28 | +## π Quick Start |
| 29 | + |
| 30 | +### Send your first SMS |
18 | 31 |
|
19 | 32 | ```php |
| 33 | +<?php |
| 34 | +require 'vendor/autoload.php'; |
| 35 | + |
20 | 36 | use Seven\Api\Client; |
21 | 37 | use Seven\Api\Resource\Sms\SmsParams; |
22 | 38 | use Seven\Api\Resource\Sms\SmsResource; |
23 | 39 |
|
24 | | -$client = new Client('MY_VERY_SECRET_API_KEY!'); |
| 40 | +// Initialize the client with your API key |
| 41 | +$client = new Client('YOUR_API_KEY'); |
| 42 | + |
| 43 | +// Create SMS resource |
25 | 44 | $smsResource = new SmsResource($client); |
26 | | -$smsParams = new SmsParams('HI2U', '+4901234567890'); |
27 | | -$res = $smsResource->dispatch($smsParams); |
28 | | -var_dump($res); |
| 45 | + |
| 46 | +// Send SMS |
| 47 | +$response = $smsResource->dispatch( |
| 48 | + new SmsParams('Hello from seven.io!', '+491234567890') |
| 49 | +); |
| 50 | + |
| 51 | +echo "SMS sent successfully! ID: " . $response->getMessages()[0]->getId(); |
| 52 | +``` |
| 53 | + |
| 54 | +## π± Features |
| 55 | + |
| 56 | +### SMS Messaging |
| 57 | +- β
Send SMS to single or multiple recipients |
| 58 | +- β
Bulk SMS support |
| 59 | +- β
Flash SMS |
| 60 | +- β
Unicode support |
| 61 | +- β
Delivery reports |
| 62 | +- β
Schedule messages |
| 63 | + |
| 64 | +### Voice Calls |
| 65 | +- β
Text-to-Speech calls |
| 66 | +- β
Voice message broadcasts |
| 67 | + |
| 68 | +### Number Lookup |
| 69 | +- β
HLR (Home Location Register) lookup |
| 70 | +- β
Number format validation |
| 71 | +- β
Carrier information |
| 72 | +- β
Number portability check |
| 73 | + |
| 74 | +### Other Features |
| 75 | +- β
Balance inquiry |
| 76 | +- β
Pricing information |
| 77 | +- β
Webhook management |
| 78 | +- β
Contact management |
| 79 | +- β
Analytics & Journal |
| 80 | + |
| 81 | +## π» Usage Examples |
| 82 | + |
| 83 | +### Send SMS with custom sender |
| 84 | + |
| 85 | +```php |
| 86 | +$params = (new SmsParams('Your message here', '+491234567890')) |
| 87 | + ->setFrom('YourBrand') |
| 88 | + ->setUnicode(true) |
| 89 | + ->setFlash(false); |
| 90 | + |
| 91 | +$response = $smsResource->dispatch($params); |
| 92 | +``` |
| 93 | + |
| 94 | +### Send bulk SMS |
| 95 | + |
| 96 | +```php |
| 97 | +$params = new SmsParams( |
| 98 | + 'Bulk message to multiple recipients', |
| 99 | + ['+491234567890', '+491234567891', '+491234567892'] |
| 100 | +); |
| 101 | + |
| 102 | +$response = $smsResource->dispatch($params); |
| 103 | +``` |
| 104 | + |
| 105 | +### Schedule SMS for later |
| 106 | + |
| 107 | +```php |
| 108 | +$params = (new SmsParams('Scheduled message', '+491234567890')) |
| 109 | + ->setDelay(new \DateTime('+1 hour')); |
| 110 | + |
| 111 | +$response = $smsResource->dispatch($params); |
| 112 | +``` |
| 113 | + |
| 114 | +### Perform HLR lookup |
| 115 | + |
| 116 | +```php |
| 117 | +use Seven\Api\Resource\Lookup\LookupResource; |
| 118 | + |
| 119 | +$lookupResource = new LookupResource($client); |
| 120 | +$result = $lookupResource->hlr('+491234567890'); |
| 121 | + |
| 122 | +echo "Carrier: " . $result->getCarrier(); |
| 123 | +echo "Country: " . $result->getCountry(); |
29 | 124 | ``` |
30 | 125 |
|
31 | | -See [docs](/docs) for more details. |
| 126 | +### Check account balance |
32 | 127 |
|
33 | | -##### Tests |
| 128 | +```php |
| 129 | +use Seven\Api\Resource\Balance\BalanceResource; |
| 130 | + |
| 131 | +$balanceResource = new BalanceResource($client); |
| 132 | +$balance = $balanceResource->get(); |
| 133 | + |
| 134 | +echo "Current balance: β¬" . $balance->getAmount(); |
| 135 | +``` |
| 136 | + |
| 137 | +### Text-to-Speech call |
| 138 | + |
| 139 | +```php |
| 140 | +use Seven\Api\Resource\Voice\VoiceResource; |
| 141 | +use Seven\Api\Resource\Voice\VoiceParams; |
| 142 | + |
| 143 | +$voiceResource = new VoiceResource($client); |
| 144 | +$params = new VoiceParams('+491234567890', 'Hello, this is a test call'); |
| 145 | + |
| 146 | +$response = $voiceResource->call($params); |
| 147 | +``` |
| 148 | + |
| 149 | +## π§ Advanced Configuration |
34 | 150 |
|
35 | | -Some basic tests are implemented. You can run them like this: |
| 151 | +### Initialize with signing secret (for webhook validation) |
36 | 152 |
|
37 | | -```shell script |
38 | | -SEVEN_API_KEY=<API-KEY> php vendor/bin/phpunit tests |
| 153 | +```php |
| 154 | +$client = new Client( |
| 155 | + apiKey: 'YOUR_API_KEY', |
| 156 | + signingSecret: 'YOUR_SIGNING_SECRET' |
| 157 | +); |
39 | 158 | ``` |
40 | 159 |
|
41 | | -or |
| 160 | +### Error Handling |
| 161 | + |
| 162 | +```php |
| 163 | +use Seven\Api\Exception\InvalidApiKeyException; |
| 164 | +use Seven\Api\Exception\InsufficientBalanceException; |
42 | 165 |
|
43 | | -```shell script |
44 | | -SEVEN_API_KEY_SANDBOX=<SANDBOX-API-KEY> php vendor/bin/phpunit tests |
| 166 | +try { |
| 167 | + $response = $smsResource->dispatch($params); |
| 168 | +} catch (InvalidApiKeyException $e) { |
| 169 | + echo "Invalid API key provided"; |
| 170 | +} catch (InsufficientBalanceException $e) { |
| 171 | + echo "Not enough balance to send SMS"; |
| 172 | +} catch (\Exception $e) { |
| 173 | + echo "Error: " . $e->getMessage(); |
| 174 | +} |
45 | 175 | ``` |
46 | 176 |
|
47 | | -Make sure to fill in the values. |
| 177 | +## π§ͺ Testing |
| 178 | + |
| 179 | +Run the test suite with your API credentials: |
| 180 | + |
| 181 | +```bash |
| 182 | +# Using production API key |
| 183 | +SEVEN_API_KEY=your_api_key php vendor/bin/phpunit tests |
| 184 | + |
| 185 | +# Using sandbox API key |
| 186 | +SEVEN_API_KEY_SANDBOX=your_sandbox_key php vendor/bin/phpunit tests |
| 187 | +``` |
| 188 | + |
| 189 | +### Run specific tests |
| 190 | + |
| 191 | +```bash |
| 192 | +# Test only SMS functionality |
| 193 | +php vendor/bin/phpunit tests/SmsTest.php |
| 194 | + |
| 195 | +# Test with verbose output |
| 196 | +php vendor/bin/phpunit tests --verbose |
| 197 | +``` |
| 198 | + |
| 199 | +## π API Resources |
| 200 | + |
| 201 | +The SDK provides access to all seven.io API endpoints: |
| 202 | + |
| 203 | +| Resource | Description | |
| 204 | +|----------|-------------| |
| 205 | +| `AnalyticsResource` | Analytics and statistics | |
| 206 | +| `BalanceResource` | Account balance | |
| 207 | +| `ContactsResource` | Contact management | |
| 208 | +| `HooksResource` | Webhook management | |
| 209 | +| `JournalResource` | Message history | |
| 210 | +| `LookupResource` | Number lookup & validation | |
| 211 | +| `PricingResource` | Pricing information | |
| 212 | +| `RcsResource` | RCS messaging | |
| 213 | +| `SmsResource` | SMS messaging | |
| 214 | +| `StatusResource` | Delivery reports | |
| 215 | +| `SubaccountsResource` | Subaccount management | |
| 216 | +| `ValidateForVoiceResource` | Voice number validation | |
| 217 | +| `VoiceResource` | Voice calls | |
| 218 | + |
| 219 | +## π Environment Variables |
| 220 | + |
| 221 | +| Variable | Description | |
| 222 | +|----------|-------------| |
| 223 | +| `SEVEN_API_KEY` | Your production API key | |
| 224 | +| `SEVEN_API_KEY_SANDBOX` | Your sandbox API key for testing | |
| 225 | +| `SEVEN_SIGNING_SECRET` | Webhook signing secret | |
| 226 | + |
| 227 | +## π Requirements |
| 228 | + |
| 229 | +- PHP 8.1 or higher |
| 230 | +- Composer (for installation) |
| 231 | +- ext-curl |
| 232 | +- ext-json |
| 233 | + |
| 234 | +## π€ Contributing |
| 235 | + |
| 236 | +We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details. |
| 237 | + |
| 238 | +1. Fork the repository |
| 239 | +2. Create your feature branch (`git checkout -b feature/amazing-feature`) |
| 240 | +3. Commit your changes (`git commit -m 'Add some amazing feature'`) |
| 241 | +4. Push to the branch (`git push origin feature/amazing-feature`) |
| 242 | +5. Open a Pull Request |
| 243 | + |
| 244 | +## π Support |
| 245 | + |
| 246 | +- π [API Documentation](https://www.seven.io/en/docs/gateway/http-api/) |
| 247 | +- π¬ [Contact Support](https://www.seven.io/en/company/contact/) |
| 248 | +- π [Report Issues](https://github.com/seven-io/php-client/issues) |
| 249 | +- π‘ [Feature Requests](https://github.com/seven-io/php-client/issues/new?labels=enhancement) |
| 250 | + |
| 251 | +## π License |
48 | 252 |
|
49 | | -###### Support |
| 253 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
50 | 254 |
|
51 | | -Need help? Feel free to [contact us](https://www.seven.io/en/company/contact/). |
| 255 | +--- |
52 | 256 |
|
53 | | -[](LICENSE) |
| 257 | +Made with β€οΈ by [seven.io](https://www.seven.io) |
0 commit comments