1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace hiqdev\php\billing\tests\behat\bootstrap; |
4
|
|
|
|
5
|
|
|
use hiqdev\php\billing\price\EnumPrice; |
6
|
|
|
use hiqdev\php\billing\price\SinglePrice; |
7
|
|
|
use hiqdev\php\billing\price\PriceFactory; |
8
|
|
|
use hiqdev\php\billing\order\Order; |
9
|
|
|
use hiqdev\php\billing\tests\support\tools\SimpleFactory; |
10
|
|
|
use hiqdev\php\billing\tests\support\order\SimpleBilling; |
11
|
|
|
use hiqdev\billing\hiapi\tests\support\order\SimpleCalculator; |
|
|
|
|
12
|
|
|
|
13
|
|
|
class FactoryBasedBuilder |
14
|
|
|
{ |
15
|
|
|
private $reseller; |
16
|
|
|
|
17
|
|
|
private $customer; |
18
|
|
|
|
19
|
|
|
private $time; |
20
|
|
|
|
21
|
|
|
private $plan; |
22
|
|
|
|
23
|
|
|
private $sale; |
24
|
|
|
|
25
|
|
|
private $prices = []; |
26
|
|
|
|
27
|
|
|
private $bill; |
28
|
|
|
|
29
|
|
|
private $charges = []; |
30
|
|
|
|
31
|
|
|
private $factory; |
32
|
|
|
|
33
|
|
|
private $calculator; |
34
|
|
|
|
35
|
|
|
private $billing; |
36
|
|
|
|
37
|
|
|
public function __construct() |
38
|
|
|
{ |
39
|
|
|
$this->factory = new SimpleFactory([ |
40
|
|
|
'price' => new PriceFactory([ |
41
|
|
|
'certificate,certificate_purchase' => EnumPrice::class, |
42
|
|
|
'certificate,certificate_renewal' => EnumPrice::class, |
43
|
|
|
], SinglePrice::class), |
44
|
|
|
]); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
private function getBilling() |
48
|
|
|
{ |
49
|
|
|
if ($this->billing === null) { |
50
|
|
|
$this->billing = new SimpleBilling($this->getCalculator()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $this->billing; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
private function getCalculator() |
57
|
|
|
{ |
58
|
|
|
if ($this->calculator === null) { |
59
|
|
|
$this->calculator = new SimpleCalculator(null, $this->sale, $this->plan); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $this->calculator; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function buildReseller(string $login) |
66
|
|
|
{ |
67
|
|
|
$this->reseller = $login; |
68
|
|
|
$this->factory->get('customer', $login); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function buildCustomer(string $login) |
72
|
|
|
{ |
73
|
|
|
$this->customer = $login; |
74
|
|
|
$this->factory->get('customer', [ |
75
|
|
|
'login' => $login, |
76
|
|
|
'seller' => $this->reseller, |
77
|
|
|
]); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function buildPlan(string $name, string $type, bool $grouping = false) |
|
|
|
|
81
|
|
|
{ |
82
|
|
|
$this->prices = []; |
83
|
|
|
$this->plan = $this->factory->get('plan', [ |
84
|
|
|
'name' => $name, |
85
|
|
|
'seller' => $this->reseller, |
86
|
|
|
]); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function buildPrice(array $data) |
90
|
|
|
{ |
91
|
|
|
$this->prices[] = $this->factory->get('price', $data); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function recreatePlan(string $name) |
95
|
|
|
{ |
96
|
|
|
$plan = $this->factory->get('plan', $name); |
97
|
|
|
$plan->setPrices($this->prices); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function buildSale(string $id, string $target, string $plan, string $time) |
101
|
|
|
{ |
102
|
|
|
$this->time = $time; |
103
|
|
|
$this->sale = $this->factory->get('sale', [ |
104
|
|
|
'id' => $id, |
105
|
|
|
'customer' => $this->customer, |
106
|
|
|
'target' => $target, |
107
|
|
|
'plan' => $plan, |
108
|
|
|
'time' => $time, |
109
|
|
|
]); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function buildTarget(string $target) |
113
|
|
|
{ |
114
|
|
|
return $this->factory->get('target', $target); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function performAction(array $data) |
118
|
|
|
{ |
119
|
|
|
$action = $this->buildAction($data); |
120
|
|
|
$this->getBilling()->perform(Order::fromActions([$action])); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function buildAction(array $data) |
124
|
|
|
{ |
125
|
|
|
$data['time'] = $data['time'] ?? $this->time; |
126
|
|
|
$data['customer'] = $data['customer'] ?? $this->customer; |
127
|
|
|
if (!empty($data['targets'])) { |
128
|
|
|
$data['target'] = $this->factory->get('targets', $data['targets']); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
return $this->factory->get('action', $data); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function findBills(array $data): array |
135
|
|
|
{ |
136
|
|
|
$data['sum'] = $data['sum'] ?? '0 USD'; |
137
|
|
|
$data['quantity'] = $data['quantity'] ?? '0 items'; |
138
|
|
|
$bill = $this->buildBill($data); |
139
|
|
|
$repo = $this->getBilling()->getBillRepository(); |
140
|
|
|
|
141
|
|
|
return $repo->findByUniqueness([$bill]); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function findBill(array $data) |
145
|
|
|
{ |
146
|
|
|
$bills = $this->findBills($data); |
147
|
|
|
$this->bill = reset($bills); |
148
|
|
|
$this->charges = $this->bill->getCharges(); |
149
|
|
|
|
150
|
|
|
return $this->bill; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function buildBill(array $data) |
154
|
|
|
{ |
155
|
|
|
$data['time'] = $data['time'] ?? $this->time; |
156
|
|
|
$data['customer'] = $data['customer'] ?? $this->customer; |
157
|
|
|
if (!empty($data['targets'])) { |
158
|
|
|
$data['target'] = $this->factory->get('targets', $data['targets']); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
return $this->factory->get('bill', $data); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
public function findCharges(array $data): array |
165
|
|
|
{ |
166
|
|
|
$data['sum'] = $data['sum'] ?? '0 USD'; |
167
|
|
|
$data['quantity'] = $data['quantity'] ?? '0 items'; |
168
|
|
|
$bill = $this->buildCharge($data); |
169
|
|
|
$repo = $this->getBilling()->getChargeRepository(); |
170
|
|
|
|
171
|
|
|
return $repo->findByUniqueness($bill); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
public function getNextCharge() |
175
|
|
|
{ |
176
|
|
|
$charge = current($this->charges); |
177
|
|
|
next($this->charges); |
178
|
|
|
|
179
|
|
|
return $charge; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function buildCharge(array $data) |
183
|
|
|
{ |
184
|
|
|
$data['time'] = $data['time'] ?? $this->time; |
185
|
|
|
$data['customer'] = $data['customer'] ?? $this->customer; |
186
|
|
|
if (!empty($data['targets'])) { |
187
|
|
|
$data['target'] = $this->factory->get('targets', $data['targets']); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
return $this->factory->get('bill', $data); |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths