mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-05 12:47:43 +00:00
core: move SubscriptionState to Badges.Types (structural)
BadgeState, which lives in Badges.Types, is about to carry a subscription's state, and Badges.Service imports Badges.Types. Service re-exports it, as it does BadgeServiceErrorCode. No behaviour change. Run: 003-badge-subscriptions-ui, slice 1
This commit is contained in:
1 parent
8e1623b8b0
commit
a488fbc4d2
2 files changed
+31
-31
No files matched your search
@@ -43,7 +43,6 @@ import Simplex.Chat.Badges
|
||||
import Simplex.Chat.Badges.Types
|
||||
import Simplex.Chat.PaymentService
|
||||
import qualified Simplex.Messaging.Crypto as C
|
||||
import Simplex.Messaging.Encoding.String (TextEncoding (..), textParseJSON, textToEncoding, textToJSON)
|
||||
import Simplex.Messaging.Parsers (defaultJSON, dropPrefix, taggedObjectJSON)
|
||||
import Simplex.Messaging.Version (VersionRange, VersionScope, mkVersionRange)
|
||||
import Simplex.Messaging.Version.Internal (Version (..))
|
||||
@@ -132,15 +131,6 @@ data BadgeServiceResponse
|
||||
retryAfter :: Maybe Word32
|
||||
}
|
||||
|
||||
-- | The store's answer as the service last read it. A client reads a state it does not know as not ended.
|
||||
data SubscriptionState
|
||||
= SSRenewing
|
||||
| SSCancelled -- auto-renew is off, and the paid period still runs
|
||||
| SSBillingRetry -- a charge failed and the store is retrying it: grace, retry or hold
|
||||
| SSEnded -- no charge will come: expired, revoked or refunded
|
||||
| SSUnknown Text -- forwards-compatible: service is deployed ahead of clients
|
||||
deriving (Eq, Show)
|
||||
|
||||
data BadgeCatalog = BadgeCatalog
|
||||
{ prices :: [BadgePrice],
|
||||
offers :: [BadgeOffer]
|
||||
@@ -248,27 +238,6 @@ instance ToJSON StatementDebitType where
|
||||
SDUnknown _ j -> JE.value $ J.Object j
|
||||
v -> $(JQ.mkToEncoding (taggedObjectJSON $ dropPrefix "SD") ''StatementDebitType) v
|
||||
|
||||
instance TextEncoding SubscriptionState where
|
||||
textEncode = \case
|
||||
SSRenewing -> "renewing"
|
||||
SSCancelled -> "cancelled"
|
||||
SSBillingRetry -> "billingRetry"
|
||||
SSEnded -> "ended"
|
||||
SSUnknown t -> t
|
||||
textDecode s = Just $ case s of
|
||||
"renewing" -> SSRenewing
|
||||
"cancelled" -> SSCancelled
|
||||
"billingRetry" -> SSBillingRetry
|
||||
"ended" -> SSEnded
|
||||
t -> SSUnknown t
|
||||
|
||||
instance ToJSON SubscriptionState where
|
||||
toJSON = textToJSON
|
||||
toEncoding = textToEncoding
|
||||
|
||||
instance FromJSON SubscriptionState where
|
||||
parseJSON = textParseJSON "SubscriptionState"
|
||||
|
||||
$(JQ.deriveJSON (taggedObjectJSON $ dropPrefix "SE") ''StatementEntryType)
|
||||
|
||||
$(JQ.deriveJSON defaultJSON ''StatementEntry)
|
||||
|
||||
@@ -20,6 +20,7 @@ module Simplex.Chat.Badges.Types
|
||||
LedgerDebitType (..),
|
||||
BadgeAlertKind (..),
|
||||
BadgeServiceErrorCode (..),
|
||||
SubscriptionState (..),
|
||||
BadgeIssueFailure (..),
|
||||
BadgeIssueError (..),
|
||||
BadgeFunding (..),
|
||||
@@ -249,6 +250,15 @@ data BadgeServiceErrorCode
|
||||
| BSEUnknown Text -- forwards-compatible: service is deployed ahead of clients
|
||||
deriving (Eq, Show)
|
||||
|
||||
-- | The store's answer as the service last read it. A client reads a state it does not know as not ended.
|
||||
data SubscriptionState
|
||||
= SSRenewing
|
||||
| SSCancelled -- auto-renew is off, and the paid period still runs
|
||||
| SSBillingRetry -- a charge failed and the store is retrying it: grace, retry or hold
|
||||
| SSEnded -- no charge will come: expired, revoked or refunded
|
||||
| SSUnknown Text -- forwards-compatible: service is deployed ahead of clients
|
||||
deriving (Eq, Show)
|
||||
|
||||
-- | Why a renewal request ended without a credential stored. retryable is the service's own view of
|
||||
-- transience: it gave retryAfter, which holds for codes this version does not know.
|
||||
data BadgeIssueFailure
|
||||
@@ -378,6 +388,27 @@ instance ToJSON BadgeServiceErrorCode where
|
||||
instance FromJSON BadgeServiceErrorCode where
|
||||
parseJSON = textParseJSON "BadgeServiceErrorCode"
|
||||
|
||||
instance TextEncoding SubscriptionState where
|
||||
textEncode = \case
|
||||
SSRenewing -> "renewing"
|
||||
SSCancelled -> "cancelled"
|
||||
SSBillingRetry -> "billingRetry"
|
||||
SSEnded -> "ended"
|
||||
SSUnknown t -> t
|
||||
textDecode s = Just $ case s of
|
||||
"renewing" -> SSRenewing
|
||||
"cancelled" -> SSCancelled
|
||||
"billingRetry" -> SSBillingRetry
|
||||
"ended" -> SSEnded
|
||||
t -> SSUnknown t
|
||||
|
||||
instance ToJSON SubscriptionState where
|
||||
toJSON = textToJSON
|
||||
toEncoding = textToEncoding
|
||||
|
||||
instance FromJSON SubscriptionState where
|
||||
parseJSON = textParseJSON "SubscriptionState"
|
||||
|
||||
instance StrEncoding BadgeIssueFailure where
|
||||
strEncode = \case
|
||||
BIFServiceError {code, retryable} -> "service_error " <> (if retryable then "retry " else "final ") <> encodeUtf8 (textEncode code)
|
||||
|
||||
Reference in new issue
Block a user