mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-09-05 06:05:32 +00:00
core: refactor badge types (#7387)
Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com>
This commit is contained in:
co-authored by
Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com>
parent
78332d0c73
commit
1c7bc1aed4
@@ -8,14 +8,12 @@ module Simplex.Chat.Badges.Types
|
||||
BadgePlan (..),
|
||||
BadgeItemStatus (..),
|
||||
OfferDiscount (..),
|
||||
BadgePaymentStatus (..),
|
||||
BadgePurchaseStatus (..),
|
||||
LedgerEntryType (..),
|
||||
LedgerCreditType (..),
|
||||
LedgerDebitType (..),
|
||||
BadgeAlertKind (..),
|
||||
BadgePurchase (..),
|
||||
BadgePayment (..),
|
||||
BadgeLedgerEntry (..),
|
||||
BadgeCharge (..),
|
||||
BadgeIssuance (..),
|
||||
@@ -30,7 +28,7 @@ import Data.Text (Text)
|
||||
import Data.Time.Clock (UTCTime)
|
||||
import Data.Word (Word8)
|
||||
import Simplex.Chat.Badges hiding (BadgePurchase (..))
|
||||
import Simplex.Chat.PaymentService.Types (InvoiceId, PaymentProvider)
|
||||
import Simplex.Chat.PaymentService.Types (InvoiceId, StoredPayment)
|
||||
import Simplex.Messaging.Agent.Protocol (UserId)
|
||||
import qualified Simplex.Messaging.Crypto as C
|
||||
|
||||
@@ -56,10 +54,6 @@ data OfferDiscount
|
||||
| ODDiscount {discount :: Word8} -- percent
|
||||
deriving (Eq, Show)
|
||||
|
||||
-- unconfirmed draft
|
||||
data BadgePaymentStatus = BPSNew | BPSInvoiced | BPSPending | BPSSettled | BPSFailed | BPSExpired
|
||||
deriving (Eq, Show)
|
||||
|
||||
-- unconfirmed draft
|
||||
data BadgePurchaseStatus = PSAcquiring | PSIssued | PSSuperseded | PSFailed
|
||||
deriving (Eq, Show)
|
||||
@@ -112,36 +106,6 @@ data BadgePurchase = BadgePurchase
|
||||
updatedAt :: UTCTime
|
||||
}
|
||||
|
||||
-- to review
|
||||
data BadgePayment = BadgePayment
|
||||
{ paymentId :: Int64,
|
||||
userId :: UserId,
|
||||
purchaseKey :: C.PublicKeyEd25519,
|
||||
badgeType :: BadgeType,
|
||||
priceId :: Maybe BadgePriceId,
|
||||
offerId :: Maybe BadgeOfferId,
|
||||
invoiceUuid :: Maybe InvoiceId,
|
||||
months :: Maybe Int,
|
||||
amount :: Maybe Int64,
|
||||
currency :: Maybe Text,
|
||||
provider :: PaymentProvider,
|
||||
providerRef :: Maybe Text,
|
||||
invoiceUrl :: Maybe Text,
|
||||
invoiceAddress :: Maybe Text,
|
||||
invoiceCryptoAmount :: Maybe Text,
|
||||
invoiceExpiresAt :: Maybe UTCTime,
|
||||
evidence :: Maybe ByteString,
|
||||
receiptCode :: Maybe Text,
|
||||
status :: BadgePaymentStatus,
|
||||
exception :: Maybe Text,
|
||||
renewsAt :: Maybe UTCTime,
|
||||
graceUntil :: Maybe UTCTime,
|
||||
cancelled :: Bool,
|
||||
createdAt :: UTCTime,
|
||||
updatedAt :: UTCTime
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
-- confirmed
|
||||
data BadgeLedgerEntry = BadgeLedgerEntry
|
||||
{ entryId :: Int64,
|
||||
@@ -197,7 +161,7 @@ data BadgeAlert = BadgeAlert
|
||||
data UserBadgeState = UserBadgeState
|
||||
{ badges :: [BadgePurchase],
|
||||
shownBadgeId :: Maybe Int64,
|
||||
payments :: [BadgePayment],
|
||||
payments :: [StoredPayment],
|
||||
monthsLeft :: Int,
|
||||
paidThrough :: Maybe UTCTime,
|
||||
renewsAt :: Maybe UTCTime,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
module Simplex.Chat.PaymentService.Types
|
||||
( CurrencyAmount (..),
|
||||
InvoiceId (..),
|
||||
PaymentId (..),
|
||||
PaymentProvider (..),
|
||||
CardProvider (..),
|
||||
CryptoCurrency (..),
|
||||
@@ -12,8 +13,13 @@ module Simplex.Chat.PaymentService.Types
|
||||
ServicePaymentDestination (..),
|
||||
InvoiceStatus (..),
|
||||
StoredInvoice (..),
|
||||
StoredPayment (..),
|
||||
PaymentFunding (..),
|
||||
PaymentTerm (..),
|
||||
PaymentStatus (..),
|
||||
) where
|
||||
|
||||
import Data.ByteString.Char8 (ByteString)
|
||||
import Data.Text (Text)
|
||||
import Data.Time.Clock (UTCTime)
|
||||
import Data.Word (Word32)
|
||||
@@ -26,6 +32,10 @@ newtype CurrencyAmount = CurrencyAmount Word32
|
||||
newtype InvoiceId = InvoiceId Text
|
||||
deriving newtype (Eq, Show)
|
||||
|
||||
-- confirmed
|
||||
newtype PaymentId = PaymentId Text
|
||||
deriving newtype (Eq, Show)
|
||||
|
||||
-- confirmed
|
||||
data PaymentProvider = PPApple | PPGoogle | PPStripe | PPCrypto | PPCode | PPReceipt
|
||||
deriving (Eq, Show)
|
||||
@@ -72,3 +82,53 @@ data StoredInvoice = StoredInvoice
|
||||
updatedAt :: UTCTime
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
-- to review
|
||||
data StoredPayment = StoredPayment
|
||||
{ paymentId :: PaymentId,
|
||||
funding :: PaymentFunding,
|
||||
term :: PaymentTerm,
|
||||
status :: PaymentStatus,
|
||||
createdAt :: UTCTime,
|
||||
updatedAt :: UTCTime
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
-- to review
|
||||
data PaymentFunding
|
||||
= PFInvoice
|
||||
{ invoiceId :: InvoiceId,
|
||||
providerRef :: Text,
|
||||
amount :: CurrencyAmount,
|
||||
currency :: Text,
|
||||
receiptCode :: Maybe Text -- client; the service holds its hash
|
||||
}
|
||||
| PFApple
|
||||
{ providerRef :: Text,
|
||||
amount :: CurrencyAmount,
|
||||
currency :: Text,
|
||||
evidence :: Maybe ByteString -- client only
|
||||
}
|
||||
| PFGoogle
|
||||
{ providerRef :: Text,
|
||||
amount :: CurrencyAmount,
|
||||
currency :: Text,
|
||||
evidence :: Maybe ByteString -- client only
|
||||
}
|
||||
| PFCode
|
||||
| PFReceipt
|
||||
deriving (Show)
|
||||
|
||||
-- to review
|
||||
data PaymentTerm
|
||||
= PTOneOff
|
||||
| PTSubscription
|
||||
{ renewsAt :: UTCTime,
|
||||
graceUntil :: Maybe UTCTime,
|
||||
cancelled :: Bool
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
-- to review
|
||||
data PaymentStatus = PSPending | PSSettled | PSFailed {exception :: Text}
|
||||
deriving (Show)
|
||||
|
||||
Reference in New Issue
Block a user