11/*
2- * Copyright (c) 2024-2025 Joachim Ansorg.
2+ * Copyright (c) 2024-2026 Joachim Ansorg.
33 * SPDX-License-Identifier: AGPL-3.0-or-later
44 */
55
@@ -15,6 +15,7 @@ import dev.ja.marketplace.client.model.CustomerType
1515import dev.ja.marketplace.client.model.LicensePeriod
1616import dev.ja.marketplace.client.model.PluginPriceInfo
1717import dev.ja.marketplace.services.Countries
18+ import dev.ja.marketplace.services.Country
1819import dev.ja.marketplace.services.CountryIsoCode
1920import org.javamoney.moneta.FastMoney
2021import org.javamoney.moneta.Money
@@ -50,7 +51,27 @@ data class PluginPricing(
5051 licensePeriod : LicensePeriod ,
5152 continuityDiscount : ContinuityDiscount ,
5253 ): MonetaryAmount ? {
53- return basePriceCache.get(PricingCacheKey (customerInfo.country, customerInfo.type, licensePeriod, continuityDiscount)) { key ->
54+ val country = customerInfo.country
55+ val basePrice = getBasePriceByCountry(country, customerInfo.type, licensePeriod, continuityDiscount)
56+ if (basePrice != null ) {
57+ return basePrice
58+ }
59+
60+ // Attempt to fall back to US base price for currency USD. JetBrains' data is missing the country sometimes.
61+ if (country.isEmpty()) {
62+ return getBasePriceByCountry(Country .UNITED_STATES , customerInfo.type, licensePeriod, continuityDiscount)
63+ }
64+
65+ return null
66+ }
67+
68+ private suspend fun getBasePriceByCountry (
69+ country : String ,
70+ customerType : CustomerType ,
71+ licensePeriod : LicensePeriod ,
72+ continuityDiscount : ContinuityDiscount
73+ ): MonetaryAmount ? {
74+ return basePriceCache.get(PricingCacheKey (country, customerType, licensePeriod, continuityDiscount)) { key ->
5475 getBasePriceInner(key.country, key.customerType, key.licensePeriod, key.continuityDiscount) ? : NoBasePriceValue
5576 }.takeIf { it != = NoBasePriceValue }
5677 }
0 commit comments