Skip to content

Commit

Permalink
[EXTERNAL] Fixes Amazon subscription period parsing (#1813) by @tessm…
Browse files Browse the repository at this point in the history
…erandre (#1828)

### Checklist
- [x] If applicable, unit tests
- [x] If applicable, create follow-up issues for `purchases-ios` and
hybrids

### Motivation
<!-- Why is this change required? What problem does it solve? --> Amazon
subscription periods were being incorrectly parsed.


https://developer.amazon.com/docs/in-app-purchasing/iap-implement-iap.html#successful-request

<!-- Please link to issues following this format: Resolves #999999 -->
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 <tessmerandre@gmail.com>
  • Loading branch information
tonidero and tessmerandre authored Aug 30, 2024
1 parent e05b91a commit 48957cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(" ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down

0 comments on commit 48957cd

Please sign in to comment.