All Downloads are FREE. Search and download functionalities are using the official Maven repository.

iosMain.com.revenuecat.purchases.kmp.mappings.CustomerInfo.ios.kt Maven / Gradle / Ivy

There is a newer version: 1.3.2+13.9.0
Show newest version
package com.revenuecat.purchases.kmp.mappings

import com.revenuecat.purchases.kmp.mappings.ktx.toEpochMilliseconds
import com.revenuecat.purchases.kmp.models.CustomerInfo
import platform.Foundation.dictionaryWithValuesForKeys
import platform.darwin.NSObject
import cocoapods.PurchasesHybridCommon.RCCustomerInfo as IosCustomerInfo

public fun IosCustomerInfo.toCustomerInfo(): CustomerInfo {
    @Suppress("UNCHECKED_CAST")
    return CustomerInfo(
        activeSubscriptions = activeSubscriptions() as Set,
        allExpirationDateMillis = allPurchasedProductIdentifiers().associate { productId ->
            productId as String to expirationDateForProductIdentifier(productId)?.toEpochMilliseconds()
        },
        allPurchaseDateMillis = allPurchasedProductIdentifiers().associate { productId ->
            productId as String to purchaseDateForProductIdentifier(productId)?.toEpochMilliseconds()
        },
        allPurchasedProductIdentifiers = allPurchasedProductIdentifiers() as Set,
        entitlements = entitlements().toEntitlementInfos(),
        firstSeenMillis = firstSeen().toEpochMilliseconds(),
        latestExpirationDateMillis = latestExpirationDate()?.toEpochMilliseconds(),
        managementUrlString = managementURL()?.absoluteString,
        nonSubscriptionTransactions = nonSubscriptions().map {
            val map = (it as NSObject)
                .dictionaryWithValuesForKeys(
                    listOf("transactionIdentifier", "productIdentifier", "purchaseDate")
                ).mapKeys { (key, _) -> key as String }
            map.toTransaction()
        },
        originalAppUserId = originalAppUserId(),
        originalApplicationVersion = null,
        originalPurchaseDateMillis = originalPurchaseDate()?.toEpochMilliseconds(),
        requestDateMillis = requestDate().toEpochMilliseconds()
    )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy