1+ <?php
2+
3+ namespace Alma \API \Entities \DTO \MerchantBusinessEvent ;
4+
5+
6+ use Alma \API \Exceptions \ParametersException ;
7+
8+ class OrderConfirmedBusinessEvent extends AbstractBusinessEvent
9+ {
10+
11+ /**
12+ * @var bool
13+ */
14+ private $ almaP1XStatus ;
15+ /**
16+ * @var bool
17+ */
18+ private $ almaBNPLStatus ;
19+ /**
20+ * @var bool
21+ */
22+ private $ wasBNPLEligible ;
23+ /**
24+ * @var string
25+ */
26+ private $ orderId ;
27+ /**
28+ * @var string
29+ */
30+ private $ cartId ;
31+ /**
32+ * @var string | null
33+ */
34+ private $ almaPaymentId ;
35+
36+
37+ /**
38+ * For non alma payment, almaPaymentId should be null
39+ * For Alma payment, almaPaymentId should be a string
40+ *
41+ * @param bool $isAlmaP1X
42+ * @param bool $isAlmaBNPL
43+ * @param bool $wasBNPLEligible
44+ * @param string $orderId
45+ * @param string $cartId
46+ * @param string | null $almaPaymentId
47+ * @throws ParametersException
48+ */
49+ public function __construct ($ isAlmaP1X , $ isAlmaBNPL , $ wasBNPLEligible , $ orderId , $ cartId , $ almaPaymentId = null )
50+ {
51+ $ this ->eventType = 'order_confirmed ' ;
52+ $ this ->almaP1XStatus = $ isAlmaP1X ;
53+ $ this ->almaBNPLStatus = $ isAlmaBNPL ;
54+ $ this ->wasBNPLEligible = $ wasBNPLEligible ;
55+ $ this ->orderId = $ orderId ;
56+ $ this ->cartId = $ cartId ;
57+ $ this ->almaPaymentId = $ almaPaymentId ;
58+ $ this ->validateData ();
59+ }
60+
61+ /**
62+ * @return bool
63+ */
64+ public function isAlmaP1X ()
65+ {
66+ return $ this ->almaP1XStatus ;
67+ }
68+
69+ /**
70+ * @return bool
71+ */
72+ public function isAlmaBNPL ()
73+ {
74+ return $ this ->almaBNPLStatus ;
75+ }
76+
77+ /**
78+ * Was eligible at the time of payment
79+ *
80+ * @return bool
81+ */
82+ public function wasBNPLEligible ()
83+ {
84+ return $ this ->wasBNPLEligible ;
85+ }
86+
87+ /**
88+ * @return string
89+ */
90+ public function getOrderId ()
91+ {
92+ return $ this ->orderId ;
93+ }
94+
95+ /**
96+ * @return string
97+ */
98+ public function getCartId ()
99+ {
100+ return $ this ->cartId ;
101+ }
102+
103+ /**
104+ * @return string | null
105+ */
106+ public function getAlmaPaymentId ()
107+ {
108+ return $ this ->almaPaymentId ;
109+ }
110+
111+ /**
112+ * Check if it is an Alma payment
113+ *
114+ * @return bool
115+ */
116+ public function isAlmaPayment ()
117+ {
118+ return $ this ->almaP1XStatus || $ this ->almaBNPLStatus ;
119+ }
120+
121+ /**
122+ * @return void
123+ * @throws ParametersException
124+ */
125+ protected function validateData ()
126+ {
127+ if (
128+ !is_bool ($ this ->almaP1XStatus ) ||
129+ !is_bool ($ this ->almaBNPLStatus ) ||
130+ !is_bool ($ this ->wasBNPLEligible ) ||
131+ (!is_string ($ this ->orderId ) || empty ($ this ->orderId )) ||
132+ (!is_string ($ this ->cartId ) || empty ($ this ->cartId )) ||
133+ // Alma payment id should be absent for non Alma payments
134+ (!$ this ->isAlmaPayment () && !is_null ($ this ->almaPaymentId ))
135+ )
136+ {
137+ throw new ParametersException ('Invalid data type in OrderConfirmedBusinessEvent constructor ' );
138+ }
139+
140+ //Alma payment id for Alma payment, Must be a string
141+ if (
142+ $ this ->isAlmaPayment () &&
143+ (!is_string ($ this ->almaPaymentId ) || empty ($ this ->almaPaymentId ))
144+ )
145+ {
146+ throw new ParametersException ('Alma payment id is mandatory for Alma payment ' );
147+ }
148+ }
149+
150+
151+ }
0 commit comments