Last active
April 26, 2018 19:48
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Transactional; | |
class SubscriptionCreateNotification extends Notification | |
{ | |
public function send() | |
{ | |
//Dispara o email | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Transactional; | |
class SubscriptionPaidNotification extends Notification | |
{ | |
public function send() | |
{ | |
//Dispara o email | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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