|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of byrokrat\giroapp. |
|
5
|
|
|
* |
|
6
|
|
|
* byrokrat\giroapp is free software: you can redistribute it and/or |
|
7
|
|
|
* modify it under the terms of the GNU General Public License as published |
|
8
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* byrokrat\giroapp is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
* GNU General Public License for more details. |
|
15
|
|
|
* |
|
16
|
|
|
* You should have received a copy of the GNU General Public License |
|
17
|
|
|
* along with byrokrat\giroapp. If not, see <http://www.gnu.org/licenses/>. |
|
18
|
|
|
* |
|
19
|
|
|
* Copyright 2016-21 Hannes Forsgård |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
declare(strict_types=1); |
|
23
|
|
|
|
|
24
|
|
|
namespace byrokrat\giroapp\Domain; |
|
25
|
|
|
|
|
26
|
|
|
use byrokrat\giroapp\Domain\State\StateCollection; |
|
27
|
|
|
use byrokrat\banking\AccountFactoryInterface; |
|
28
|
|
|
use byrokrat\id\IdFactoryInterface; |
|
29
|
|
|
use Money\Currency; |
|
30
|
|
|
use Money\MoneyParser; |
|
31
|
|
|
|
|
32
|
|
|
class DonorFactory |
|
33
|
|
|
{ |
|
34
|
|
|
/** @var StateCollection */ |
|
35
|
|
|
private $stateCollection; |
|
36
|
|
|
|
|
37
|
|
|
/** @var AccountFactoryInterface */ |
|
38
|
|
|
private $accountFactory; |
|
39
|
|
|
|
|
40
|
|
|
/** @var IdFactoryInterface */ |
|
41
|
|
|
private $idFactory; |
|
42
|
|
|
|
|
43
|
|
|
/** @var MoneyParser */ |
|
44
|
|
|
private $moneyParser; |
|
45
|
|
|
|
|
46
|
|
|
public function __construct( |
|
47
|
|
|
StateCollection $stateCollection, |
|
48
|
|
|
AccountFactoryInterface $accountFactory, |
|
49
|
|
|
IdFactoryInterface $idFactory, |
|
50
|
|
|
MoneyParser $moneyParser |
|
51
|
|
|
) { |
|
52
|
|
|
$this->stateCollection = $stateCollection; |
|
53
|
|
|
$this->accountFactory = $accountFactory; |
|
54
|
|
|
$this->idFactory = $idFactory; |
|
55
|
|
|
$this->moneyParser = $moneyParser; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param string[] $address |
|
60
|
|
|
* @param string[] $attributes |
|
61
|
|
|
*/ |
|
62
|
|
|
public function createDonor( |
|
63
|
|
|
string $mandateKey = '', |
|
64
|
|
|
string $state = '', |
|
65
|
|
|
string $mandateSource = '', |
|
66
|
|
|
string $payerNumber = '', |
|
67
|
|
|
string $accountNumber = '', |
|
68
|
|
|
string $donorId = '', |
|
69
|
|
|
string $name = '', |
|
70
|
|
|
array $address = [], |
|
71
|
|
|
string $email = '', |
|
72
|
|
|
string $phone = '', |
|
73
|
|
|
string $donationAmount = '0', |
|
74
|
|
|
string $comment = '', |
|
75
|
|
|
string $created = '', |
|
76
|
|
|
string $updated = '', |
|
77
|
|
|
array $attributes = [] |
|
78
|
|
|
): Donor { |
|
79
|
|
|
return new Donor( |
|
80
|
|
|
$mandateKey, |
|
81
|
|
|
$this->stateCollection->getState($state), |
|
82
|
|
|
$mandateSource, |
|
83
|
|
|
$payerNumber, |
|
84
|
|
|
$this->accountFactory->createAccount($accountNumber), |
|
85
|
|
|
$this->idFactory->createId($donorId), |
|
86
|
|
|
$name, |
|
87
|
|
|
new PostalAddress(...$address), |
|
|
|
|
|
|
88
|
|
|
$email, |
|
89
|
|
|
$phone, |
|
90
|
|
|
$this->moneyParser->parse($donationAmount, new Currency('SEK')), |
|
91
|
|
|
$comment, |
|
92
|
|
|
new \DateTimeImmutable($created), |
|
93
|
|
|
new \DateTimeImmutable($updated), |
|
94
|
|
|
$attributes |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|