Skip to content

Commit

Permalink
Refactor remaining classes to new architecture and move them to `mode…
Browse files Browse the repository at this point in the history
…ls` and `mappings` modules (#160)

* Move models and mappings to models and mappings modules (WIP)

* Further moving things to mappings/models modules and move wrapped objects to mapping module

* Further changes to fix new architecture

* Add back models module api files + some paywall fixes

* Some renames and fixes

* Lots of improvements from review

* Some more review fixes

* Make data classes normal classes

* Update apis

* Refactor LogHandler

* Remove leftover print

* Wraps the native LogHandler if necessary (#162)

* Converts the last few data classes to regular classes. (#163)

---------

Co-authored-by: JayShortway <[email protected]>
  • Loading branch information
tonidero and JayShortway authored Aug 28, 2024
1 parent 99cde62 commit 54e645c
Show file tree
Hide file tree
Showing 146 changed files with 1,865 additions and 1,910 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
package com.revenuecat.purchases.kmp.apitester

import com.revenuecat.purchases.kmp.PresentedOfferingContext
import com.revenuecat.purchases.kmp.StoreKitVersion
import com.revenuecat.purchases.kmp.models.InstallmentsInfo
import com.revenuecat.purchases.kmp.models.PricingPhase
import com.revenuecat.purchases.kmp.models.SubscriptionOption
import com.revenuecat.purchases.kmp.models.isBasePlan
import com.revenuecat.purchases.kmp.models.isPrepaid

@Suppress("unused")
@Suppress("unused", "UNUSED_VARIABLE")
private class InstallmentsInfoAPI {
fun checkInstallmentsInfo(installmentsInfo: InstallmentsInfo) {
val commitmentPaymentsCount: Int = installmentsInfo.commitmentPaymentsCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@ package com.revenuecat.purchases.kmp.apitester

import com.revenuecat.purchases.kmp.Offering
import com.revenuecat.purchases.kmp.Package
import com.revenuecat.purchases.kmp.annual
import com.revenuecat.purchases.kmp.availablePackages
import com.revenuecat.purchases.kmp.get
import com.revenuecat.purchases.kmp.getMetadataString
import com.revenuecat.purchases.kmp.getPackage
import com.revenuecat.purchases.kmp.identifier
import com.revenuecat.purchases.kmp.lifetime
import com.revenuecat.purchases.kmp.metadata
import com.revenuecat.purchases.kmp.monthly
import com.revenuecat.purchases.kmp.serverDescription
import com.revenuecat.purchases.kmp.sixMonth
import com.revenuecat.purchases.kmp.threeMonth
import com.revenuecat.purchases.kmp.twoMonth
import com.revenuecat.purchases.kmp.weekly

@Suppress("unused", "UNUSED_VARIABLE")
private class OfferingAPI {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package com.revenuecat.purchases.kmp.apitester

import com.revenuecat.purchases.kmp.Offering
import com.revenuecat.purchases.kmp.Offerings
import com.revenuecat.purchases.kmp.all
import com.revenuecat.purchases.kmp.current
import com.revenuecat.purchases.kmp.get
import com.revenuecat.purchases.kmp.getOffering

@Suppress("unused", "UNUSED_VARIABLE")
private class OfferingsAPI {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.revenuecat.purchases.kmp.apitester

import com.revenuecat.purchases.kmp.Package
import com.revenuecat.purchases.kmp.identifier
import com.revenuecat.purchases.kmp.models.StoreProduct
import com.revenuecat.purchases.kmp.storeProduct

@Suppress("unused", "UNUSED_VARIABLE")
private class PackageAPI {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package com.revenuecat.purchases.kmp.apitester
import com.revenuecat.purchases.kmp.PurchasesAreCompletedBy
import com.revenuecat.purchases.kmp.StoreKitVersion

@Suppress("unused")
@Suppress("unused", "UNUSED_VARIABLE")
private class PurchasesAreCompletedByAPI {
fun check(mode: PurchasesAreCompletedBy) {
when (mode) {
is PurchasesAreCompletedBy.RevenueCat -> { }
is PurchasesAreCompletedBy.MyApp -> {
val storeKitVersion: StoreKitVersion = mode.storeKitVersion
val storeKitVersion: StoreKitVersion = mode.storeKitVersion
}
}.exhaustive
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.revenuecat.purchases.kmp.apitester

import com.revenuecat.purchases.kmp.models.StoreTransaction
import com.revenuecat.purchases.kmp.models.productIds
import com.revenuecat.purchases.kmp.models.purchaseTime
import com.revenuecat.purchases.kmp.models.transactionId

@Suppress("unused", "UNUSED_VARIABLE", "LongMethod")
private class StoreTransactionAPI {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ import com.revenuecat.purchases.kmp.Offering
import com.revenuecat.purchases.kmp.Offerings
import com.revenuecat.purchases.kmp.Purchases
import com.revenuecat.purchases.kmp.PurchasesConfiguration
import com.revenuecat.purchases.kmp.all
import com.revenuecat.purchases.kmp.current
import com.revenuecat.purchases.kmp.either.awaitOfferingsEither
import com.revenuecat.purchases.kmp.identifier

@Composable
fun MainScreen(
Expand Down
458 changes: 17 additions & 441 deletions core/api/core.api

Large diffs are not rendered by default.

482 changes: 8 additions & 474 deletions core/api/core.klib.api

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ kotlin {
api(projects.models)
}
androidMain.dependencies {
api(libs.revenuecat.common)
implementation(libs.revenuecat.common)
implementation(libs.androidx.startup)
implementation(projects.mappings)
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,26 @@ import com.revenuecat.purchases.getProductsWith
import com.revenuecat.purchases.kmp.di.AndroidProvider
import com.revenuecat.purchases.kmp.di.requireActivity
import com.revenuecat.purchases.kmp.di.requireApplication
import com.revenuecat.purchases.kmp.mappings.toAndroidBillingFeature
import com.revenuecat.purchases.kmp.mappings.toAndroidCacheFetchPolicy
import com.revenuecat.purchases.kmp.mappings.toAndroidGoogleReplacementMode
import com.revenuecat.purchases.kmp.mappings.toAndroidLogHandler
import com.revenuecat.purchases.kmp.mappings.toAndroidLogLevel
import com.revenuecat.purchases.kmp.mappings.toAndroidPackage
import com.revenuecat.purchases.kmp.mappings.toAndroidStore
import com.revenuecat.purchases.kmp.mappings.toAndroidStoreProduct
import com.revenuecat.purchases.kmp.mappings.toAndroidSubscriptionOption
import com.revenuecat.purchases.kmp.mappings.toCustomerInfo
import com.revenuecat.purchases.kmp.mappings.toHybridString
import com.revenuecat.purchases.kmp.mappings.toLogHandler
import com.revenuecat.purchases.kmp.mappings.toLogLevel
import com.revenuecat.purchases.kmp.mappings.toOfferings
import com.revenuecat.purchases.kmp.mappings.toPurchasesDelegate
import com.revenuecat.purchases.kmp.mappings.toPurchasesError
import com.revenuecat.purchases.kmp.mappings.toStore
import com.revenuecat.purchases.kmp.models.AndroidSubscriptionOption
import com.revenuecat.purchases.kmp.mappings.toStoreProduct
import com.revenuecat.purchases.kmp.mappings.toStoreTransaction
import com.revenuecat.purchases.kmp.mappings.toUpdatedCustomerInfoListener
import com.revenuecat.purchases.kmp.models.BillingFeature
import com.revenuecat.purchases.kmp.models.GoogleReplacementMode
import com.revenuecat.purchases.kmp.models.PromotionalOffer
Expand All @@ -20,8 +36,6 @@ import com.revenuecat.purchases.kmp.models.StoreProduct
import com.revenuecat.purchases.kmp.models.StoreProductDiscount
import com.revenuecat.purchases.kmp.models.StoreTransaction
import com.revenuecat.purchases.kmp.models.SubscriptionOption
import com.revenuecat.purchases.kmp.models.toAndroidBillingFeature
import com.revenuecat.purchases.kmp.models.toAndroidGoogleReplacementMode
import com.revenuecat.purchases.kmp.strings.ConfigureStrings
import com.revenuecat.purchases.logInWith
import com.revenuecat.purchases.logOutWith
Expand Down Expand Up @@ -54,7 +68,11 @@ public actual class Purchases private constructor(private val androidPurchases:
}

@JvmStatic
public actual var logHandler: LogHandler by AndroidPurchases.Companion::logHandler
public actual var logHandler: LogHandler
get() = AndroidPurchases.Companion.logHandler.toLogHandler()
set(value) {
AndroidPurchases.Companion.logHandler = value.toAndroidLogHandler()
}

@JvmStatic
public actual var proxyURL: String?
Expand Down Expand Up @@ -149,15 +167,15 @@ public actual class Purchases private constructor(private val androidPurchases:
onSuccess: (offerings: Offerings) -> Unit,
): Unit = androidPurchases.syncAttributesAndOfferingsIfNeededWith(
onError = { error -> onError(error.toPurchasesError()) },
onSuccess = onSuccess
onSuccess = { offerings -> onSuccess(offerings.toOfferings()) }
)

public actual fun getOfferings(
onError: (error: PurchasesError) -> Unit,
onSuccess: (offerings: Offerings) -> Unit,
): Unit = androidPurchases.getOfferingsWith(
onError = { error -> onError(error.toPurchasesError()) },
onSuccess = { offerings -> onSuccess(offerings) }
onSuccess = { offerings -> onSuccess(offerings.toOfferings()) }
)

public actual fun getProducts(
Expand All @@ -167,7 +185,7 @@ public actual class Purchases private constructor(private val androidPurchases:
): Unit = androidPurchases.getProductsWith(
productIds = productIds,
onError = { onError(it.toPurchasesError()) },
onGetStoreProducts = { onSuccess(it.map { product -> StoreProduct(product) }) },
onGetStoreProducts = { onSuccess(it.map { product -> product.toStoreProduct() }) },
)

public actual fun getPromotionalOffer(
Expand All @@ -190,7 +208,7 @@ public actual class Purchases private constructor(private val androidPurchases:
): Unit = androidPurchases.purchaseWith(
purchaseParams = PurchaseParams.Builder(
AndroidProvider.requireActivity(),
storeProduct.wrapped
storeProduct.toAndroidStoreProduct()
).apply {
if (isPersonalizedPrice != null) isPersonalizedPrice(isPersonalizedPrice)
if (oldProductId != null) oldProductId(oldProductId)
Expand All @@ -200,7 +218,7 @@ public actual class Purchases private constructor(private val androidPurchases:
}
.build(),
onError = { error, userCancelled -> onError(error.toPurchasesError(), userCancelled) },
onSuccess = { purchase, customerInfo -> onSuccess(purchase!!, customerInfo.toCustomerInfo()) },
onSuccess = { purchase, customerInfo -> onSuccess(purchase!!.toStoreTransaction(), customerInfo.toCustomerInfo()) },
)

public actual fun purchase(
Expand All @@ -213,7 +231,7 @@ public actual class Purchases private constructor(private val androidPurchases:
): Unit = androidPurchases.purchaseWith(
purchaseParams = PurchaseParams.Builder(
AndroidProvider.requireActivity(),
packageToPurchase
packageToPurchase.toAndroidPackage(),
).apply {
if (isPersonalizedPrice != null) isPersonalizedPrice(isPersonalizedPrice)
if (oldProductId != null) oldProductId(oldProductId)
Expand All @@ -223,7 +241,7 @@ public actual class Purchases private constructor(private val androidPurchases:
}
.build(),
onError = { error, userCancelled -> onError(error.toPurchasesError(), userCancelled) },
onSuccess = { purchase, customerInfo -> onSuccess(purchase!!, customerInfo.toCustomerInfo()) },
onSuccess = { purchase, customerInfo -> onSuccess(purchase!!.toStoreTransaction(), customerInfo.toCustomerInfo()) },
)

public actual fun purchase(
Expand All @@ -236,7 +254,7 @@ public actual class Purchases private constructor(private val androidPurchases:
): Unit = androidPurchases.purchaseWith(
purchaseParams = PurchaseParams.Builder(
AndroidProvider.requireActivity(),
(subscriptionOption as AndroidSubscriptionOption).wrapped
subscriptionOption.toAndroidSubscriptionOption(),
).apply {
if (isPersonalizedPrice != null) isPersonalizedPrice(isPersonalizedPrice)
if (oldProductId != null) oldProductId(oldProductId)
Expand All @@ -246,7 +264,7 @@ public actual class Purchases private constructor(private val androidPurchases:
}
.build(),
onError = { error, userCancelled -> onError(error.toPurchasesError(), userCancelled) },
onSuccess = { purchase, customerInfo -> onSuccess(purchase!!, customerInfo.toCustomerInfo()) },
onSuccess = { purchase, customerInfo -> onSuccess(purchase!!.toStoreTransaction(), customerInfo.toCustomerInfo()) },
)

public actual fun purchase(
Expand Down
Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 54e645c

Please sign in to comment.