Skip to content

Commit e6ff2a0

Browse files
committed
Initial Release
1 parent 648827d commit e6ff2a0

File tree

4 files changed

+4
-143
lines changed

4 files changed

+4
-143
lines changed

README.md

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Laravel SMS Notify
22

33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/teaminfinitydev/laravel-sms-notify.svg?style=flat-square)](https://packagist.org/packages/teaminfinitydev/laravel-sms-notify)
4-
[![GitHub Tests Action Status](https://github.com/teaminfinitydev/laravel-sms-notify/actions/workflows/tests.yml/badge.svg)](https://github.com/teaminfinitydev/laravel-sms-notify/actions/workflows/tests.yml)
4+
[![GitHub Tests Action Status](https://github.com/teaminfinitydev/laravel-sms-notify/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/teaminfinitydev/laravel-sms-notify/actions/workflows/tests.yml)
55
[![Total Downloads](https://img.shields.io/packagist/dt/teaminfinitydev/laravel-sms-notify.svg?style=flat-square)](https://packagist.org/packages/teaminfinitydev/laravel-sms-notify)
66

7-
Laravel package for Notifi.lk SMS Gateway Integration
7+
Laravel package for Notify.lk SMS Gateway Integration
88

99
## Installation
1010

@@ -54,43 +54,11 @@ $response = $notifyService->send(['771234567', '772345678'], 'Your message here'
5454
]
5555
```
5656

57-
### Check Balance
58-
59-
```php
60-
$balance = $notifyService->checkBalance();
61-
62-
// Response format
63-
[
64-
'success' => true,
65-
'data' => [
66-
'balance' => 100
67-
],
68-
'status_code' => 200
69-
]
70-
```
71-
72-
73-
### Check Delivery Status
74-
75-
```php
76-
$status = $notifyService->getDeliveryReport('message-id-here');
77-
78-
// Response format
79-
[
80-
'success' => true,
81-
'data' => [
82-
'status' => 'delivered'
83-
],
84-
'status_code' => 200
85-
]
86-
```
8757

8858
## Features
8959

9060
- Send SMS to single or multiple numbers
9161
- Automatic phone number formatting
92-
- Check account balance
93-
- Get delivery reports
9462
- Configurable retry attempts
9563
- Exception handling
9664
- Comprehensive testing
@@ -103,4 +71,4 @@ composer test
10371

10472
## License
10573

106-
The MIT License (MIT). Please see [License File](LICENSE) for more information.
74+
The MIT License (MIT). Please see [License File](LICENSE) for more information.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Laravel Notifi.lk SMS Gateway Integration",
44
"type": "library",
55
"license": "MIT",
6-
"version": "1.1.0",
6+
"version": "1.0.1",
77
"authors": [
88
{
99
"name": "TeamInfinity Dev",

src/Exceptions/NotifyException.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,6 @@ public static function rateLimitExceeded(): self
6262
return new self('API rate limit exceeded. Please try again later.');
6363
}
6464

65-
/**
66-
* Create a new exception for insufficient balance.
67-
*/
68-
public static function insufficientBalance(): self
69-
{
70-
return new self('Insufficient balance in your Notifi.lk account.');
71-
}
7265

7366
/**
7467
* Create a new exception for invalid message ID.

src/Services/NotifyService.php

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -55,39 +55,6 @@ protected function formatNumber(string $number): string
5555
return $number;
5656
}
5757

58-
/**
59-
* Check if there's sufficient balance before sending
60-
*
61-
* @param int $requiredMessages Number of messages to be sent
62-
* @return bool
63-
* @throws NotifyException
64-
*/
65-
protected function hasSufficientBalance(int $requiredMessages = 1): bool
66-
{
67-
try {
68-
$response = Http::get($this->baseUrl . '/balance', [
69-
'user_id' => $this->userId,
70-
'api_key' => $this->apiKey,
71-
]);
72-
73-
if (!$response->successful()) {
74-
throw NotifyException::apiError('Failed to check balance', $response->status());
75-
}
76-
77-
$data = $response->json();
78-
$balance = $data['data']['balance'] ?? 0;
79-
80-
if ($balance < $requiredMessages) {
81-
throw NotifyException::insufficientBalance();
82-
}
83-
84-
return true;
85-
} catch (NotifyException $e) {
86-
throw $e;
87-
} catch (\Exception $e) {
88-
throw NotifyException::apiError('Failed to check balance: ' . $e->getMessage());
89-
}
90-
}
9158

9259
/**
9360
* Send SMS
@@ -107,17 +74,6 @@ public function send($to, string $message, array $options = []): array
10774
$numbers = is_array($to) ? $to : [$to];
10875
$formattedNumbers = array_map([$this, 'formatNumber'], $numbers);
10976

110-
// Check balance before sending
111-
try {
112-
$this->hasSufficientBalance(count($numbers));
113-
} catch (NotifyException $e) {
114-
return [
115-
'success' => false,
116-
'error' => $e->getMessage(),
117-
'status_code' => $e->getCode(),
118-
];
119-
}
120-
12177
$payload = array_merge([
12278
'user_id' => $this->userId,
12379
'api_key' => $this->apiKey,
@@ -158,60 +114,4 @@ public function send($to, string $message, array $options = []): array
158114
}
159115
}
160116

161-
162-
/**
163-
* Check balance
164-
*
165-
* @return array
166-
*/
167-
public function checkBalance(): array
168-
{
169-
try {
170-
$response = Http::get($this->baseUrl . '/balance', [
171-
'user_id' => $this->userId,
172-
'api_key' => $this->apiKey,
173-
]);
174-
175-
return [
176-
'success' => $response->successful(),
177-
'data' => $response->json(),
178-
'status_code' => $response->status(),
179-
];
180-
} catch (\Exception $e) {
181-
return [
182-
'success' => false,
183-
'error' => $e->getMessage(),
184-
'status_code' => $e->getCode(),
185-
];
186-
}
187-
}
188-
189-
/**
190-
* Get delivery report
191-
*
192-
* @param string $messageId
193-
* @return array
194-
*/
195-
public function getDeliveryReport(string $messageId): array
196-
{
197-
try {
198-
$response = Http::get($this->baseUrl . '/status', [
199-
'user_id' => $this->userId,
200-
'api_key' => $this->apiKey,
201-
'message_id' => $messageId,
202-
]);
203-
204-
return [
205-
'success' => $response->successful(),
206-
'data' => $response->json(),
207-
'status_code' => $response->status(),
208-
];
209-
} catch (\Exception $e) {
210-
return [
211-
'success' => false,
212-
'error' => $e->getMessage(),
213-
'status_code' => $e->getCode(),
214-
];
215-
}
216-
}
217117
}

0 commit comments

Comments
 (0)