Last active
April 17, 2017 19:47
-
-
Save carlosbelisario/401664d110ea47221412276a426e77cd to your computer and use it in GitHub Desktop.
Refacotr
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 | |
/** | |
* Se creo una interface correspondiente a los medios de pagos para asegurar que implementen el metodo | |
* Se hizo cambio en el nombre de la clase añadiendo el sufijo servicio ya que es un enlace entre el domain y los servicios de medio de pago | |
* Se indico de manera explicita la dependencia de PaymenthMethodInterface a la clase de servicio | |
* Se realizo un FactoryMethod para la creación del medio de pago según lo que venga por parámetros | |
*/ | |
/** | |
* Interface PaymenthMethodInterface | |
*/ | |
interface PaymenthMethodInterface | |
{ | |
public function pay($client, $total); | |
} | |
/** | |
* Class PaymenthMethodService | |
*/ | |
class PaymenthMethodService | |
{ | |
/** | |
* @var PaymenthMethodInterface | |
*/ | |
private $paymentMethod; | |
/** | |
* @param PaymenthMethodInterface $paymentMethod | |
*/ | |
public function __construct(PaymenthMethodInterface $paymentMethod) | |
{ | |
$this->paymentMethod = $paymentMethod; | |
} | |
public function pay($client, $total) | |
{ | |
$this->paymentMethod->pay($client, $total); | |
} | |
} | |
/** | |
* Class PaymenthMethodFactory | |
*/ | |
class PaymenthMethodFactory | |
{ | |
/** | |
* @param string $method | |
* @return PaymenthMethodInterface | |
*/ | |
public static function create($method) | |
{ | |
switch ($method) { | |
case 'mercadoPAgo': | |
return new MercadoPago(); | |
break; | |
case 'payPal': | |
return new Paypal(); | |
break; | |
case 'stripe': | |
return new Stripe(); | |
break; | |
default: | |
throw new \RuntimeException('the payment method not exist'); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment