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\charge\Generalizer; |
15
|
|
|
use hiqdev\php\billing\order\Billing; |
16
|
|
|
use hiqdev\php\billing\order\BillingInterface; |
17
|
|
|
use hiqdev\php\billing\order\Calculator; |
18
|
|
|
use hiqdev\php\billing\order\OrderInterface; |
19
|
|
|
use hiqdev\php\billing\plan\PlanInterface; |
20
|
|
|
use hiqdev\php\billing\sale\SaleInterface; |
21
|
|
|
use hiqdev\php\billing\tests\support\bill\SimpleBillRepository; |
22
|
|
|
use hiqdev\php\billing\tests\support\plan\SimplePlanRepository; |
23
|
|
|
use hiqdev\php\billing\tests\support\sale\SimpleSaleRepository; |
24
|
|
|
use hiqdev\php\billing\tools\Aggregator; |
25
|
|
|
use hiqdev\php\billing\tools\Merger; |
26
|
|
|
|
27
|
|
|
class SimpleBilling implements BillingInterface |
28
|
|
|
{ |
29
|
|
|
private $billing; |
30
|
|
|
|
31
|
|
|
private $billRepository; |
32
|
|
|
|
33
|
|
|
public function __construct(SaleInterface $sale = null, PlanInterface $plan = null) |
34
|
|
|
{ |
35
|
|
|
$saleRepo = $sale ? new SimpleSaleRepository($sale) : null; |
36
|
|
|
$planRepo = $plan ? new SimplePlanRepository($plan) : null; |
37
|
|
|
$this->billRepository = $plan ? new SimpleBillRepository() : null; |
38
|
|
|
$calculator = new Calculator(new Generalizer(), $saleRepo, $planRepo); |
39
|
|
|
$aggregator = new Aggregator(new Generalizer()); |
40
|
|
|
$this->billing = new Billing($calculator, $aggregator, new Merger(), $this->billRepository); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function calculate(OrderInterface $order): array |
44
|
|
|
{ |
45
|
|
|
return $this->billing->calculate($order); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function perform(OrderInterface $order): array |
49
|
|
|
{ |
50
|
|
|
return $this->billing->perform($order); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getBillRepository(): BillRepositoryInterface |
54
|
|
|
{ |
55
|
|
|
return $this->billRepository; |
|
|
|
|
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|