@@ -11,52 +11,62 @@ class Response
1111 /**
1212 * @var string
1313 */
14- public $ message ;
14+ public $ message = "" ;
1515 /**
1616 * @var string
1717 */
18- public $ status ;
18+ public $ status = "" ;
1919 /**
2020 * @var string
2121 */
22- public $ errorCode ;
22+ public $ errorCode = "" ;
2323 /**
2424 * @var array
2525 */
26- public $ data ;
26+ public $ data = [] ;
2727
2828 /**
2929 * The external reference
3030 */
31- public $ externalReference ;
31+ public $ externalReference = "" ;
3232
3333 /**
3434 * The id of the request
3535 */
36- public $ request_id ;
36+ public $ request_id = "" ;
3737
3838 /**
3939 * Transaction status
4040 */
41- public $ transactionStatus ;
41+ public $ transactionStatus = "" ;
4242 /**
4343 * Finacial transaction id
4444 */
45- public $ financialTransactionId ;
45+ public $ financialTransactionId = "" ;
4646 /**
4747 * Response constructor.
4848 * @param \Unirest\Response $res
4949 */
5050 public function __construct (\Unirest \Response $ res )
5151 {
5252 $ body = $ res ->body ;
53- $ this ->errorCode = "" ; //$body->errorCode;
54- $ this ->message = $ body ->message ;
55- $ this ->status = "" ; //$body->status;
56- $ this ->data = (array )$ body ->data ;
57- $ this ->externalReference = $ this ->data ["externalReference " ];
58- $ this ->request_id = $ this ->data ["request_id " ];
59- $ this ->transactionStatus = $ this ->data ['transactionStatus ' ];
60- $ this ->financialTransactionId = $ this ->data ['financialTransactionId ' ] ?? "" ;
53+ if (property_exists ($ body , 'errorCode ' )) {
54+ $ this ->errorCode = $ body ->errorCode ;
55+ }
56+
57+ if (property_exists ($ body , 'message ' )) {
58+ $ this ->message = $ body ->message ;
59+ }
60+
61+ if (property_exists ($ body , 'status ' )) {
62+ $ this ->status = $ body ->status ;
63+ }
64+ if (property_exists ($ body , 'data ' )) {
65+ $ this ->data = (array )$ body ->data ;
66+ $ this ->externalReference = $ this ->data ["externalReference " ] ?? "" ;
67+ $ this ->request_id = $ this ->data ["request_id " ] ?? "" ;
68+ $ this ->transactionStatus = $ this ->data ['transactionStatus ' ] ?? "" ;
69+ $ this ->financialTransactionId = $ this ->data ['financialTransactionId ' ] ?? "" ;
70+ }
6171 }
6272}
0 commit comments