99
1010namespace Matscode \Paystack \Resources ;
1111
12+ use GuzzleHttp \Exception \GuzzleException ;
1213use Matscode \Paystack \Exceptions \InvalidArgumentException ;
14+ use Matscode \Paystack \Exceptions \JsonException ;
1315use Matscode \Paystack \Interfaces \ResourceInterface ;
1416use Matscode \Paystack \Traits \ResourcePath ;
1517use Matscode \Paystack \Utility \Helpers ;
1618use Matscode \Paystack \Utility \HTTP \HTTPClient ;
1719use Matscode \Paystack \Utility \Text ;
20+ use stdClass ;
1821
1922class Transaction implements ResourceInterface
2023{
2124 use ResourcePath;
2225
2326 protected $ httpClient , $ callbackUrl , $ data ;
2427
28+ /**
29+ * @throws \Exception
30+ */
2531 public function __construct (HTTPClient $ HTTPClient )
2632 {
2733 $ this ->setBasePath ('transaction ' );
@@ -36,10 +42,11 @@ public function __construct(HTTPClient $HTTPClient)
3642 * @link https://paystack.com/docs/api/#transaction-initialize
3743 *
3844 * @param array $data
39- * @return mixed|\stdClass
40- * @throws \GuzzleHttp\Exception\GuzzleException
45+ * @return stdClass
46+ * @throws GuzzleException
47+ * @throws JsonException
4148 */
42- public function initialize (array $ data = []): \ stdClass
49+ public function initialize (array $ data = []): stdClass
4350 {
4451 $ data = array_merge ($ this ->data , $ data );
4552
@@ -54,9 +61,9 @@ public function initialize(array $data = []): \stdClass
5461
5562 $ this ->data = []; // empty the bag
5663
57- return Helpers::responseToObj ($ this ->httpClient ->post ($ this ->makePath ('initialize ' ), [
64+ return Helpers::JSONStringToObj ($ this ->httpClient ->post ($ this ->makePath ('initialize ' ), [
5865 'json ' => $ data
59- ]));
66+ ])-> getBody () );
6067 }
6168
6269 /**
@@ -66,12 +73,13 @@ public function initialize(array $data = []): \stdClass
6673 *
6774 * @param string $referenceCode
6875 *
69- * @return \StdClass
70- * @throws \GuzzleHttp\Exception\GuzzleException
76+ * @return StdClass
77+ * @throws GuzzleException
78+ * @throws JsonException
7179 */
72- public function verify (string $ referenceCode ): \ StdClass
80+ public function verify (string $ referenceCode ): StdClass
7381 {
74- return Helpers::responseToObj ($ this ->httpClient ->get ($ this ->makePath ('verify/ ' . $ referenceCode )));
82+ return Helpers::JSONStringToObj ($ this ->httpClient ->get ($ this ->makePath ('verify/ ' . $ referenceCode ))-> getBody ( ));
7583 }
7684
7785 /**
@@ -80,7 +88,8 @@ public function verify(string $referenceCode): \StdClass
8088 * @param string $reference
8189 *
8290 * @return bool
83- * @throws \GuzzleHttp\Exception\GuzzleException
91+ * @throws GuzzleException
92+ * @throws JsonException
8493 */
8594 public function isSuccessful (string $ reference ): bool
8695 {
@@ -91,7 +100,7 @@ public function isSuccessful(string $reference): bool
91100 // check if transaction is successful
92101 if (isset ($ response ->data )
93102 && is_object ($ response ->data )
94- && $ response ->status == true
103+ && $ response ->status
95104 && $ response ->data ->status == 'success '
96105 ) {
97106 $ isSuccessful = true ;
@@ -123,15 +132,15 @@ public function addMetadata(array $metadata = []): Transaction
123132 */
124133 public function setPlan (string $ plan ): Transaction
125134 {
126- // set amount to 0 to Invalid amount error when setting a plan
135+ // set amount to 0 to Invalidate amount error when setting a plan
127136 $ this ->data ['amount ' ] = 0 ;
128137 $ this ->data ['plan ' ] = $ plan ;
129138
130139 return $ this ;
131140 }
132141
133142 /**
134- * @param $email
143+ * @param string $email
135144 *
136145 * @return $this
137146 */
@@ -193,7 +202,7 @@ public function setReference(string $reference): Transaction
193202 * @return null
194203 *
195204 */
196- public function getReference ($ afterInitialize = false )
205+ public function getReference (bool $ afterInitialize = false )
197206 {
198207 return $ this ->data ['reference ' ];
199208 }
@@ -220,15 +229,16 @@ public function setCallbackUrl(string $callbackUrl): Transaction
220229 * @param int $numberOfRecords number of record per page
221230 * @param int $page page number
222231 * @param array $otherOptions
223- * @return \StdClass
224- * @throws \GuzzleHttp\Exception\GuzzleException
232+ * @return stdClass
233+ * @throws GuzzleException
234+ * @throws JsonException
225235 */
226- public function list ($ numberOfRecords = 50 , $ page = 1 , $ otherOptions = []): \ StdClass
236+ public function list (int $ numberOfRecords = 50 , int $ page = 1 , array $ otherOptions = []): stdClass
227237 {
228- return Helpers::responseToObj ($ this ->httpClient ->get ($ this ->makePath () . '? ' . http_build_query ($ otherOptions + [
238+ return Helpers::JSONStringToObj ($ this ->httpClient ->get ($ this ->makePath () . '? ' . http_build_query ($ otherOptions + [
229239 'perPage ' => $ numberOfRecords ,
230240 'page ' => $ page
231- ])));
241+ ]))-> getBody () );
232242 }
233243
234- }
244+ }
0 commit comments