1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Claudsonm\BoletoWinner\Converters; |
4
|
|
|
|
5
|
|
|
use Claudsonm\BoletoWinner\Bill; |
6
|
|
|
|
7
|
|
|
class BoletoConverter implements Converter |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* {@inheritdoc} |
11
|
|
|
*/ |
12
|
26 |
|
public function toBarcode(Bill $bill): string |
13
|
|
|
{ |
14
|
26 |
|
$writableLine = $bill->getWritableLine(); |
15
|
|
|
$barcodeParts = [ |
16
|
26 |
|
'bankCode' => substr($writableLine, 0, 3), |
17
|
26 |
|
'currency' => substr($writableLine, 3, 1), |
18
|
26 |
|
'financialInfo' => substr($writableLine, 32), |
19
|
26 |
|
'firstFreeFields' => substr($writableLine, 4, 5), |
20
|
26 |
|
'secondFreeFields' => substr($writableLine, 10, 10), |
21
|
26 |
|
'thirdFreeFields' => substr($writableLine, 21, 10), |
22
|
|
|
]; |
23
|
|
|
|
24
|
26 |
|
return implode('', $barcodeParts); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
25 |
|
public function toWritableLine(Bill $bill): string |
31
|
|
|
{ |
32
|
25 |
|
$barcode = $bill->getBarcode(); |
33
|
|
|
$blocks = [ |
34
|
25 |
|
substr($barcode, 0, 4).substr($barcode, 19, 5), |
35
|
25 |
|
substr($barcode, 24, 10), |
36
|
25 |
|
substr($barcode, 34, 10), |
37
|
|
|
]; |
38
|
|
|
|
39
|
25 |
|
foreach ($blocks as &$block) { |
40
|
25 |
|
$block .= module10($block); |
41
|
|
|
} |
42
|
25 |
|
$blocks[] = substr($barcode, 4, 1); |
43
|
25 |
|
$blocks[] = substr($barcode, 5, 14); |
44
|
|
|
|
45
|
25 |
|
return implode('', $blocks); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|