Skip to content

Commit 687b429

Browse files
committed
bug fix (Reading un defined properties )
1 parent 1cf4400 commit 687b429

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

src/Response.php

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

tests/SsentezoWalletTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
namespace SsentezoWallet\Tests;
44

5-
use SsentezoWallet\SentezoWallet;
5+
use Codelords\SsentezoWallet\SsentezoWallet;
66
use PHPUnit\Framework\TestCase;
77

88
class SsentezoWalletTest extends TestCase
99
{
1010
public function testCanInstantiateSsentezoWallet()
1111
{
12-
$ssentezoWallet = new SentezoWallet($this->username, $this->password);
12+
$ssentezoWallet = new SsentezoWallet($this->username, $this->password);
1313
$this->assertInstanceOf(SentezoWallet::class, $ssentezoWallet);
1414
}
1515
public function testCanSetEnvironment()
1616
{
17-
$ssentezoWallet = new SentezoWallet($this->username, $this->password);
17+
$ssentezoWallet = new SsentezoWallet($this->username, $this->password);
1818
$ssentezoWallet->setEnvironment("sandbox");
1919
$this->assertEquals("sandbox", $ssentezoWallet->getEnvironment());
2020

0 commit comments

Comments
 (0)