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

Support for Client Ref on the Nexmo API #17

Merged
merged 4 commits into from
Jul 29, 2019
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 src/Channels/NexmoSmsChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function send($notifiable, Notification $notification)
'from' => $message->from ?: $this->from,
'to' => $to,
'text' => trim($message->content),
'client_ref' => $message->clientRef,
]);
}
}
20 changes: 20 additions & 0 deletions src/Messages/NexmoMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class NexmoMessage
*/
public $type = 'text';

/**
* The client reference.
*
* @var string
*/
public $clientRef = '';

/**
* Create a new message instance.
*
Expand Down Expand Up @@ -73,4 +80,17 @@ public function unicode()

return $this;
}

/**
* Set the client reference (up to 40 characters).
*
* @param string $clientRef
* @return $this
*/
public function clientRef($clientRef)
{
$this->clientRef = $clientRef;

return $this;
}
}
30 changes: 30 additions & 0 deletions tests/NotificationNexmoChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function testSmsIsSentViaNexmo()
'from' => '4444444444',
'to' => '5555555555',
'text' => 'this is my message',
'client_ref' => '',
]);

$channel->send($notifiable, $notification);
Expand All @@ -50,6 +51,27 @@ public function testSmsIsSentViaNexmoWithCustomFrom()
'from' => '5554443333',
'to' => '5555555555',
'text' => 'this is my message',
'client_ref' => '',
]);

$channel->send($notifiable, $notification);
}

public function testSmsIsSentViaNexmoWithCustomFromAndClientRef()
{
$notification = new NotificationNexmoChannelTestCustomFromAndClientRefNotification;
$notifiable = new NotificationNexmoChannelTestNotifiable;

$channel = new NexmoSmsChannel(
$nexmo = m::mock(Client::class), '4444444444'
);

$nexmo->shouldReceive('message->send')->with([
'type' => 'unicode',
'from' => '5554443333',
'to' => '5555555555',
'text' => 'this is my message',
'client_ref' => '11',
]);

$channel->send($notifiable, $notification);
Expand Down Expand Up @@ -78,3 +100,11 @@ public function toNexmo($notifiable)
return (new NexmoMessage('this is my message'))->from('5554443333')->unicode();
}
}

class NotificationNexmoChannelTestCustomFromAndClientRefNotification extends Notification
{
public function toNexmo($notifiable)
{
return (new NexmoMessage('this is my message'))->from('5554443333')->unicode()->clientRef('11');
}
}