Skip to content

Commit

Permalink
Use new web redemption endpoint (#1903)
Browse files Browse the repository at this point in the history
### Description
Change to use new web redemption endpoint that passes the user id as
part of the body
  • Loading branch information
tonidero authored Nov 7, 2024
1 parent 36d80c8 commit 75dfbe7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -667,9 +667,9 @@ internal class Backend(
onSuccessHandler: (CustomerInfo) -> Unit,
onErrorHandler: (PurchasesError) -> Unit,
) {
val endpoint = Endpoint.PostRedeemWebPurchase(appUserID)
val endpoint = Endpoint.PostRedeemWebPurchase
val path = endpoint.getPath()
val body = mapOf("redemption_token" to redemptionToken)
val body = mapOf("redemption_token" to redemptionToken, APP_USER_ID to appUserID)
val call = object : Dispatcher.AsyncCall() {
override fun call(): HTTPResult {
return httpClient.performRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ internal sealed class Endpoint(val pathTemplate: String, val name: String) {
) {
override fun getPath() = pathTemplate.format(Uri.encode(userId))
}
data class PostRedeemWebPurchase(val userId: String) : Endpoint(
"/subscribers/%s/redeem_web_purchase",
object PostRedeemWebPurchase : Endpoint(
"/subscribers/redeem_purchase",
"post_redeem_web_purchase",
) {
override fun getPath() = pathTemplate.format(Uri.encode(userId))
override fun getPath() = pathTemplate
}

val supportsSignatureVerification: Boolean
Expand All @@ -54,7 +54,7 @@ internal sealed class Endpoint(val pathTemplate: String, val name: String) {
PostReceipt,
is GetOfferings,
GetProductEntitlementMapping,
is PostRedeemWebPurchase,
PostRedeemWebPurchase,
->
true
is GetAmazonReceipt,
Expand All @@ -71,7 +71,7 @@ internal sealed class Endpoint(val pathTemplate: String, val name: String) {
is GetCustomerInfo,
LogIn,
PostReceipt,
is PostRedeemWebPurchase,
PostRedeemWebPurchase,
->
true
is GetAmazonReceipt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ import com.revenuecat.purchases.common.createCustomerInfo
import com.revenuecat.purchases.common.networking.Endpoint
import com.revenuecat.purchases.common.networking.HTTPResult
import com.revenuecat.purchases.common.networking.RCHTTPStatusCodes
import com.revenuecat.purchases.customercenter.CustomerCenterConfigData
import com.revenuecat.purchases.customercenter.CustomerCenterConfigData.HelpPath
import com.revenuecat.purchases.customercenter.CustomerCenterConfigData.Screen
import com.revenuecat.purchases.customercenter.CustomerCenterConfigData.Screen.ScreenType
import com.revenuecat.purchases.customercenter.RCColor
import com.revenuecat.purchases.utils.Responses
import io.mockk.every
import io.mockk.mockk
Expand All @@ -29,15 +24,13 @@ import org.junit.Assert.fail
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import java.io.File
import java.net.URL
import java.util.concurrent.CountDownLatch
import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit
import kotlin.time.Duration.Companion.seconds

@OptIn(ExperimentalPreviewRevenueCatPurchasesAPI::class)
@RunWith(AndroidJUnit4::class)
class BackendRedeemWebPurchaseTest {

Expand Down Expand Up @@ -136,8 +129,8 @@ class BackendRedeemWebPurchaseTest {
verify(exactly = 1) {
httpClient.performRequest(
mockBaseURL,
Endpoint.PostRedeemWebPurchase("test-user-id"),
body = mapOf("redemption_token" to "test-redemption-token"),
Endpoint.PostRedeemWebPurchase,
body = mapOf("redemption_token" to "test-redemption-token", "app_user_id" to "test-user-id"),
postFieldsToSign = null,
any()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class EndpointTest {
Endpoint.PostAttributes("test-user-id"),
Endpoint.PostDiagnostics,
Endpoint.PostPaywallEvents,
Endpoint.PostRedeemWebPurchase("test-user-id"),
Endpoint.PostRedeemWebPurchase,
)

@Test
Expand Down Expand Up @@ -88,8 +88,8 @@ class EndpointTest {

@Test
fun `PostRedeemWebPurchase has correct path`() {
val endpoint = Endpoint.PostRedeemWebPurchase("test user-id")
val expectedPath = "/subscribers/test%20user-id/redeem_web_purchase"
val endpoint = Endpoint.PostRedeemWebPurchase
val expectedPath = "/subscribers/redeem_purchase"
assertThat(endpoint.getPath()).isEqualTo(expectedPath)
}

Expand All @@ -101,7 +101,7 @@ class EndpointTest {
Endpoint.PostReceipt,
Endpoint.GetOfferings("test-user-id"),
Endpoint.GetProductEntitlementMapping,
Endpoint.PostRedeemWebPurchase("test-user-id"),
Endpoint.PostRedeemWebPurchase,
)
for (endpoint in expectedSupportsValidationEndpoints) {
assertThat(endpoint.supportsSignatureVerification)
Expand Down Expand Up @@ -142,7 +142,7 @@ class EndpointTest {
Endpoint.GetCustomerInfo("test-user-id"),
Endpoint.LogIn,
Endpoint.PostReceipt,
Endpoint.PostRedeemWebPurchase("test-user-id"),
Endpoint.PostRedeemWebPurchase,
)
for (endpoint in expectedEndpoints) {
assertThat(endpoint.needsNonceToPerformSigning)
Expand Down

0 comments on commit 75dfbe7

Please sign in to comment.