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

iosMain.com.revenuecat.purchases.kmp.mappings.StoreTransaction.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.StoreTransaction
import cocoapods.PurchasesHybridCommon.RCStoreTransaction as IosStoreTransaction

public fun IosStoreTransaction.toStoreTransaction(): StoreTransaction =
    StoreTransaction(
        transactionId = transactionIdentifier(),
        productIds = listOf(productIdentifier()),
        purchaseTime = purchaseDate().toEpochMilliseconds(),
    )

public fun buildStoreTransaction(storeTransactionMap: Map): Result {
    val transactionId = storeTransactionMap["transactionIdentifier"] as? String
    val productId = storeTransactionMap["productIdentifier"] as? String
    val purchaseTime = (storeTransactionMap["purchaseDateMillis"] as? Number)?.toLong()

    if(transactionId == null) {
        return Result.failure(IllegalArgumentException("Expected a non-null transactionIdentifier"))
    }

    if(productId == null) {
        return Result.failure(IllegalArgumentException("Expected a non-null productIdentifier"))
    }

    if(purchaseTime == null) {
        return Result.failure(IllegalArgumentException("Expected a non-null purchaseDateMillis"))
    }

    return Result.success(
        StoreTransaction(
            transactionId = transactionId,
            productIds = listOf(productId),
            purchaseTime = purchaseTime
        )
    )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy