-
Notifications
You must be signed in to change notification settings - Fork 1
/
UiTPASService.php
105 lines (90 loc) · 3.25 KB
/
UiTPASService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace CultuurNet\UiTPASBeheer\UiTPAS;
use CultuurNet\UiTPASBeheer\Counter\CounterAwareUitpasService;
use CultuurNet\UiTPASBeheer\Exception\CompleteResponseException;
use CultuurNet\UiTPASBeheer\UiTPAS\Price\Inquiry;
use CultuurNet\UiTPASBeheer\UiTPAS\Price\Price;
use CultuurNet\UiTPASBeheer\UiTPAS\Registration\Registration;
class UiTPASService extends CounterAwareUitpasService implements UiTPASServiceInterface
{
/**
* @param UiTPASNumber $uitpasNumber
*/
public function block(UiTPASNumber $uitpasNumber)
{
$this->getUitpasService()->blockUitpas(
$uitpasNumber->toNative(),
$this->getCounterConsumerKey()
);
}
/**
* @param UiTPASNumber $uitpasNumber
* @return UiTPAS
*/
public function get(UiTPASNumber $uitpasNumber)
{
$uitpasQuery = new \CultureFeed_Uitpas_CardInfoQuery();
$uitpasQuery->uitpasNumber = $uitpasNumber->toNative();
$uitpasQuery->balieConsumerKey = $this->getCounterConsumerKey();
return UiTPAS::fromCultureFeedCardInfo(
$this->getUitpasService()->getCard($uitpasQuery)
);
}
/**
* @param UiTPASNumber $uitpasNumber
* @param Registration $registration
*/
public function register(UiTPASNumber $uitpasNumber, Registration $registration)
{
$options = new \CultureFeed_Uitpas_Passholder_Query_RegisterUitpasOptions();
$options->balieConsumerKey = $this->getCounterConsumerKey();
$options->uitpasNumber = $uitpasNumber->toNative();
$options->uid = $registration->getPassHolderUid()->toNative();
$options->reason = $registration->getReason()->toNative();
if (!is_null($registration->getKansenStatuut())) {
$options->kansenStatuutEndDate = $registration
->getKansenStatuut()
->getEndDate()
->toNativeDateTime()
->getTimestamp();
}
if (!is_null($registration->getVoucherNumber())) {
$options->voucherNumber = $registration->getVoucherNumber()->toNative();
}
$this->getUitpasService()->registerUitpas($options);
}
/**
* @param Inquiry $inquiry
*
* @return Price
*
* @throws CompleteResponseException
* When an UiTPAS API error occurred.
*/
public function getPrice(Inquiry $inquiry)
{
$dateOfBirth = $postalCode = $voucherNumber = null;
if (!is_null($inquiry->getDateOfBirth())) {
$dateOfBirth = $inquiry->getDateOfBirth()
->toNativeDateTime()
->getTimestamp();
}
if (!is_null($inquiry->getPostalCode())) {
$postalCode = $inquiry->getPostalCode()
->toNative();
}
if (!is_null($inquiry->getVoucherNumber())) {
$voucherNumber = $inquiry->getVoucherNumber()
->toNative();
}
$cfPrice = $this->getUitpasService()->getPriceByUitpas(
$inquiry->getUiTPASNumber()->toNative(),
$inquiry->getReason()->toNative(),
$dateOfBirth,
$postalCode,
$voucherNumber,
$this->getCounterConsumerKey()
);
return Price::fromCultureFeedUiTPASPrice($cfPrice);
}
}