From 48957cd2b2d8909a1ee5c64b1e31f89718bc21f9 Mon Sep 17 00:00:00 2001 From: Toni Rico Date: Fri, 30 Aug 2024 12:32:57 +0200 Subject: [PATCH] [EXTERNAL] Fixes Amazon subscription period parsing (#1813) by @tessmerandre (#1828) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### 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. Contributed by @tessmerandre --------- Co-authored-by: André Tessmer --- .../purchases/amazon/storeProductConversions.kt | 8 ++++++-- .../revenuecat/purchases/amazon/ProductConverterTest.kt | 2 ++ 2 files changed, 8 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..ddd094ad95 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,12 @@ 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")),