Skip to content

Commit fd7a015

Browse files
committed
Disable GET_GROSS_PRICES option for TME info provider when using private key. Otherwise we receive an error.
This fixes issue #838
1 parent 1e19ff2 commit fd7a015

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ PROVIDER_TME_CURRENCY=EUR
143143
PROVIDER_TME_LANGUAGE=en
144144
# The country to get results for
145145
PROVIDER_TME_COUNTRY=DE
146-
# Set this to 1 to get gross prices (including VAT) instead of net prices
146+
# [DEPRECATED] Set this to 1 to get gross prices (including VAT) instead of net prices
147+
# With private API keys, this option cannot be used anymore is ignored by Part-DB. The VAT inclusion depends on your TME account settings.
147148
PROVIDER_TME_GET_GROSS_PRICES=1
148149

149150
# Octopart / Nexar Provider:

src/Services/InfoProviderSystem/Providers/TMEClient.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ public function isUsable(): bool
5050
return $this->token !== '' && $this->secret !== '';
5151
}
5252

53+
/**
54+
* Returns true if the client is using a private (account related token) instead of a deprecated anonymous token
55+
* to authenticate with TME.
56+
* @return bool
57+
*/
58+
public function isUsingPrivateToken(): bool
59+
{
60+
//Private tokens are longer than anonymous ones (50 instead of 45 characters)
61+
return strlen($this->token) > 45;
62+
}
5363

5464
/**
5565
* Generates the signature for the given action and parameters.

src/Services/InfoProviderSystem/Providers/TMEProvider.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,19 @@ class TMEProvider implements InfoProviderInterface
3636

3737
private const VENDOR_NAME = 'TME';
3838

39+
/** @var bool If true, the prices are gross prices. If false, the prices are net prices. */
40+
private readonly bool $get_gross_prices;
41+
3942
public function __construct(private readonly TMEClient $tmeClient, private readonly string $country,
4043
private readonly string $language, private readonly string $currency,
41-
/** @var bool If true, the prices are gross prices. If false, the prices are net prices. */
42-
private readonly bool $get_gross_prices)
44+
bool $get_gross_prices)
4345
{
44-
46+
//If we have a private token, set get_gross_prices to false, as it is automatically determined by the account type then
47+
if ($this->tmeClient->isUsingPrivateToken()) {
48+
$this->get_gross_prices = false;
49+
} else {
50+
$this->get_gross_prices = $get_gross_prices;
51+
}
4552
}
4653

4754
public function getProviderInfo(): array

0 commit comments

Comments
 (0)