From 646c9e92de7a19c286d0b78a71edae4c017adceb Mon Sep 17 00:00:00 2001 From: Karol Wojciechowski Date: Tue, 14 Apr 2026 06:45:02 +0200 Subject: [PATCH 1/6] mising fields --- src/Model/Fields/Alias/RecommendedAuthLevel.php | 17 +++++++++++++++++ src/Model/Objects/Transactions/Alias.php | 5 +++++ 2 files changed, 22 insertions(+) create mode 100644 src/Model/Fields/Alias/RecommendedAuthLevel.php diff --git a/src/Model/Fields/Alias/RecommendedAuthLevel.php b/src/Model/Fields/Alias/RecommendedAuthLevel.php new file mode 100644 index 0000000..ecb8f5b --- /dev/null +++ b/src/Model/Fields/Alias/RecommendedAuthLevel.php @@ -0,0 +1,17 @@ + Type::class, 'label' => Label::class, 'key' => Key::class, + 'recommendedAuthLevel' => RecommendedAuthLevel::class, 'autopayment' => Autopayment::class, 'noDelay' => Boolean::class, ]; @@ -33,6 +35,9 @@ class Alias extends Objects /** @var Key */ public $key; + /** @var RecommendedAuthLevel */ + public $recommendedAuthLevel; + /** @var Autopayment */ public $autopayment; From 2f3e7579561939f2050600d5b9678a8d7b9af7a3 Mon Sep 17 00:00:00 2001 From: Karol Wojciechowski Date: Tue, 14 Apr 2026 10:03:43 +0200 Subject: [PATCH 2/6] Blik part of API support --- src/Api/Blik/BlikApi.php | 39 +++++++++++++++++++ src/Api/TpayApi.php | 20 ++++++++++ src/Model/Fields/CreateAlias/Description.php | 16 ++++++++ src/Model/Fields/CreateAlias/Lang.php | 24 ++++++++++++ src/Model/Objects/Blik/CreateAliasPay.php | 23 +++++++++++ src/Model/Objects/RequestBody/CreateAlias.php | 34 ++++++++++++++++ src/Model/Objects/RequestBody/DeleteAlias.php | 23 +++++++++++ 7 files changed, 179 insertions(+) create mode 100644 src/Api/Blik/BlikApi.php create mode 100644 src/Model/Fields/CreateAlias/Description.php create mode 100644 src/Model/Fields/CreateAlias/Lang.php create mode 100644 src/Model/Objects/Blik/CreateAliasPay.php create mode 100644 src/Model/Objects/RequestBody/CreateAlias.php create mode 100644 src/Model/Objects/RequestBody/DeleteAlias.php diff --git a/src/Api/Blik/BlikApi.php b/src/Api/Blik/BlikApi.php new file mode 100644 index 0000000..ae4e6b2 --- /dev/null +++ b/src/Api/Blik/BlikApi.php @@ -0,0 +1,39 @@ +run(static::POST, '/blik/alias', $fields, new CreateAlias()); + } + + /** + * @param string $aliasValue + * @param string $aliasType + */ + public function getAlias($aliasValue, $aliasType) + { + $requestUrl = $this->addQueryFields( + sprintf('/blik/alias/%s', $aliasValue), + ['aliasType' => $aliasType] + ); + + return $this->run(static::GET, $requestUrl); + } + + /** + * @param string $aliasValue + * @param array $fields + */ + public function deleteAlias($aliasValue, $fields) + { + return $this->run(static::DELETE, sprintf('/blik/alias/%s', $aliasValue), $fields, new DeleteAlias()); + } +} diff --git a/src/Api/TpayApi.php b/src/Api/TpayApi.php index 66ca600..0518459 100644 --- a/src/Api/TpayApi.php +++ b/src/Api/TpayApi.php @@ -5,6 +5,7 @@ use RuntimeException; use Tpay\OpenApi\Api\Accounts\AccountsApi; use Tpay\OpenApi\Api\Authorization\AuthorizationApi; +use Tpay\OpenApi\Api\Blik\BlikApi; use Tpay\OpenApi\Api\Collect\CollectApi; use Tpay\OpenApi\Api\Refunds\RefundsApi; use Tpay\OpenApi\Api\Reports\ReportsApi; @@ -15,6 +16,9 @@ class TpayApi { + /** @var null|BlikApi */ + private $blik; + /** @var null|AccountsApi */ private $accounts; @@ -93,6 +97,22 @@ public function getToken() return $this->token; } + /** @return BlikApi */ + public function blik() + { + $this->authorize(); + if (null === $this->blik) { + $this->blik = (new BlikApi($this->token, $this->productionMode)) + ->overrideApiUrl($this->apiUrl); + + if ($this->clientName) { + $this->blik->setClientName($this->clientName); + } + } + + return $this->blik; + } + /** @return AccountsApi */ public function accounts() { diff --git a/src/Model/Fields/CreateAlias/Description.php b/src/Model/Fields/CreateAlias/Description.php new file mode 100644 index 0000000..58e91c4 --- /dev/null +++ b/src/Model/Fields/CreateAlias/Description.php @@ -0,0 +1,16 @@ + BlikPaymentData::class, + ]; + + /** @var BlikPaymentData */ + public $blikPaymentData; + + public function getRequiredFields() + { + return [ + $this->blikPaymentData, + ]; + } +} diff --git a/src/Model/Objects/RequestBody/CreateAlias.php b/src/Model/Objects/RequestBody/CreateAlias.php new file mode 100644 index 0000000..7f6d82c --- /dev/null +++ b/src/Model/Objects/RequestBody/CreateAlias.php @@ -0,0 +1,34 @@ + Description::class, + 'lang' => Lang::class, + 'pay' => CreateAliasPay::class, + ]; + + /** @var Description */ + public $description; + + /** @var Lang */ + public $lang; + + /** @var CreateAliasPay */ + public $pay; + + public function getRequiredFields() + { + return [ + $this->description, + $this->pay, + ]; + } +} diff --git a/src/Model/Objects/RequestBody/DeleteAlias.php b/src/Model/Objects/RequestBody/DeleteAlias.php new file mode 100644 index 0000000..7a3553a --- /dev/null +++ b/src/Model/Objects/RequestBody/DeleteAlias.php @@ -0,0 +1,23 @@ + Type::class, + ]; + + /** @var Type */ + public $aliasType; + + public function getRequiredFields() + { + return [ + $this->aliasType, + ]; + } +} From 07f480da49676b54e2b099855be66e729ec16758 Mon Sep 17 00:00:00 2001 From: Karol Wojciechowski Date: Mon, 4 May 2026 10:03:47 +0200 Subject: [PATCH 3/6] Fixed encoding --- src/Curl/Curl.php | 2 +- .../Autopayment/SingleLimitAmount.php | 4 +- .../Autopayment/TotalLimitAmount.php | 4 +- tests/Api/Blik/BlikApiTest.php | 98 +++++++++++++++++++ 4 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 tests/Api/Blik/BlikApiTest.php diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 2a1a8dc..f299801 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -193,7 +193,7 @@ private function setCurlMethod($curl) case 'POST': curl_setopt($curl, CURLOPT_POST, 1); if (!empty($this->postData)) { - $json = json_encode($this->postData); + $json = json_encode($this->postData, JSON_PRESERVE_ZERO_FRACTION); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); } break; diff --git a/src/Model/Fields/BlikPaymentData/Autopayment/SingleLimitAmount.php b/src/Model/Fields/BlikPaymentData/Autopayment/SingleLimitAmount.php index d1fc45e..4fc33b2 100644 --- a/src/Model/Fields/BlikPaymentData/Autopayment/SingleLimitAmount.php +++ b/src/Model/Fields/BlikPaymentData/Autopayment/SingleLimitAmount.php @@ -5,10 +5,10 @@ use Tpay\OpenApi\Model\Fields\Field; /** - * @method getValue(): string + * @method getValue(): float */ class SingleLimitAmount extends Field { protected $name = __CLASS__; - protected $type = self::INT; + protected $type = self::NUMBER; } diff --git a/src/Model/Fields/BlikPaymentData/Autopayment/TotalLimitAmount.php b/src/Model/Fields/BlikPaymentData/Autopayment/TotalLimitAmount.php index 9bfdb41..7efb715 100644 --- a/src/Model/Fields/BlikPaymentData/Autopayment/TotalLimitAmount.php +++ b/src/Model/Fields/BlikPaymentData/Autopayment/TotalLimitAmount.php @@ -5,10 +5,10 @@ use Tpay\OpenApi\Model\Fields\Field; /** - * @method getValue(): string + * @method getValue(): float */ class TotalLimitAmount extends Field { protected $name = __CLASS__; - protected $type = self::INT; + protected $type = self::NUMBER; } diff --git a/tests/Api/Blik/BlikApiTest.php b/tests/Api/Blik/BlikApiTest.php new file mode 100644 index 0000000..f8557d9 --- /dev/null +++ b/tests/Api/Blik/BlikApiTest.php @@ -0,0 +1,98 @@ +createBlikApiWithCurlMock('"ok"'); + + $result = $blikApi->createAlias($fields); + + self::assertSame('ok', $result); + } + + public function testGetAlias() + { + $blikApi = $this->createBlikApiWithCurlMock('"ok"'); + + $result = $blikApi->getAlias('some-alias-value', 'PAYID'); + + self::assertSame('ok', $result); + } + + public function testDeleteAlias() + { + $blikApi = $this->createBlikApiWithCurlMock('"ok"'); + + $result = $blikApi->deleteAlias('some-alias-value', ['aliasType' => 'PAYID']); + + self::assertSame('ok', $result); + } + + public static function dataCreateAlias() + { + $fields = [ + 'description' => 'YourGroceryShop payments', + 'pay' => [ + 'blikPaymentData' => [ + 'blikToken' => '123456', + 'type' => 0, + ], + ], + ]; + + yield 'without lang' => [$fields]; + + $fields['lang'] = 'pl'; + + yield 'with lang' => [$fields]; + + $fields['pay']['blikPaymentData']['aliases'] = [ + 'value' => 'TPAY_ALIAS_1', + 'type' => 'PAYID', + 'label' => 'YourGroceryShop, the best shop for your grocery needs', + 'autopayment' => [ + 'model' => 'A', + 'frequency' => '17D', + 'singleLimitAmount' => 100, + 'totalLimitAmount' => 1000, + 'currency' => 'PLN', + 'initDate' => '2025-01-01T00:00:00+00:00', + 'expirationDate' => '2028-01-01T00:00:00+00:00', + ], + ]; + + yield 'with aliases and autopayment' => [$fields]; + + $fields['pay']['blikPaymentData']['type'] = 2; + unset($fields['pay']['blikPaymentData']['blikToken']); + + yield 'autopayment type 2 without blikToken' => [$fields]; + } + + private function createBlikApiWithCurlMock($response) + { + $accessToken = $this->createMock(AccessToken::class); + + $token = $this->createMock(Token::class); + $token->access_token = $accessToken; + + $blikApi = new BlikApi($token, false); + + CurlMock::setConsecutiveReturnedTransfers($response); + + return $blikApi; + } +} From bf0828bd65fc2737a3424a5c8560bc4cf758b357 Mon Sep 17 00:00:00 2001 From: Karol Wojciechowski Date: Tue, 12 May 2026 09:17:34 +0200 Subject: [PATCH 4/6] Fix DELETE method --- src/Curl/Curl.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index f299801..59e2ff5 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -203,7 +203,8 @@ private function setCurlMethod($curl) case 'DELETE': curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE'); if (!empty($this->postData)) { - curl_setopt($curl, CURLOPT_POSTFIELDS, $this->postData); + $json = json_encode($this->postData, JSON_PRESERVE_ZERO_FRACTION); + curl_setopt($curl, CURLOPT_POSTFIELDS, $json); } break; case 'GET': From 02cd90988de18b165ae21675fb7a996efd85a568 Mon Sep 17 00:00:00 2001 From: Karol Wojciechowski Date: Tue, 12 May 2026 09:19:58 +0200 Subject: [PATCH 5/6] Method fix --- src/Curl/Curl.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 59e2ff5..8bcd9b8 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -205,6 +205,7 @@ private function setCurlMethod($curl) if (!empty($this->postData)) { $json = json_encode($this->postData, JSON_PRESERVE_ZERO_FRACTION); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE'); } break; case 'GET': From 473867eee61283b39b9aef18aa3db8430bc16558 Mon Sep 17 00:00:00 2001 From: Karol Wojciechowski Date: Tue, 12 May 2026 09:36:52 +0200 Subject: [PATCH 6/6] Fix --- src/Dictionary/HttpCodesDictionary.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Dictionary/HttpCodesDictionary.php b/src/Dictionary/HttpCodesDictionary.php index 6ee8b77..8c3ee48 100644 --- a/src/Dictionary/HttpCodesDictionary.php +++ b/src/Dictionary/HttpCodesDictionary.php @@ -9,6 +9,7 @@ class HttpCodesDictionary 200 => 'OK - default successful outcome of the request', 201 => 'Created - successfully created a new object', 202 => 'Accepted - successfully created a new object, but requires further action', + 204 => 'No Content - successful outcome of the request, but no content to return', ]; const HTTP_ERROR_CODES = [