Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
- added GatewayApi Facade
- added setCallbackUrl method
  • Loading branch information
Loafer19 committed Aug 31, 2021
1 parent 96035a3 commit 1989316
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,24 @@ GATEWAY_SENDER="Milky Way"

On the fly
```
(new GatewayApi())
->setSenderName('Elon Musk')
GatewayApi::setSenderName('Elon Musk')
->sendSimpleSMS('test message', [+380987654321])
```

By default, the sender's name is the name of the app

Up to 11 alphanumeric characters or 15 digits

### Callback Url

[Official Docs](https://gatewayapi.com/docs/apis/rest/#http-callback)

You can easily specify the callback url:

On the fly
```
GatewayApi::setCallbackUrl('https://test-dev.com/callbacks/sms')
->sendSimpleSMS('test message', [+380987654321])
```

By default, the callback url is null
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
"laravel": {
"providers": [
"Loafer\\GatewayApi\\GatewayApiServiceProvider"
]
],
"aliases": {
"GatewayApi": "Loafer\\GatewayApi\\Facades\\GatewayApi"
}
}
}
}
}
13 changes: 13 additions & 0 deletions src/Facades/GatewayApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Loafer\GatewayApi\Facades;

use Illuminate\Support\Facades\Facade;

class GatewayApi extends Facade
{
protected static function getFacadeAccessor()
{
return 'gatewayapi';
}
}
16 changes: 16 additions & 0 deletions src/GatewayApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class GatewayApi
private $client;

private $sender_name;
private $callback_url = null;

public function __construct()
{
Expand Down Expand Up @@ -49,6 +50,17 @@ public function setSenderName(string $name)
return $this;
}

public function setCallbackUrl(string $url)
{
if (!filter_var($url, FILTER_VALIDATE_URL)) {
throw new InvalidArgumentException('The callback URL is invalid, ' . $url);
};

$this->callback_url = $url;

return $this;
}

public function sendSimpleSMS(string $message, array $recipients)
{
$body = [
Expand All @@ -57,6 +69,10 @@ public function sendSimpleSMS(string $message, array $recipients)
'sender' => $this->sender_name
];

if ($this->callback_url) {
$body['callback_url'] = $this->callback_url;
}

foreach ($recipients as $recipient) {
$body['recipients'][] = ['msisdn' => $recipient];
}
Expand Down
4 changes: 3 additions & 1 deletion src/GatewayApiServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class GatewayApiServiceProvider extends ServiceProvider
*/
public function register()
{
//
$this->app->bind('gatewayapi', function ($app) {
return new GatewayApi();
});
}

/**
Expand Down

0 comments on commit 1989316

Please sign in to comment.