Advertisement
Guest User

Untitled

a guest
May 31st, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. interface PaymentInterface
  2. {
  3. public function pay(PaymentRequest $request);
  4. }
  5.  
  6. class Payment implements PaymentInterface
  7. {
  8. public function pay(PaymentRequest $request)
  9. {
  10. if ($request->isFirstPayment()) {
  11. $this->firstPayment->pay($request);
  12. } else {
  13. $this->tokenPayment->pay($request);
  14. }
  15. }
  16. }
  17.  
  18. $payment->pay($paymentRequest);
  19.  
  20. class PaymentFactory
  21. {
  22. public static function choosePayment(PaymentRequest $request)
  23. {
  24. if ($request->isFirstPayment()) {
  25. return new FirstPayment();
  26. }
  27.  
  28. return new TokenPayment();
  29. }
  30. }
  31.  
  32. $payment = PaymentFactory::choosePayment($paymentRequest);
  33. $payment->pay($paymentRequest);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement