44
55namespace Paytrail \SDK ;
66
7+ use JsonSerializable ;
8+ use Paytrail \SDK \Exception \ClientException ;
79use Paytrail \SDK \Exception \HmacException ;
810use Paytrail \SDK \Exception \ValidationException ;
911use Paytrail \SDK \Util \RequestClient ;
1012use Paytrail \SDK \Util \Signature ;
13+ use Psr \Http \Client \ClientInterface ;
14+ use Psr \Http \Message \RequestFactoryInterface ;
1115
1216abstract class PaytrailClient
1317{
@@ -39,9 +43,17 @@ abstract class PaytrailClient
3943 */
4044 protected $ http_client ;
4145
42- protected function createHttpClient ()
43- {
44- $ this ->http_client = new RequestClient ();
46+ /**
47+ * @param ClientInterface|null $client
48+ * @param RequestFactoryInterface|null $requestFactory
49+ *
50+ * @return void
51+ */
52+ protected function createHttpClient (
53+ ?ClientInterface $ client = null ,
54+ ?RequestFactoryInterface $ requestFactory = null
55+ ): void {
56+ $ this ->http_client = new RequestClient ($ client , $ requestFactory );
4557 }
4658
4759 /**
@@ -59,21 +71,22 @@ abstract public function validateHmac(array $response = [], string $body = '', s
5971 /**
6072 * A wrapper for post requests.
6173 *
62- * @param string $uri The uri for the request.
63- * @param \ JsonSerializable|null $data The request payload.
64- * @param callable|null $callback The callback method to run for the decoded response.
65- * If left empty, the response is returned.
66- * @param string|null $transactionId Paytrail transaction ID when accessing single transaction.
67- * Not required for a new payment request.
68- * @param bool $signatureInHeader Checks if signature is calculated from header/body parameters
69- * @param string|null $paytrailTokenizationId Paytrail tokenization ID for getToken request
74+ * @param string $uri The uri for the request.
75+ * @param JsonSerializable|null $data The request payload.
76+ * @param callable|null $callback The callback method to run for the decoded response.
77+ * If left empty, the response is returned.
78+ * @param string|null $transactionId Paytrail transaction ID when accessing single transaction.
79+ * Not required for a new payment request.
80+ * @param bool $signatureInHeader Checks if signature is calculated from header/body parameters
81+ * @param string|null $paytrailTokenizationId Paytrail tokenization ID for getToken request
7082 *
7183 * @return mixed
7284 * @throws HmacException
85+ * @throws ClientException
7386 */
7487 protected function post (
7588 string $ uri ,
76- \ JsonSerializable $ data = null ,
89+ JsonSerializable $ data = null ,
7790 callable $ callback = null ,
7891 string $ transactionId = null ,
7992 bool $ signatureInHeader = true ,
@@ -124,13 +137,14 @@ protected function post(
124137 /**
125138 * A wrapper for get requests.
126139 *
127- * @param string $uri The uri for the request.
128- * @param callable|null $callback The callback method to run for the decoded response.
129- * If left empty, the response is returned.
130- * @param string|null $transactionId Paytrail transaction ID when accessing single transaction.
131- * Not required for a new payment request.
140+ * @param string $uri The uri for the request.
141+ * @param callable|null $callback The callback method to run for the decoded response.
142+ * If left empty, the response is returned.
143+ * @param string|null $transactionId Paytrail transaction ID when accessing single transaction.
144+ * Not required for a new payment request.
132145 *
133146 * @return mixed
147+ * @throws ClientException
134148 * @throws HmacException
135149 */
136150 protected function get (string $ uri , callable $ callback = null , string $ transactionId = null )
0 commit comments