From 00b524dacc3968a012c6bdd10692c62531585796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Tessmer?= Date: Fri, 30 Aug 2024 05:03:17 -0300 Subject: [PATCH 1/2] Fixes Amazon subscription period parsing (#1813) ### Checklist - [x] If applicable, unit tests - [x] If applicable, create follow-up issues for `purchases-ios` and hybrids ### Motivation Amazon subscription periods were being incorrectly parsed. https://developer.amazon.com/docs/in-app-purchasing/iap-implement-iap.html#successful-request Resolves #1771 ### Description Amazon returns annual and semiannual subscription periods as `Annual` and `SemiAnnual`. Please look at the [docs](https://developer.amazon.com/docs/in-app-purchasing/iap-implement-iap.html#successful-request) for more information. --- .../revenuecat/purchases/amazon/storeProductConversions.kt | 6 ++++-- .../com/revenuecat/purchases/amazon/ProductConverterTest.kt | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/purchases/src/main/kotlin/com/revenuecat/purchases/amazon/storeProductConversions.kt b/purchases/src/main/kotlin/com/revenuecat/purchases/amazon/storeProductConversions.kt index 34b53359dc..8e06e6e240 100644 --- a/purchases/src/main/kotlin/com/revenuecat/purchases/amazon/storeProductConversions.kt +++ b/purchases/src/main/kotlin/com/revenuecat/purchases/amazon/storeProductConversions.kt @@ -47,8 +47,10 @@ internal fun String.createPeriod(): Period? { "Monthly" -> Period(1, Period.Unit.MONTH, "P1M") "BiMonthly" -> Period(2, Period.Unit.MONTH, "P2M") "Quarterly" -> Period(3, Period.Unit.MONTH, "P3M") - "SemiAnnually" -> Period(6, Period.Unit.MONTH, "P6M") - "Annually" -> Period(1, Period.Unit.YEAR, "P1Y") + "SemiAnnually", + "SemiAnnual" -> Period(6, Period.Unit.MONTH, "P6M") + "Annually", + "Annual" -> Period(1, Period.Unit.YEAR, "P1Y") // Handle "7 Days" or "14 Days" or "1 Month" just in case else -> this.split(" ") diff --git a/purchases/src/test/java/com/revenuecat/purchases/amazon/ProductConverterTest.kt b/purchases/src/test/java/com/revenuecat/purchases/amazon/ProductConverterTest.kt index e18d0f0c12..f242082837 100644 --- a/purchases/src/test/java/com/revenuecat/purchases/amazon/ProductConverterTest.kt +++ b/purchases/src/test/java/com/revenuecat/purchases/amazon/ProductConverterTest.kt @@ -154,7 +154,9 @@ class PeriodParsingTest(private val periodRaw: String, private val periodExpecte arrayOf("BiMonthly", Period(2, Period.Unit.MONTH, "P2M")), arrayOf("Quarterly", Period(3, Period.Unit.MONTH, "P3M")), arrayOf("SemiAnnually", Period(6, Period.Unit.MONTH, "P6M")), + arrayOf("SemiAnnual", Period(6, Period.Unit.MONTH, "P6M")), arrayOf("Annually", Period(1, Period.Unit.YEAR, "P1Y")), + arrayOf("Annual", Period(1, Period.Unit.YEAR, "P1Y")), arrayOf("7 Days", Period(7, Period.Unit.DAY, "P7D")), arrayOf("14 Weeks", Period(14, Period.Unit.WEEK, "P14W")), arrayOf("1 Year", Period(1, Period.Unit.YEAR, "P1Y")), From c855c7f23eb2378df32f08dd5527f183e32bde46 Mon Sep 17 00:00:00 2001 From: Toni Rico Date: Fri, 30 Aug 2024 10:43:44 +0200 Subject: [PATCH 2/2] Fix detekt --- .../revenuecat/purchases/amazon/storeProductConversions.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/purchases/src/main/kotlin/com/revenuecat/purchases/amazon/storeProductConversions.kt b/purchases/src/main/kotlin/com/revenuecat/purchases/amazon/storeProductConversions.kt index 8e06e6e240..ddd094ad95 100644 --- a/purchases/src/main/kotlin/com/revenuecat/purchases/amazon/storeProductConversions.kt +++ b/purchases/src/main/kotlin/com/revenuecat/purchases/amazon/storeProductConversions.kt @@ -48,9 +48,11 @@ internal fun String.createPeriod(): Period? { "BiMonthly" -> Period(2, Period.Unit.MONTH, "P2M") "Quarterly" -> Period(3, Period.Unit.MONTH, "P3M") "SemiAnnually", - "SemiAnnual" -> Period(6, Period.Unit.MONTH, "P6M") + "SemiAnnual", + -> Period(6, Period.Unit.MONTH, "P6M") "Annually", - "Annual" -> Period(1, Period.Unit.YEAR, "P1Y") + "Annual", + -> Period(1, Period.Unit.YEAR, "P1Y") // Handle "7 Days" or "14 Days" or "1 Month" just in case else -> this.split(" ")