1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHP Billing Library |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/php-billing |
6
|
|
|
* @package php-billing |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hiqdev\php\billing\tests\unit\plan; |
12
|
|
|
|
13
|
|
|
use hiqdev\php\billing\customer\Customer; |
14
|
|
|
use hiqdev\php\billing\plan\Plan; |
15
|
|
|
use hiqdev\php\billing\price\EnumPrice; |
16
|
|
|
use hiqdev\php\billing\target\Target; |
17
|
|
|
use hiqdev\php\billing\type\Type; |
18
|
|
|
use hiqdev\php\units\Unit; |
19
|
|
|
use Money\Money; |
20
|
|
|
|
21
|
|
|
class CertificatePlan extends Plan |
22
|
|
|
{ |
23
|
|
|
protected static $instance; |
24
|
|
|
|
25
|
|
|
public static function get() |
26
|
|
|
{ |
27
|
|
|
if (static::$instance === null) { |
28
|
|
|
new static(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
return static::$instance; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function __construct() |
35
|
|
|
{ |
36
|
|
|
if (static::$instance === null) { |
37
|
|
|
static::$instance = $this; |
38
|
|
|
} |
39
|
|
|
$this->seller = new Customer(1, 'seller'); |
40
|
|
|
$this->customer = new Customer(2, 'client', $this->seller); |
|
|
|
|
41
|
|
|
$this->purchase = new Type('certificate_purchase'); |
|
|
|
|
42
|
|
|
$this->renewal = new Type('certificate_renewal'); |
|
|
|
|
43
|
|
|
$this->rapidssl = new Target('certificate_type', 'rapidssl_standard'); |
|
|
|
|
44
|
|
|
$this->verisign = new Target('certificate_type', 'verisign_standard'); |
|
|
|
|
45
|
|
|
$this->types = [ |
|
|
|
|
46
|
|
|
'purchase' => $this->purchase, |
47
|
|
|
'renewal' => $this->renewal, |
48
|
|
|
]; |
49
|
|
|
$this->targets = [ |
|
|
|
|
50
|
|
|
'rapidssl' => $this->rapidssl, |
51
|
|
|
'verisign' => $this->verisign, |
52
|
|
|
]; |
53
|
|
|
$this->rawPrices = [ |
|
|
|
|
54
|
|
|
$this->getRawPriceKey($this->purchase, $this->rapidssl) => [ |
55
|
|
|
1 => Money::USD(1129), |
56
|
|
|
2 => Money::USD(1219), |
57
|
|
|
3 => Money::USD(1309), |
58
|
|
|
], |
59
|
|
|
$this->getRawPriceKey($this->renewal, $this->rapidssl) => [ |
60
|
|
|
1 => Money::USD(1125), |
61
|
|
|
2 => Money::USD(1215), |
62
|
|
|
3 => Money::USD(1305), |
63
|
|
|
], |
64
|
|
|
$this->getRawPriceKey($this->purchase, $this->verisign) => [ |
65
|
|
|
1 => Money::USD(2129), |
66
|
|
|
2 => Money::USD(2219), |
67
|
|
|
3 => Money::USD(2309), |
68
|
|
|
], |
69
|
|
|
$this->getRawPriceKey($this->renewal, $this->verisign) => [ |
70
|
|
|
1 => Money::USD(2125), |
71
|
|
|
2 => Money::USD(2215), |
72
|
|
|
3 => Money::USD(2305), |
73
|
|
|
], |
74
|
|
|
]; |
75
|
|
|
$prices = []; |
76
|
|
|
foreach ($this->types as $type) { |
77
|
|
|
foreach ($this->targets as $target) { |
78
|
|
|
$prices[] = new EnumPrice(null, $type, $target, Unit::year(), $this->getRawPrices($type, $target)); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
parent::__construct(null, 'Test Certificate Plan', $this->seller, $prices); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getRawPrice($action) |
85
|
|
|
{ |
86
|
|
|
$years = $action->getQuantity()->convert(Unit::year())->getQuantity(); |
87
|
|
|
return $this->getRawPrices($action->getType(), $action->getTarget())[$years]; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getRawPrices($type, $target) |
91
|
|
|
{ |
92
|
|
|
return $this->rawPrices[$this->getRawPriceKey($type, $target)]; |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function getRawPriceKey($type, $target) |
96
|
|
|
{ |
97
|
|
|
return $type->getName() . '-' . $target->getUniqId(); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: