-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadapter.php
More file actions
50 lines (42 loc) · 1.07 KB
/
adapter.php
File metadata and controls
50 lines (42 loc) · 1.07 KB
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
<?php
//Adapter
interface PaymentGateway {
function sendMoney($amount);
}
class PaymentProcessing {
private $pg;
function __construct( PaymentGateway $pg){
$this->pg = $pg;
}
function purchaseProduct($amount){
$this->pg->sendMoney($amount);
}
}
class Paypal implements PaymentGateway {
function sendMoney($amount){
echo "{$amount} USD has been sent from Paypal\n";
}
}
class Stripe {
function makePayment($amount, $currency='USD'){
echo "{$amount} {$currency} payment from Stripe\n";
}
}
class StripeAdapter implements PaymentGateway {
private $pg;
private $currency;
function __construct(Stripe $pg, $currency='USD'){
$this->pg = $pg;
$this->currency = $currency;
}
function sendMoney($amount){
$this->pg->makePayment($amount, $this->currency);
}
}
$pl = new Paypal();
$sp = new Stripe();
$spa = new StripeAdapter($sp);
$payment1 = new PaymentProcessing($pl);
$payment2 = new PaymentProcessing($spa);
$payment1->purchaseProduct(1000);
$payment2->purchaseProduct(2000);