From 6ec748514c1a70439f12de5da80aa66472099479 Mon Sep 17 00:00:00 2001 From: Andy Boedo Date: Thu, 20 Jul 2023 13:44:50 -0300 Subject: [PATCH] CustomEntitlementsComputation: Prevent posting subscriber attributes in post receipt (#1151) Prevents sending subscriber attributes when posting receipts in custom entitlements computation mode. --- .../revenuecat/purchases/common/Backend.kt | 2 +- .../purchases/common/BackendTest.kt | 1 + .../SubscriberAttributesBackendTests.kt | 27 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/purchases/src/main/kotlin/com/revenuecat/purchases/common/Backend.kt b/purchases/src/main/kotlin/com/revenuecat/purchases/common/Backend.kt index 7122a0cb7..3b25afd5e 100644 --- a/purchases/src/main/kotlin/com/revenuecat/purchases/common/Backend.kt +++ b/purchases/src/main/kotlin/com/revenuecat/purchases/common/Backend.kt @@ -198,7 +198,7 @@ internal class Backend( "observer_mode" to observerMode, "price" to receiptInfo.price, "currency" to receiptInfo.currency, - "attributes" to subscriberAttributes.takeUnless { it.isEmpty() }, + "attributes" to subscriberAttributes.takeUnless { it.isEmpty() || appConfig.customEntitlementComputation }, "normal_duration" to receiptInfo.duration, "store_user_id" to storeAppUserID, "pricing_phases" to receiptInfo.pricingPhases?.map { it.toMap() }, diff --git a/purchases/src/test/java/com/revenuecat/purchases/common/BackendTest.kt b/purchases/src/test/java/com/revenuecat/purchases/common/BackendTest.kt index 16882c1cb..2a407e225 100644 --- a/purchases/src/test/java/com/revenuecat/purchases/common/BackendTest.kt +++ b/purchases/src/test/java/com/revenuecat/purchases/common/BackendTest.kt @@ -85,6 +85,7 @@ class BackendTest { private val mockAppConfig: AppConfig = mockk().apply { every { baseURL } returns mockBaseURL every { diagnosticsURL } returns mockDiagnosticsBaseURL + every { customEntitlementComputation } returns false } private val dispatcher = SyncDispatcher() private val backendHelper = BackendHelper(API_KEY, dispatcher, mockAppConfig, mockClient) diff --git a/purchases/src/test/java/com/revenuecat/purchases/subscriberattributes/SubscriberAttributesBackendTests.kt b/purchases/src/test/java/com/revenuecat/purchases/subscriberattributes/SubscriberAttributesBackendTests.kt index cee45a7c2..97678bb93 100644 --- a/purchases/src/test/java/com/revenuecat/purchases/subscriberattributes/SubscriberAttributesBackendTests.kt +++ b/purchases/src/test/java/com/revenuecat/purchases/subscriberattributes/SubscriberAttributesBackendTests.kt @@ -42,6 +42,7 @@ class SubscriberAttributesPosterTests { private val mockBaseURL = URL("http://mock-api-test.revenuecat.com/") private val mockAppConfig = mockk().apply { every { baseURL } returns mockBaseURL + every { customEntitlementComputation } returns false } private val appUserID = "jerry" private val dispatcher = SyncDispatcher() @@ -316,6 +317,32 @@ class SubscriberAttributesPosterTests { assertThat(actualPostReceiptBody["attributes"]).isNotNull } + @Test + fun `posting receipt with attributes skips them in custom entitlements computation mode`() { + every { mockAppConfig.customEntitlementComputation } returns true + mockPostReceiptResponse() + + val productInfo = ReceiptInfo( + productIDs = listOf(productID) + ) + backend.postReceiptData( + purchaseToken = fetchToken, + appUserID = appUserID, + isRestore = false, + observerMode = false, + subscriberAttributes = mapOfSubscriberAttributes, + receiptInfo = productInfo, + storeAppUserID = null, + onSuccess = expectedOnSuccessPostReceipt, + onError = unexpectedOnErrorPostReceipt + ) + + assertThat(receivedCustomerInfo).isNotNull + val actualPostReceiptBody = actualPostReceiptBodySlot.captured + assertThat(actualPostReceiptBody).isNotNull + assertThat(actualPostReceiptBody.containsKey("attributes")).isFalse + } + @Test fun `posting receipt without attributes skips them`() { mockPostReceiptResponse()