1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Sprain\SwissQrBill\DataGroup\Element; |
4
|
|
|
|
5
|
|
|
use Sprain\SwissQrBill\DataGroup\QrCodeableInterface; |
6
|
|
|
use Sprain\SwissQrBill\Validator\SelfValidatableInterface; |
7
|
|
|
use Sprain\SwissQrBill\Validator\SelfValidatableTrait; |
8
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
9
|
|
|
use Symfony\Component\Validator\Mapping\ClassMetadata; |
10
|
|
|
|
11
|
|
|
final class AdditionalInformation implements QrCodeableInterface, SelfValidatableInterface |
12
|
|
|
{ |
13
|
|
|
use SelfValidatableTrait; |
14
|
|
|
|
15
|
|
|
public const TRAILER_EPD = 'EPD'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Unstructured information can be used to indicate the payment purpose |
19
|
|
|
* or for additional textual information about payments with a structured reference. |
20
|
|
|
*/ |
21
|
|
|
private ?string $message; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Bill information contains coded information for automated booking of the payment. |
25
|
|
|
* The data is not forwarded with the payment. |
26
|
|
|
*/ |
27
|
|
|
private ?string $billInformation; |
28
|
|
|
|
29
|
|
|
private function __construct( |
30
|
|
|
?string $message, |
31
|
|
|
?string $billInformation |
32
|
|
|
) { |
33
|
|
|
$this->message = $message; |
34
|
|
|
$this->billInformation = $billInformation; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public static function create( |
38
|
|
|
?string $message, |
39
|
|
|
?string $billInformation = null |
40
|
|
|
): self { |
41
|
|
|
return new self($message, $billInformation); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getMessage(): ?string |
45
|
|
|
{ |
46
|
|
|
return $this->message; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getBillInformation(): ?string |
50
|
|
|
{ |
51
|
|
|
return $this->billInformation; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getFormattedString(): ?string |
55
|
|
|
{ |
56
|
|
|
$string = $this->getMessage(); |
57
|
|
|
if ($this->getBillInformation()) { |
58
|
|
|
$string .= "\n".$this->getBillInformation(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $string; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getQrCodeData(): array |
65
|
|
|
{ |
66
|
|
|
$qrCodeData = [ |
67
|
|
|
$this->getMessage(), |
68
|
|
|
self::TRAILER_EPD, |
69
|
|
|
]; |
70
|
|
|
|
71
|
|
|
if ($this->getBillInformation()) { |
72
|
|
|
$qrCodeData[]= $this->getBillInformation(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $qrCodeData; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public static function loadValidatorMetadata(ClassMetadata $metadata): void |
79
|
|
|
{ |
80
|
|
|
$metadata->addPropertyConstraints('message', [ |
81
|
|
|
new Assert\Length([ |
82
|
|
|
'max' => 140 |
83
|
|
|
]) |
84
|
|
|
]); |
85
|
|
|
|
86
|
|
|
$metadata->addPropertyConstraints('billInformation', [ |
87
|
|
|
new Assert\Length([ |
88
|
|
|
'max' => 140 |
89
|
|
|
]) |
90
|
|
|
]); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|