|
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-2018, HiQDev (http://hiqdev.com/) |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace hiqdev\php\billing\charge\modifiers; |
|
12
|
|
|
|
|
13
|
|
|
use hiqdev\php\billing\charge\modifiers\addons\Reason; |
|
14
|
|
|
use hiqdev\php\billing\charge\modifiers\addons\Since; |
|
15
|
|
|
use hiqdev\php\billing\charge\modifiers\addons\Till; |
|
16
|
|
|
use hiqdev\php\billing\action\ActionInterface; |
|
17
|
|
|
use hiqdev\php\billing\charge\ChargeInterface; |
|
18
|
|
|
use hiqdev\php\billing\charge\ChargeModifier; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Fixed discount. |
|
22
|
|
|
* |
|
23
|
|
|
* @author Andrii Vasyliev <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class Modifier implements ChargeModifier |
|
26
|
|
|
{ |
|
27
|
|
|
const REASON = 'reason'; |
|
28
|
|
|
const SINCE = 'since'; |
|
29
|
|
|
const TILL = 'till'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var AddonInterface[] |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $addons; |
|
35
|
|
|
|
|
36
|
5 |
|
public function __construct(array $addons = []) |
|
37
|
|
|
{ |
|
38
|
5 |
|
$this->addons = $addons; |
|
39
|
5 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function modifyCharge(ChargeInterface $charge, ActionInterface $action): array |
|
42
|
|
|
{ |
|
43
|
|
|
throw new \Exception('not finished modifier'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
public function reason($text) |
|
47
|
|
|
{ |
|
48
|
1 |
|
return $this->addAddon(self::REASON, new Reason($text)); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
1 |
|
public function since($time) |
|
52
|
|
|
{ |
|
53
|
1 |
|
return $this->addAddon(self::SINCE, new Since($time)); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
1 |
|
public function till($time) |
|
57
|
|
|
{ |
|
58
|
1 |
|
return $this->addAddon(self::TILL, new Till($time)); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
1 |
|
public function addAddon($name, $addon) |
|
62
|
|
|
{ |
|
63
|
1 |
|
if (isset($this->addons[$name])) { |
|
64
|
|
|
throw new \Exception("'$name' is already set"); |
|
65
|
|
|
} |
|
66
|
1 |
|
$this->addons[$name] = $addon; |
|
67
|
|
|
|
|
68
|
1 |
|
return $this; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
1 |
|
public function getAddon($name) |
|
72
|
|
|
{ |
|
73
|
1 |
|
return empty($this->addons[$name]) ? null : $this->addons[$name]; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
1 |
|
public function getReason() |
|
77
|
|
|
{ |
|
78
|
1 |
|
return $this->getAddon(self::REASON); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
1 |
|
public function getSince() |
|
82
|
|
|
{ |
|
83
|
1 |
|
return $this->getAddon(self::SINCE); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
1 |
|
public function getTill() |
|
87
|
|
|
{ |
|
88
|
1 |
|
return $this->getAddon(self::TILL); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|