diff --git a/app/src/main/kotlin/net/primal/android/premium/api/PremiumApi.kt b/app/src/main/kotlin/net/primal/android/premium/api/PremiumApi.kt index 0b648333..34cef8c7 100644 --- a/app/src/main/kotlin/net/primal/android/premium/api/PremiumApi.kt +++ b/app/src/main/kotlin/net/primal/android/premium/api/PremiumApi.kt @@ -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 @@ -14,5 +15,5 @@ interface PremiumApi { suspend fun getMembershipProducts() - suspend fun cancelMembership(userId: String, purchaseJson: String) + suspend fun cancelMembership(userId: String, body: CancelMembershipRequest) } diff --git a/app/src/main/kotlin/net/primal/android/premium/api/PremiumApiImpl.kt b/app/src/main/kotlin/net/primal/android/premium/api/PremiumApiImpl.kt index f3dc337e..6cddd05b 100644 --- a/app/src/main/kotlin/net/primal/android/premium/api/PremiumApiImpl.kt +++ b/app/src/main/kotlin/net/primal/android/premium/api/PremiumApiImpl.kt @@ -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 @@ -103,7 +104,7 @@ 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, @@ -111,7 +112,7 @@ class PremiumApiImpl @Inject constructor( AppSpecificDataRequest( eventFromUser = nostrNotary.signAppSpecificDataNostrEvent( userId = userId, - content = purchaseJson, + content = NostrJson.encodeToString(body), ), ), ), diff --git a/app/src/main/kotlin/net/primal/android/premium/api/model/CancelMembershipRequest.kt b/app/src/main/kotlin/net/primal/android/premium/api/model/CancelMembershipRequest.kt new file mode 100644 index 00000000..f190d2fd --- /dev/null +++ b/app/src/main/kotlin/net/primal/android/premium/api/model/CancelMembershipRequest.kt @@ -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, +) diff --git a/app/src/main/kotlin/net/primal/android/premium/repository/PremiumRepository.kt b/app/src/main/kotlin/net/primal/android/premium/repository/PremiumRepository.kt index 13b11e41..d57fe5c8 100644 --- a/app/src/main/kotlin/net/primal/android/premium/repository/PremiumRepository.kt +++ b/app/src/main/kotlin/net/primal/android/premium/repository/PremiumRepository.kt @@ -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 @@ -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) } }