-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathopen_closed.php
89 lines (77 loc) · 1.66 KB
/
open_closed.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
interface PayableInterface
{
public function pay();
}
class CreditCardPayment implements PayableInterface
{
public function pay()
{
// execute credit card payment logic
}
}
class PaypalPayment implements PayableInterface
{
public function pay()
{
// execute PayPal payment logic
}
}
class ATMTransferPayment implements PayableInterface
{
public function pay()
{
// execute ATM transfer payment logic
}
}
class PaymentFactory
{
public function initializePayment($type)
{
if ($type === 'credit') {
return new CreditCardPayment();
}
if ($type == 'paypal') {
return new PaypalPayment();
}
if ($type === 'atm') {
return new ATMTransferPayment();
}
throw new Exception("Unsupported payment method");
}
}
## Controller
public function pay(Request $request)
{
$paymentFactory = new PaymentFactory();
$payment = $paymentFactory->initializePayment($request->type);
$payment->pay();
}
class PaymentManager
{
public function pay(Request $request)
{
$payment = new Payment;
if ($type === 'credit') {
// prepare credit card Details
// for processing
$payment->payWithCreditCard();
}
if ($type === 'paypal') {
// prepare paypal details
// for processing
$payment->payWithPaypal();
}
}
}
class Payment
{
public function payWithCreditCard()
{
// logic for paying with credit card
}
public function payWithPaypal()
{
// logit for paying with paypal
}
}