Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Next version #53

Merged
merged 28 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
.styleci.yml export-ignore
CHANGELOG.md export-ignore
phpunit.xml.dist export-ignore
UPGRADE.md export-ignore
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: true
matrix:
php: ['8.0', 8.1]
laravel: [8]
laravel: [8, 9]

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

Expand Down
147 changes: 147 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Upgrade Guide

## Upgrading To 3.0 From 2.x

This major release is a thorough rewrite of this package. Please review the upgrade instruction below to ensure your application is compatible.

### Minimum Versions

The following required dependency versions have been updated:

- The minimum PHP version is now 8.0
- The minimum Laravel version is now 8.0

### Package Name

This package has been renamed from `laravel/nexmo-notification-channel` to `laravel/vonage-notification-channel` to account for Nexmo being acquired by Vonage. Therefore, you should update your `composer.json` dependencies from:

```json
"require": {
"laravel/nexmo-notification-channel": "^2.0"
},
```

To:

```json
"require": {
"laravel/vonage-notification-channel": "^3.0"
},
```

### Vonage Core Client

[The `nexmo/laravel` library](https://github.com/Nexmo/nexmo-laravel) has been merged into this package and its dependency was removed. Instead, this library now directly depends on [the `vonage/client-core` library](https://github.com/Vonage/vonage-php-sdk-core).

If you were depending on functionality from `nexmo/laravel` you may now use it directly from this package. A `Vonage\Client` instance may be resolved from Laravel's service container:

```php
use Vonage\Client;

$vonageClient = app()->make(Client::class);
```

If you were using the `Nexmo` facade from `nexmo/laravel`, you should update your code to use the `Vonage` facade instead:

```php
// Before...
use Nexmo\Laravel\Facade\Nexmo;

Nexmo::message()->send([
'to' => '14845551244',
'from' => '16105552344',
'text' => 'Using the facade to send a message.'
]);

// After...
use Illuminate\Notifications\Facades\Vonage;

Vonage::message()->send([
'to' => '14845551244',
'from' => '16105552344',
'text' => 'Using the facade to send a message.'
]);
```

### HTTP Client

An HTTP client such as Guzzle is required for this package. Most Laravel applications already include Guzzle by default:

```zsh
composer require guzzlehttp/guzzle:^7.0
```

### Configuration Changes

Previously, we recommended placing your SMS "from" number in your application's `services.php` file. However, this package includes its own `vonage` configuration file and corresponding environment variables. Therefore, you should now set this value using the `VONAGE_SMS_FROM` environment variable:

```
VONAGE_SMS_FROM=15556666666
```

Once you have defined this environment variable, you may remove the `nexmo` configuration entry from your `services` configuration file.

### Class / Method Renaming

All references to Nexmo have been updated to Vonage, including class names and method names.

For example, all `toNexmo` methods defined on your application's notification classes need to be renamed to `toVonage`. Likewise, the `NexmoMessage` class has been renamed to `VonageMessage`:

```php
/**
* Get the Vonage / SMS representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\VonageMessage
*/
public function toVonage($notifiable)
{
return (new VonageMessage)
->content('Your SMS message content');
}
```

Within your notifiable models, the `routeNotificationForNexmo` method should to be renamed to `routeNotificationForVonage`:

```php
/**
* Route notifications for the Vonage channel.
*
* @param \Illuminate\Notifications\Notification $notification
* @return string
*/
public function routeNotificationForVonage($notification)
{
return $this->phone_number;
}
```

### Environment Variables

Additionally, all environment variables have been renamed to reference Vonage instead of Nexmo:

```
# Before...
NEXMO_KEY=
NEXMO_SECRET=
NEXMO_SIGNATURE_SECRET=
NEXMO_PRIVATE_KEY=
NEXMO_APPLICATION_ID=
NEXMO_APP_NAME=
NEXMO_APP_VERSION=
NEXMO_HTTP_CLIENT=

# After...
VONAGE_KEY=
VONAGE_SECRET=
VONAGE_SIGNATURE_SECRET=
VONAGE_PRIVATE_KEY=
VONAGE_APPLICATION_ID=
VONAGE_APP_NAME=
VONAGE_APP_VERSION=
VONAGE_HTTP_CLIENT=
```

### Shortcode Functionality Removed

Vonage has deprecated support for "shortcodes" within their SDKs. Therefore, support for this feature has been removed.
14 changes: 9 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
],
"require": {
"php": "^8.0",
"illuminate/notifications": "^8.0",
"vonage/client-core": "^2.10"
"illuminate/notifications": "^8.0|^9.0",
"illuminate/support": "^8.0|^9.0",
"vonage/client-core": "^3.0"
},
"require-dev": {
"guzzlehttp/guzzle": "^7.2",
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^9.3"
"orchestra/testbench": "^6.0|^7.0"
},
"autoload": {
"psr-4": {
Expand All @@ -26,7 +27,7 @@
},
"autoload-dev": {
"psr-4": {
"Illuminate\\Tests\\Notifications\\": "tests/"
"Illuminate\\Notifications\\Tests\\": "tests/"
}
},
"config": {
Expand All @@ -42,7 +43,10 @@
"laravel": {
"providers": [
"Illuminate\\Notifications\\VonageChannelServiceProvider"
]
],
"aliases": {
"Vonage": "Illuminate\\Notifications\\Facades\\Vonage"
}
}
},
"minimum-stability": "dev",
Expand Down
77 changes: 77 additions & 0 deletions config/vonage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| SMS "From" Number
|--------------------------------------------------------------------------
|
| This configuration option defines the phone number that will be used as
| the "from" number for all outgoing text messages. You should provide
| the number you have already reserved within your Vonage dashboard.
|
*/

'sms_from' => env('VONAGE_SMS_FROM'),

/*
|--------------------------------------------------------------------------
| API Credentials
|--------------------------------------------------------------------------
|
| The following configuration options contain your API credentials, which
| may be accessed from your Vonage dashboard. These credentials may be
| used to authenticate with the Vonage API so you may send messages.
|
*/

'api_key' => env('VONAGE_KEY'),

'api_secret' => env('VONAGE_SECRET'),

'application_id' => env('VONAGE_APPLICATION_ID'),

/*
|--------------------------------------------------------------------------
| Signature Secret
|--------------------------------------------------------------------------
|
| If your application is receiving webhooks from Vonage, you may wish to
| configure a message signature secret so that you can ensure each of
| the inbound webhook calls are actually originating within Vonage.
|
*/

'signature_secret' => env('VONAGE_SIGNATURE_SECRET'),

/*
|--------------------------------------------------------------------------
| Private Key
|--------------------------------------------------------------------------
|
| Some of Vonage's recent APIs utilize JWTs for authentication, which also
| require a private key so that they may be signed. You may define your
| application's private key string below via the configuration value.
|
*/

'private_key' => env('VONAGE_PRIVATE_KEY'),

/*
|--------------------------------------------------------------------------
| Application Identifiers
|--------------------------------------------------------------------------
|
| Adding an application name and version may assist you in identifying
| problems with your application or when viewing analytics for your
| application's API usage within the dedicated Vonage dashboards.
|
*/

'app' => [
'name' => env('VONAGE_APP_NAME', 'Laravel'),
'version' => env('VONAGE_APP_VERSION', '1.1.2'),
],

];
7 changes: 5 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
verbose="true"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix="Test.php">./tests</directory>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
</phpunit>
45 changes: 0 additions & 45 deletions src/Channels/VonageShortcodeChannel.php

This file was deleted.

10 changes: 5 additions & 5 deletions src/Channels/VonageSmsChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class VonageSmsChannel
*
* @var \Vonage\Client
*/
protected $vonage;
protected $client;

/**
* The phone number notifications should be sent from.
Expand All @@ -25,14 +25,14 @@ class VonageSmsChannel
/**
* Create a new Vonage channel instance.
*
* @param \Vonage\Client $vonage
* @param \Vonage\Client $client
* @param string $from
* @return void
*/
public function __construct(VonageClient $vonage, $from)
public function __construct(VonageClient $client, $from)
{
$this->from = $from;
$this->vonage = $vonage;
$this->client = $client;
}

/**
Expand Down Expand Up @@ -66,6 +66,6 @@ public function send($notifiable, Notification $notification)
$payload['callback'] = $message->statusCallback;
}

return ($message->client ?? $this->vonage)->message()->send($payload);
return ($message->client ?? $this->client)->message()->send($payload);
}
}
19 changes: 19 additions & 0 deletions src/Facades/Vonage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Illuminate\Notifications\Facades;

use Illuminate\Support\Facades\Facade;
use Vonage\Client;

class Vonage extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return Client::class;
}
}
Loading