Skip to content

Commit

Permalink
Update cancel subscription api request
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandarIlic committed Nov 8, 2024
1 parent fc3fc82 commit b539f53
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.primal.android.premium.api

import net.primal.android.premium.api.model.CancelMembershipRequest
import net.primal.android.premium.api.model.MembershipStatusResponse
import net.primal.android.premium.api.model.NameAvailableResponse
import net.primal.android.premium.api.model.PurchaseMembershipRequest
Expand All @@ -14,5 +15,5 @@ interface PremiumApi {

suspend fun getMembershipProducts()

suspend fun cancelMembership(userId: String, purchaseJson: String)
suspend fun cancelMembership(userId: String, body: CancelMembershipRequest)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import net.primal.android.networking.sockets.errors.WssException
import net.primal.android.nostr.ext.asPubkeyTag
import net.primal.android.nostr.model.NostrEventKind
import net.primal.android.nostr.notary.NostrNotary
import net.primal.android.premium.api.model.CancelMembershipRequest
import net.primal.android.premium.api.model.MembershipProductsRequest
import net.primal.android.premium.api.model.MembershipStatusResponse
import net.primal.android.premium.api.model.NameAvailableRequest
Expand Down Expand Up @@ -103,15 +104,15 @@ class PremiumApiImpl @Inject constructor(
// ]
}

override suspend fun cancelMembership(userId: String, purchaseJson: String) {
override suspend fun cancelMembership(userId: String, body: CancelMembershipRequest) {
primalApiClient.query(
message = PrimalCacheFilter(
primalVerb = PrimalVerb.WALLET_MEMBERSHIP_CANCEL,
optionsJson = NostrJson.encodeToString(
AppSpecificDataRequest(
eventFromUser = nostrNotary.signAppSpecificDataNostrEvent(
userId = userId,
content = purchaseJson,
content = NostrJson.encodeToString(body),
),
),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.primal.android.premium.api.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class CancelMembershipRequest(
@SerialName("android_subscription") val playSubscription: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import javax.inject.Inject
import kotlinx.coroutines.withContext
import net.primal.android.core.coroutines.CoroutineDispatcherProvider
import net.primal.android.premium.api.PremiumApi
import net.primal.android.premium.api.model.CancelMembershipRequest
import net.primal.android.premium.api.model.MembershipStatusResponse
import net.primal.android.premium.api.model.PurchaseMembershipRequest
import net.primal.android.premium.domain.PremiumMembership
Expand Down Expand Up @@ -59,7 +60,10 @@ class PremiumRepository @Inject constructor(

suspend fun cancelSubscription(userId: String, purchaseJson: String) {
withContext(dispatchers.io()) {
premiumApi.cancelMembership(userId = userId, purchaseJson = purchaseJson)
premiumApi.cancelMembership(
userId = userId,
body = CancelMembershipRequest(playSubscription = purchaseJson),
)
fetchMembershipStatus(userId = userId)
}
}
Expand Down

0 comments on commit b539f53

Please sign in to comment.