Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added context keys to purchase #625

Merged
merged 11 commits into from
Aug 19, 2024
15 changes: 12 additions & 3 deletions config/detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
<ID>LongParameterList:IBillingClientWrapper.kt$IBillingClientWrapper$( activity: Activity, product: QProduct, offerId: String?, applyOffer: Boolean, updatePurchaseInfo: UpdatePurchaseInfo?, onFailed: (error: BillingError) -&gt; Unit )</ID>
<ID>LongParameterList:ManagersModule.kt$ManagersModule$( appContext: Application, repository: QRepository, propertiesStorage: UserPropertiesStorage, incrementalDelayCalculator: IncrementalDelayCalculator, appStateProvider: AppStateProvider, logger: Logger )</ID>
<ID>LongParameterList:ManagersModule.kt$ManagersModule$( repository: QRepository, preferences: SharedPreferences, eventMapper: AutomationsEventMapper, appContext: Application, activityProvider: ActivityProvider, appStateProvider: AppStateProvider )</ID>
<ID>LongParameterList:PurchaseModelInternalEnriched.kt$PurchaseModelInternalEnriched$( productId: String, val product: QProduct, offerId: String?, applyOffer: Boolean, oldProductId: String?, val oldProduct: QProduct?, updatePolicy: QPurchaseUpdatePolicy?, )</ID>
<ID>LongParameterList:QonversionBillingService.kt$QonversionBillingService$( activity: Activity, product: QProduct, offerId: String?, applyOffer: Boolean, oldProduct: QProduct, updatePolicy: QPurchaseUpdatePolicy? )</ID>
<ID>LongParameterList:QonversionBillingService.kt$QonversionBillingService$( private val mainHandler: Handler, private val purchasesListener: PurchasesListener, private val logger: Logger, private val isAnalyticsMode: Boolean, private val billingClientHolder: BillingClientHolder, private val billingClientWrapper: BillingClientWrapper, private val legacyBillingClientWrapper: LegacyBillingClientWrapper )</ID>
<ID>LongParameterList:RepositoryModule.kt$RepositoryModule$( retrofit: Retrofit, environmentProvider: EnvironmentProvider, config: InternalConfig, logger: Logger, apiErrorMapper: ApiErrorMapper, sharedPreferences: SharedPreferences, delayCalculator: IncrementalDelayCalculator )</ID>
Expand Down Expand Up @@ -90,6 +89,8 @@
<ID>MaxLineLength:AutomationsEventMapperTest.kt$AutomationsEventMapperTest.GetEventFromRemoteMessage$"{\"name\": \"subscription_started\", \"happened\": $timeInSec}" to AutomationsEventType.SubscriptionStarted</ID>
<ID>MaxLineLength:AutomationsEventMapperTest.kt$AutomationsEventMapperTest.GetEventFromRemoteMessage$"{\"name\": \"subscription_upgraded\", \"happened\": $timeInSec}" to AutomationsEventType.SubscriptionUpgraded</ID>
<ID>MaxLineLength:AutomationsEventMapperTest.kt$AutomationsEventMapperTest.GetEventFromRemoteMessage$"{\"name\": \"trial_billing_retry_entered\", \"happened\": $timeInSec}" to AutomationsEventType.TrialBillingRetry</ID>
<ID>MaxLineLength:GooglePurchaseConverter.kt$GooglePurchaseConverter$override</ID>
<ID>MaxLineLength:LaunchResultCacheWrapperTest.kt$LaunchResultCacheWrapperTest$cacheWrapper = LaunchResultCacheWrapper(mockMoshi, mockPrefsCache, mockCacheConfigProvider, mockQFallbacksService)</ID>
<ID>MaxLineLength:OutagerIntegrationTest.kt$OutagerIntegrationTest$"lgeigljfpmeoddkcebkcepjc.AO-J1Oy305qZj99jXTPEVBN8UZGoYAtjDLj4uTjRQvUFaG0vie-nr6VBlN0qnNDMU8eJR-sI7o3CwQyMOEHKl8eJsoQ86KSFzxKBR07PSpHLI_o7agXhNKY"</ID>
<ID>MaxLineLength:OutagerIntegrationTest.kt$OutagerIntegrationTest$purchaseToken = "lgeigljfpmeoddkcebkcepjc.AO-J1Oy305qZj99jXTPEVBN8UZGoYAtjDLj4uTjRQvUFaG0vie-nr6VBlN0qnNDMU8eJR-sI7o3CwQyMOEHKl8eJsoQ86KSFzxKBR07PSpHLI_o7agXhNKY"</ID>
<ID>MaxLineLength:OutagerIntegrationTest.kt$OutagerIntegrationTest$val token = "dt70kovLQdKymNnhIY6I94:APA91bGfg6m108VFio2ZdgLR6U0B2PtqAn0hIPVU7M4jKklkMxqDUrjoThpX_K60M7CfH8IVZqtku31ei2hmjdJZDfm-bdAl7uxLDWFU8yVcA6-3wBMn3nsYmUrhYWom-qgGC7yIUYzR"</ID>
Expand All @@ -101,12 +102,15 @@
<ID>MaxLineLength:QAutomationsManager.kt$QAutomationsManager$"To override default animation, please, provide an activity context to AutomationsDelegate.contextForScreenIntent"</ID>
<ID>MaxLineLength:QAutomationsManager.kt$QAutomationsManager$getScreenTransactionAnimations(screenPresentationConfig.presentationStyle)</ID>
<ID>MaxLineLength:QEntitlementsUpdateListener.kt$QEntitlementsUpdateListener$*</ID>
<ID>MaxLineLength:QProductCenterManager.kt$QProductCenterManager$val oldProduct: QProduct? = purchaseModel.options.oldProduct ?: getProductForPurchase(purchaseModel.oldProductId, products)</ID>
<ID>MaxLineLength:QProductCenterManagerTest.kt$QProductCenterManagerTest${ Assert.assertEquals("Wrong installDate value", installDate.milliSecondsToSeconds(), installDateSlot.captured) }</ID>
<ID>MaxLineLength:QProductCenterManagerTest.kt$QProductCenterManagerTest${ Assert.assertEquals("Wrong purchaseToken value", purchaseToken, entityPurchaseSlot.captured.purchaseToken) }</ID>
<ID>MaxLineLength:QProductStoreDetails.kt$QProductStoreDetails$basePlanSubscriptionOfferDetails?.basePlan?.recurrenceMode == QProductPricingPhase.RecurrenceMode.NonRecurring</ID>
<ID>MaxLineLength:QRemoteConfigManager.kt$QRemoteConfigManager.&lt;no name provided&gt;$val remoteConfigs = baseRemoteConfigList.remoteConfigs.filter { contextKeys.contains(it.source.contextKey) }.toMutableList()</ID>
<ID>MaxLineLength:QUserPropertiesManagerTest.kt$QUserPropertiesManagerTest$fun</ID>
<ID>MaxLineLength:Qonversion.kt$Qonversion$*</ID>
<ID>MaxLineLength:Qonversion.kt$Qonversion$@Deprecated("Use new purchase() method", replaceWith = ReplaceWith("purchase(context: Activity, product: QProduct, options: QPurchaseOptions, callback: QonversionEntitlementsCallback)"))</ID>
<ID>MaxLineLength:Qonversion.kt$Qonversion$@Deprecated("Use new updatePurchase() method", replaceWith = ReplaceWith("updatePurchase(context: Activity, product: QProduct, options: QPurchaseOptions, callback: QonversionEntitlementsCallback)"))</ID>
<ID>MaxLineLength:QonversionBillingService.kt$QonversionBillingService$"updatePurchase() -&gt; Purchase was found successfully for store product: ${purchaseHistoryRecord.productId}"</ID>
<ID>MaxLineLength:QonversionBillingService.kt$QonversionBillingService$logger.debug("queryPurchaseHistoryAsync() -&gt; purchase history for $productType is retrieved ${record.getDescription()}")</ID>
<ID>MaxLineLength:QonversionConfig.kt$QonversionConfig.Builder$*</ID>
Expand All @@ -126,6 +130,8 @@
<ID>MaxLineLength:util.kt$Util.Companion$"\"offerings\":[{\"id\":\"main\",\"tag\":1,\"products\":[{\"id\":\"in_app\",\"store_id\":\"qonversion_inapp_consumable\",\"type\":2},{\"id\":\"main\",\"store_id\":\"qonversion_subs_weekly\",\"type\":0,\"duration\":0}]"</ID>
<ID>MaxLineLength:util.kt$Util.Companion$"\"permissions\":[{\"id\":\"standart\",\"associated_product\":\"in_app\",\"renew_state\":-1,\"started_timestamp\":1612880300,\"source\":\"playstore\",\"active\":1},{\"id\":\"Test Permission\",\"associated_product\":\"in_app\",\"renew_state\":-1,\"started_timestamp\":1612880300,\"source\":\"appstore\",\"active\":1}],\"user_products\":[{\"id\":\"in_app\",\"store_id\":\"qonversion_inapp_consumable\",\"type\":2}],"</ID>
<ID>MaxLineLength:utils.kt$"ProductId: ${this.productId}; PurchaseTime: ${this.purchaseTime.convertLongToTime()}; PurchaseToken: ${this.purchaseToken}"</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.Qonversion.kt:133</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.Qonversion.kt:87</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.automations.internal.AutomationsEventMapperTest.kt:105</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.automations.internal.AutomationsEventMapperTest.kt:106</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.automations.internal.AutomationsEventMapperTest.kt:107</ID>
Expand All @@ -145,6 +151,7 @@
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.OutagerIntegrationTest.kt:370</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.OutagerIntegrationTest.kt:429</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.OutagerIntegrationTest.kt:90</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QProductCenterManager.kt:341</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QProductCenterManagerTest.kt:147</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QProductCenterManagerTest.kt:148</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.QRemoteConfigManager.kt:225</ID>
Expand All @@ -159,7 +166,9 @@
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.billing.QonversionBillingService.kt:253</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.billing.QonversionBillingService.kt:371</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.billing.utils.kt:22</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.converter.GooglePurchaseConverter.kt:17</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.errors.kt:33</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.storage.LaunchResultCacheWrapperTest.kt:29</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.storage.PurchasesCacheTest.kt:166</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.storage.PurchasesCacheTest.kt:188</ID>
<ID>MaximumLineLength:com.qonversion.android.sdk.internal.storage.PurchasesCacheTest.kt:21</ID>
Expand Down Expand Up @@ -218,7 +227,7 @@
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.billing.QonversionBillingService.kt:5</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.services.QUserInfoServiceTest.kt:11</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.services.QUserInfoServiceTest.kt:5</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.storage.LaunchResultCacheWrapperTest.kt:7</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.storage.LaunchResultCacheWrapperTest.kt:8</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.storage.PurchasesCacheTest.kt:8</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.storage.SharedPreferencesCacheTest.kt:5</ID>
<ID>NoWildcardImports:com.qonversion.android.sdk.internal.storage.util.kt:24</ID>
Expand Down Expand Up @@ -269,7 +278,6 @@
<ID>TooManyFunctions:Cache.kt$Cache</ID>
<ID>TooManyFunctions:DefaultRepository.kt$DefaultRepository : QRepository</ID>
<ID>TooManyFunctions:LaunchResultCacheWrapper.kt$LaunchResultCacheWrapper</ID>
<ID>TooManyFunctions:LegacyBillingClientWrapper.kt$LegacyBillingClientWrapper : BillingClientWrapperBaseIBillingClientWrapper</ID>
<ID>TooManyFunctions:QAutomationsManager.kt$QAutomationsManager</ID>
<ID>TooManyFunctions:QProductCenterManager.kt$QProductCenterManager : PurchasesListenerUserStateProvider</ID>
<ID>TooManyFunctions:QRemoteConfigManager.kt$QRemoteConfigManager</ID>
Expand All @@ -296,6 +304,7 @@
<ID>UnusedPrivateMember:QonversionMappingAdapters.kt$QPermissionsAdapter$@ToJson private fun toJson(permissions: Map&lt;String, QPermission&gt;): List&lt;QPermission&gt;</ID>
<ID>UnusedPrivateMember:QonversionMappingAdapters.kt$QProductRenewStateAdapter$@ToJson private fun toJson(enum: QProductRenewState): Int</ID>
<ID>UnusedPrivateMember:QonversionMappingAdapters.kt$QProductsAdapter$@ToJson private fun toJson(products: Map&lt;String, QProduct&gt;): List&lt;QProduct&gt;</ID>
<ID>UnusedPrivateMember:QonversionMappingAdapters.kt$QPurchaseOptions$@ToJson private fun toJson(permissions: Map&lt;String, QPermission&gt;): List&lt;QPermission&gt;</ID>
<ID>UnusedPrivateMember:QonversionMappingAdapters.kt$QRemoteConfigListAdapter$@ToJson private fun toJson(remoteConfigList: QRemoteConfigList?): List&lt;QRemoteConfig&gt;</ID>
<ID>UnusedPrivateMember:QonversionMappingAdapters.kt$QRemoteConfigurationSourceAssignmentTypeAdapter$@ToJson private fun toJson(enum: QRemoteConfigurationAssignmentType): String</ID>
<ID>UnusedPrivateMember:QonversionMappingAdapters.kt$QRemoteConfigurationSourceTypeAdapter$@ToJson private fun toJson(enum: QRemoteConfigurationSourceType): String</ID>
Expand Down
41 changes: 40 additions & 1 deletion sdk/src/main/java/com/qonversion/android/sdk/Qonversion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import android.app.Activity
import android.util.Log
import com.qonversion.android.sdk.dto.QAttributionProvider
import com.qonversion.android.sdk.dto.QPurchaseModel
import com.qonversion.android.sdk.dto.QPurchaseOptions
import com.qonversion.android.sdk.dto.QPurchaseUpdateModel
import com.qonversion.android.sdk.dto.products.QProduct
import com.qonversion.android.sdk.dto.properties.QUserPropertyKey
import com.qonversion.android.sdk.internal.InternalConfig
import com.qonversion.android.sdk.internal.QonversionInternal
Expand Down Expand Up @@ -82,7 +84,43 @@ interface Qonversion {
* @param callback - callback that will be called when response is received
* @see [Making Purchases](https://documentation.qonversion.io/docs/making-purchases)
*/
fun purchase(context: Activity, purchaseModel: QPurchaseModel, callback: QonversionEntitlementsCallback)
@Deprecated("Use new purchase() method", replaceWith = ReplaceWith("purchase(context: Activity, product: QProduct, options: QPurchaseOptions, callback: QonversionEntitlementsCallback)"))
SpertsyanKM marked this conversation as resolved.
Show resolved Hide resolved
fun purchase(
context: Activity,
purchaseModel: QPurchaseModel,
callback: QonversionEntitlementsCallback
)
SpertsyanKM marked this conversation as resolved.
Show resolved Hide resolved

/**
* Make a purchase and validate it through server-to-server using Qonversion's Backend
* @param context current activity context
* @param product product for purchase
* @param options necessary information for purchase
* @param callback - callback that will be called when response is received
* @see [Making Purchases](https://documentation.qonversion.io/docs/making-purchases)
*/
fun purchase(
context: Activity,
product: QProduct,
options: QPurchaseOptions,
callback: QonversionEntitlementsCallback
)

/**
* Update (upgrade/downgrade) subscription and validate it through server-to-server using Qonversion's Backend
* @param context current activity context
* @param product product for purchase
* @param options necessary information for purchase
* @param callback - callback that will be called when response is received
* @see [Update policy](https://developer.android.com/google/play/billing/subscriptions#replacement-modes)
* @see [Making Purchases](https://documentation.qonversion.io/docs/making-purchases)
*/
fun updatePurchase(
context: Activity,
product: QProduct,
options: QPurchaseOptions,
callback: QonversionEntitlementsCallback
)

/**
* Update (upgrade/downgrade) subscription and validate it through server-to-server using Qonversion's Backend
Expand All @@ -92,6 +130,7 @@ interface Qonversion {
* @see [Update policy](https://developer.android.com/google/play/billing/subscriptions#replacement-modes)
* @see [Making Purchases](https://documentation.qonversion.io/docs/making-purchases)
*/
@Deprecated("Use new updatePurchase() method", replaceWith = ReplaceWith("updatePurchase(context: Activity, product: QProduct, options: QPurchaseOptions, callback: QonversionEntitlementsCallback)"))
SpertsyanKM marked this conversation as resolved.
Show resolved Hide resolved
fun updatePurchase(
context: Activity,
purchaseUpdateModel: QPurchaseUpdateModel,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.qonversion.android.sdk.dto

import com.qonversion.android.sdk.dto.products.QProduct
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
class QPurchaseOptions internal constructor (
SpertsyanKM marked this conversation as resolved.
Show resolved Hide resolved
internal val contextKeys: List<String>? = null,
internal val offerId: String? = null,
internal val applyOffer: Boolean = true,
internal val oldProduct: QProduct? = null,
internal val updatePolicy: QPurchaseUpdatePolicy? = null
) {
class Builder {
private var contextKeys: List<String>? = null
private var offerId: String? = null
private var applyOffer: Boolean = true
private var oldProduct: QProduct? = null
private var updatePolicy: QPurchaseUpdatePolicy? = null

fun setContextKeys(contextKeys: List<String>): QPurchaseOptions.Builder = apply {
this.contextKeys = contextKeys
}

fun setOfferId(offerId: String): QPurchaseOptions.Builder = apply {
this.offerId = offerId
}
SpertsyanKM marked this conversation as resolved.
Show resolved Hide resolved

fun setOldProduct(oldProduct: QProduct): QPurchaseOptions.Builder = apply {
this.oldProduct = oldProduct
}

fun setUpdatePolicy(updatePolicy: QPurchaseUpdatePolicy): QPurchaseOptions.Builder = apply {
this.updatePolicy = updatePolicy
}

fun removeOffer() = apply {
this.applyOffer = false
}

fun build(): QPurchaseOptions {
return QPurchaseOptions(contextKeys, offerId, applyOffer, oldProduct, updatePolicy)
}
}
}
Loading
Loading