|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* API for Billing |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://github.com/hiqdev/billing-hiapi |
|
6
|
|
|
* @package billing-hiapi |
|
7
|
|
|
* @license BSD-3-Clause |
|
8
|
|
|
* @copyright Copyright (c) 2017-2018, HiQDev (http://hiqdev.com/) |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace hiqdev\billing\hiapi\price; |
|
12
|
|
|
|
|
13
|
|
|
use hiqdev\php\billing\plan\PlanInterface; |
|
14
|
|
|
use hiqdev\php\billing\price\SinglePrice; |
|
15
|
|
|
use hiqdev\php\billing\target\TargetInterface; |
|
16
|
|
|
use hiqdev\php\billing\type\TypeInterface; |
|
17
|
|
|
use hiqdev\php\units\QuantityInterface; |
|
18
|
|
|
use Money\Money; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class TemplatePrice. |
|
22
|
|
|
* |
|
23
|
|
|
* @author Dmytro Naumenko <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class TemplatePrice extends SinglePrice |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var Money[] |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $subprices = []; |
|
31
|
|
|
|
|
32
|
|
|
public function __construct( |
|
33
|
|
|
$id, |
|
34
|
|
|
TypeInterface $type, |
|
35
|
|
|
TargetInterface $target, |
|
36
|
|
|
PlanInterface $plan = null, |
|
37
|
|
|
QuantityInterface $prepaid, |
|
38
|
|
|
Money $price, |
|
39
|
|
|
array $subprices |
|
40
|
|
|
) { |
|
41
|
|
|
parent::__construct($id, $type, $target, $plan, $prepaid, $price); |
|
42
|
|
|
|
|
43
|
|
|
$this->subprices = $subprices; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function jsonSerialize() |
|
47
|
|
|
{ |
|
48
|
|
|
return array_merge(parent::jsonSerialize(), [ |
|
49
|
|
|
'subprices' => $this->subprices, |
|
50
|
|
|
]); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return Money[] |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getSubprices(): array |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->subprices; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param string $currencyCode |
|
63
|
|
|
* @return string the subprice in decimal format (e.g. `10.25`) |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getSubprice($currencyCode): string |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->subprices[strtoupper($currencyCode)] ?? '0'; |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|