Skip to content

Instantly share code, notes, and snippets.

@zedix
Last active December 6, 2016 07:56
Show Gist options
  • Save zedix/89b00f337aa54c5098230e4ddb867b86 to your computer and use it in GitHub Desktop.
Save zedix/89b00f337aa54c5098230e4ddb867b86 to your computer and use it in GitHub Desktop.
<?php
namespace SomeApp\Notifications\Payment;
// Example 1
// Would be nice to be able to configure this notification in EventServiceProvider:
// 'SomeApp\Events\Payment\PayInRefundFailed' => [
// 'SomeApp\Notifications\Payment\PayInRefundFailed@handle'
// ],
//
// It would be up to the event to carry info / recipient for the notification...
//
//
// For now, we have to do this to send the above example notification:
// $hookEvent = new \SomeApp\Events\Payment\PayOutFailed($resourceId, $date);
// Notification::send(null, new \SomeApp\Notifications\Payment\PayInRefundFailed($hookEvent));
//
use SomeApp\Notifications\Notification;
use SomeApp\Notifications\Transport\Channels\Slack; // This class contains endpoint for the slack notification
use SomeApp\Notifications\Transport\Messages\SlackMessage; // This class contains channel and bot methods
use SomeApp\Events\Payment\WebHookEvent;
class PayInRefundFailed extends Notification
{
/**
* @var string
*/
protected $resourceId;
public function __construct(WebHookEvent $event)
{
$this->resourceId = $event->resourceId;
}
/**
* Get the notification channels.
*
* @return array|string
*/
public function via()
{
return [Slack::class];
}
/**
* Get the Slack representation of the notification.
*
* @return SlackMessage
*/
public function toSlack()
{
return (new SlackMessage)
->bot('some-bot-name')
->channel('support-payment')
->content(sprintf('PayIn Refund Failed: %s', $this->resourceId));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment