Skip to content

Instantly share code, notes, and snippets.

@davidchc
Last active April 26, 2018 19:48
Show Gist options
  • Save davidchc/51c8d67afdfafe545ed14f09fa7f9630 to your computer and use it in GitHub Desktop.
Save davidchc/51c8d67afdfafe545ed14f09fa7f9630 to your computer and use it in GitHub Desktop.
Exemplo de criação para realizar notificação de transação para assinatura ou pedido
<?php
namespace Transactional;
abstract class Notification
{
protected $customer;
protected $order
public function __construct($customer, $order)
{
$this->customer = $customer;
$this->order = $order;
}
abstract public function send();
}
<?php
namespace Transactional;
class SubscriptionCreateNotification extends Notification
{
public function send()
{
//Dispara o email
}
}
<?php
namespace Transactional;
class SubscriptionPaidNotification extends Notification
{
public function send()
{
//Dispara o email
}
}
<?php
namespace Transactional;
class NotificationSubscriptionManager
{
private $notifications = [
'PAID' => Transactional\SubscriptionPaidNotification::class,
'CREATE' => Transactional\SubscriptionCreateNotification::class,
];
private $customer;
private $order;
public function __construct($customer, $order)
{
$this->customer = $customer;
$this->order = $order;
}
public function add($status, $class)
{
$this->notifications[$status] = $class;
}
public function submit($status)
{
$class = $this->notifications[$status];
$obj = new $class($this->customer, $this->order);
$obj->send();
}
}
<?php
use Transactional\NotificationSubscriptionManager;
$customer = ['id' => 123, 'name' => 'Aluno', 'email' => 'aluno@conta.com.br'];
$order = ['order_subscrition_id' => 12, 'customer_id' => 123];
$status = 'PAID';
$notification = new NotificationSubscriptionManager($customer, $order);
$notification->submit($status);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment