Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Adds managementUrl param to CustomerInfo and appUserId config function #6

Merged
merged 1 commit into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ internal fun RevenueCatEntitlementInfo.asEntitlementInfo(): EntitlementInfo {
public fun RevenueCatCustomerInfo.asCustomerInfo(): CustomerInfo {
return CustomerInfo(
originalAppUserId = this.originalAppUserId,
entitlements = entitlements.asEntitlementInfos()
entitlements = entitlements.asEntitlementInfos(),
managementURL = managementURL.toString()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@ package com.mmk.kmprevenuecat.purchases
import android.content.Context
import com.mmk.kmprevenuecat.purchases.data.CustomerInfo
import com.mmk.kmprevenuecat.purchases.data.LogInResult
import com.revenuecat.purchases.CustomerInfo as RevenueCatCustomerInfo
import com.revenuecat.purchases.PurchasesConfiguration
import com.revenuecat.purchases.PurchasesError
import com.revenuecat.purchases.PurchasesException
import com.revenuecat.purchases.awaitCustomerInfo
import com.revenuecat.purchases.getCustomerInfoWith
import com.revenuecat.purchases.interfaces.ReceiveCustomerInfoCallback
import java.util.jar.Attributes
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine
import com.revenuecat.purchases.CustomerInfo as RevenueCatCustomerInfo
import com.revenuecat.purchases.Purchases as RevenueCatPurchases
import com.revenuecat.purchases.interfaces.LogInCallback as RevenueCatLoginCallback

Expand All @@ -24,8 +17,12 @@ internal class PurchasesImpl(private val context: Context) : Purchases {
RevenueCatPurchases.logLevel = value.asRevenueCatLogLevel()
}

override fun configure(apiKey: String) {
RevenueCatPurchases.configure(PurchasesConfiguration.Builder(context, apiKey).build())
override fun configure(apiKey: String, appUserId: String?) {
RevenueCatPurchases.configure(
PurchasesConfiguration.Builder(context, apiKey)
.appUserID(appUserId)
.build()
)
}

@OptIn(KMPRevenueCatInternalApi::class)
Expand Down Expand Up @@ -73,7 +70,7 @@ internal class PurchasesImpl(private val context: Context) : Purchases {
})
}

override fun setAttributes(attributes: Map<String,String?>){
override fun setAttributes(attributes: Map<String, String?>) {
RevenueCatPurchases.sharedInstance.setAttributes(attributes)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface Purchases {

public var logLevel: LogLevel

public fun configure(apiKey: String)
public fun configure(apiKey: String, appUserId: String? = null)

public fun login(appUserId: String, onResult: (Result<LogInResult>) -> Unit)
public fun logOut(onResult: (Result<CustomerInfo>) -> Unit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package com.mmk.kmprevenuecat.purchases.data

public data class CustomerInfo(
val originalAppUserId: String,
val entitlements: EntitlementInfos
val entitlements: EntitlementInfos,
val managementURL: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ internal fun RCEntitlementInfo.asEntitlementInfo(): EntitlementInfo {
public fun RCCustomerInfo.asCustomerInfo(): CustomerInfo {
return CustomerInfo(
originalAppUserId = originalAppUserId(),
entitlements = entitlements().asEntitlementInfos()
entitlements = entitlements().asEntitlementInfos(),
managementURL = managementURL().toString()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if absoluteString and toString for NSUrl is the same.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced toString with absoluteString

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Now that you mention it, maybe I was a bit too fast when implementing this to be a String in CustomerInfo. Might actually be nice to add a wrapper class that could return the url as a String and have nativeUrl property exposing the original Uri on Android and the original NSURL on iOS.

Firebase-kotlin-sdk does this.

)
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import cocoapods.RevenueCat.configureWithAPIKey
import com.mmk.kmprevenuecat.purchases.data.CustomerInfo
import com.mmk.kmprevenuecat.purchases.data.LogInResult
import kotlinx.cinterop.ExperimentalForeignApi
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine


@OptIn(ExperimentalForeignApi::class)
Expand All @@ -18,8 +15,8 @@ internal class PurchasesImpl : Purchases {
RCPurchases.setLogLevel(value.asRevenueCatLogLevel())
}

override fun configure(apiKey: String) {
RCPurchases.configureWithAPIKey(apiKey)
override fun configure(apiKey: String, appUserId: String?) {
RCPurchases.configureWithAPIKey(apiKey, appUserId)
}

@OptIn(KMPRevenueCatInternalApi::class)
Expand Down
Loading