From c871734f12c2079b1035374bd72898377c9cd272 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 25 Jun 2024 23:29:19 +0200 Subject: [PATCH] Better client identification with clientName in TpayApi --- src/Api/TpayApi.php | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Api/TpayApi.php b/src/Api/TpayApi.php index 3f2cc7c..fefbfb3 100644 --- a/src/Api/TpayApi.php +++ b/src/Api/TpayApi.php @@ -55,14 +55,18 @@ class TpayApi /** @var string */ private $apiUrl; + /** @var string|null */ + private $clientName; + /** * @param string $clientId * @param string $clientSecret * @param bool $productionMode * @param string $scope * @param null|string $apiUrlOverride + * @param null|string $clientName */ - public function __construct($clientId, $clientSecret, $productionMode = false, $scope = 'read', $apiUrlOverride = null) + public function __construct($clientId, $clientSecret, $productionMode = false, $scope = 'read', $apiUrlOverride = null, $clientName = null) { $this->clientId = $clientId; $this->clientSecret = $clientSecret; @@ -71,6 +75,7 @@ public function __construct($clientId, $clientSecret, $productionMode = false, $ $this->apiUrl = true === $this->productionMode ? ApiAction::TPAY_API_URL_PRODUCTION : ApiAction::TPAY_API_URL_SANDBOX; + $this->clientName = $clientName; if (null !== $apiUrlOverride) { if (!filter_var($apiUrlOverride, FILTER_VALIDATE_URL)) { throw new RuntimeException(sprintf('Invalid URL provided: %s', $apiUrlOverride)); @@ -127,6 +132,10 @@ public function accounts() if (null === $this->accounts) { $this->accounts = (new AccountsApi($this->token, $this->productionMode)) ->overrideApiUrl($this->apiUrl); + + if ($this->clientName) { + $this->accounts->setClientName($this->clientName); + } } return $this->accounts; @@ -139,6 +148,10 @@ public function authorization() if (null === $this->authorization) { $this->authorization = (new AuthorizationApi($this->token, $this->productionMode)) ->overrideApiUrl($this->apiUrl); + + if ($this->clientName) { + $this->authorization->setClientName($this->clientName); + } } return $this->authorization; @@ -151,6 +164,10 @@ public function refunds() if (null === $this->refunds) { $this->refunds = (new RefundsApi($this->token, $this->productionMode)) ->overrideApiUrl($this->apiUrl); + + if ($this->clientName) { + $this->refunds->setClientName($this->clientName); + } } return $this->refunds; @@ -163,6 +180,10 @@ public function reports() if (null === $this->reports) { $this->reports = (new ReportsApi($this->token, $this->productionMode)) ->overrideApiUrl($this->apiUrl); + + if ($this->clientName) { + $this->reports->setClientName($this->clientName); + } } return $this->reports; @@ -175,6 +196,10 @@ public function transactions() if (null === $this->transactions) { $this->transactions = (new TransactionsApi($this->token, $this->productionMode)) ->overrideApiUrl($this->apiUrl); + + if ($this->clientName) { + $this->transactions->setClientName($this->clientName); + } } return $this->transactions; @@ -190,6 +215,11 @@ private function authorize() } $authApi = (new AuthorizationApi(new Token(), $this->productionMode))->overrideApiUrl($this->apiUrl); + + if ($this->clientName) { + $authApi->setClientName($this->clientName); + } + $fields = [ 'client_id' => $this->clientId, 'client_secret' => $this->clientSecret,