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\tests\support\order; |
12
|
|
|
|
13
|
|
|
use hiqdev\php\billing\bill\BillRepositoryInterface; |
14
|
|
|
use hiqdev\php\billing\customer\CustomerInterface; |
15
|
|
|
use hiqdev\php\billing\order\Billing; |
16
|
|
|
use hiqdev\php\billing\order\CalculatorInterface; |
17
|
|
|
use hiqdev\php\billing\plan\PlanInterface; |
18
|
|
|
use hiqdev\php\billing\sale\SaleInterface; |
19
|
|
|
use hiqdev\php\billing\target\Target; |
20
|
|
|
use hiqdev\php\billing\tests\support\bill\SimpleBillRepository; |
21
|
|
|
use hiqdev\php\billing\tools\Aggregator; |
22
|
|
|
use hiqdev\php\billing\tools\AggregatorInterface; |
23
|
|
|
use hiqdev\php\billing\tools\Merger; |
24
|
|
|
use hiqdev\php\billing\tools\MergerInterface; |
25
|
|
|
use hiqdev\php\billing\sale\Sale; |
26
|
|
|
|
27
|
|
|
class SimpleBilling extends Billing |
28
|
|
|
{ |
29
|
|
|
public function __construct( |
30
|
|
|
CalculatorInterface $calculator = null, |
31
|
|
|
AggregatorInterface $aggregator = null, |
32
|
|
|
MergerInterface $merger = null, |
33
|
|
|
$repository = null |
34
|
|
|
) { |
35
|
|
|
$calculator = $calculator ?: new SimpleCalculator(); |
36
|
|
|
$aggregator = $aggregator ?: new Aggregator($calculator->getGeneralizer()); |
|
|
|
|
37
|
|
|
$merger = $merger ?: new Merger(); |
38
|
|
|
$repository = $repository ?: new SimpleBillRepository(); |
39
|
|
|
|
40
|
|
|
parent::__construct($calculator, $aggregator, $merger, $repository, null); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function getBillRepository(): BillRepositoryInterface |
44
|
|
|
{ |
45
|
|
|
return $this->repository; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public static function fromPlan(PlanInterface $plan, CustomerInterface $customer = null) |
49
|
|
|
{ |
50
|
|
|
$customer ??= $plan->getSeller(); |
51
|
|
|
$sale = new Sale(null, Target::any(), $customer, $plan); |
|
|
|
|
52
|
|
|
return self::fromSale($sale); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public static function fromSale(SaleInterface $sale) |
56
|
|
|
{ |
57
|
|
|
return new self(new SimpleCalculator(null, $sale)); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|