mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-07 08:07:33 +00:00
core, badge-service: name Apple claims by reference
Rename appleTransactionId to appleTransactionRef, matching googlePurchaseRef and StoreTransactionRef. No behaviour change: the next change makes it return a subscription's original transaction id, which the old name would misstate. Run: 001-badge-subscriptions, slice 1
This commit is contained in:
1 parent
263ac949f3
commit
dcbf3ee262
5 files changed
+11
-11
No files matched your search
@@ -18,7 +18,7 @@ import Data.Char (isAlphaNum, isAscii, isAsciiLower, isAsciiUpper, isControl, is
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import Simplex.Chat.PaymentService (ServicePayment (..), appleTransactionId, googlePurchaseRef)
|
||||
import Simplex.Chat.PaymentService (ServicePayment (..), appleTransactionRef, googlePurchaseRef)
|
||||
import Simplex.Chat.PaymentService.Types (CurrencyAmount, PaymentProvider (..), StoreTransactionRef (..))
|
||||
import Simplex.Messaging.Util (catchOwn', tshow)
|
||||
import System.Timeout (timeout)
|
||||
@@ -73,7 +73,7 @@ noStoreVerifier = StoreVerifier {verifyApple = Nothing, verifyGoogle = Nothing,
|
||||
-- or, from Google, a URL holding the token.
|
||||
toStoreReceipt :: StoreVerifier -> ServicePayment -> Maybe (Either StoreRefusal StoreReceipt)
|
||||
toStoreReceipt StoreVerifier {verifyApple, verifyGoogle, acknowledgeGoogle, verifyTimeout} = \case
|
||||
SPApple {jws} -> Just $ case appleTransactionId jws of
|
||||
SPApple {jws} -> Just $ case appleTransactionRef jws of
|
||||
Nothing -> Left $ SRInvalid "names no transaction"
|
||||
Just ref -> Right $ StoreReceipt (StoreTransactionRef PPApple ref) (maybe unconfigured (\verify -> offline $ verify jws) verifyApple) Nothing
|
||||
SPGoogle {productId, token}
|
||||
|
||||
@@ -10,7 +10,7 @@ import qualified Data.ByteString.Base64.URL as B64U
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import Data.Text.Encoding (encodeUtf8)
|
||||
import Simplex.Chat.PaymentService (appleTransactionId, googlePurchaseRef)
|
||||
import Simplex.Chat.PaymentService (appleTransactionRef, googlePurchaseRef)
|
||||
import Simplex.Messaging.Util (eitherToMaybe)
|
||||
|
||||
-- | Vouches for any well-formed receipt without verifying anything. Each transaction is named by
|
||||
@@ -27,7 +27,7 @@ mockApple signed = case T.splitOn "." signed of
|
||||
productId <- case JM.lookup "productId" o of
|
||||
Just (J.String p) -> Right p
|
||||
_ -> Left $ SRInvalid "no productId"
|
||||
transactionRef <- maybe (Left $ SRInvalid "no transactionId") Right $ appleTransactionId signed
|
||||
transactionRef <- maybe (Left $ SRInvalid "no transactionId") Right $ appleTransactionRef signed
|
||||
Right $ vouched transactionRef productId
|
||||
_ -> Left $ SRInvalid "not three dot-separated parts"
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ import Simplex.Chat.Messages.CIContent
|
||||
import Simplex.Chat.Messages.CIContent.Events
|
||||
import Simplex.Chat.Operators
|
||||
import Simplex.Chat.Options
|
||||
import Simplex.Chat.PaymentService (ServicePayment (..), appleTransactionId, googlePurchaseRef)
|
||||
import Simplex.Chat.PaymentService (ServicePayment (..), appleTransactionRef, googlePurchaseRef)
|
||||
import Simplex.Chat.PaymentService.Types (PaymentProvider (..), StoreTransactionRef (..))
|
||||
import Simplex.Chat.ProfileGenerator (generateRandomProfile)
|
||||
import Simplex.Chat.Protocol
|
||||
@@ -5314,7 +5314,7 @@ storeReceiptRefused = \case
|
||||
-- | The same reference the service claims a transaction by, read without verifying anything.
|
||||
storeTransactionRef :: ServicePayment -> Maybe StoreTransactionRef
|
||||
storeTransactionRef = \case
|
||||
SPApple {jws} -> StoreTransactionRef PPApple <$> appleTransactionId jws
|
||||
SPApple {jws} -> StoreTransactionRef PPApple <$> appleTransactionRef jws
|
||||
SPGoogle {token} -> Just $ StoreTransactionRef PPGoogle $ googlePurchaseRef token
|
||||
SPInvoice {} -> Nothing
|
||||
SPReceipt {} -> Nothing
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
module Simplex.Chat.PaymentService
|
||||
( ServiceInvoice (..),
|
||||
ServicePayment (..),
|
||||
appleTransactionId,
|
||||
appleTransactionRef,
|
||||
googlePurchaseRef,
|
||||
module Simplex.Chat.PaymentService.Types,
|
||||
) where
|
||||
@@ -44,8 +44,8 @@ data ServicePayment
|
||||
deriving (Show)
|
||||
|
||||
-- | Read without verifying the signature: it names the transaction, and proves nothing about it.
|
||||
appleTransactionId :: Text -> Maybe Text
|
||||
appleTransactionId signed = case T.splitOn "." signed of
|
||||
appleTransactionRef :: Text -> Maybe Text
|
||||
appleTransactionRef signed = case T.splitOn "." signed of
|
||||
[_, payload, _] -> do
|
||||
J.Object o <- J.decodeStrict' =<< eitherToMaybe (B64U.decodeUnpadded $ encodeUtf8 payload)
|
||||
J.String txId <- JM.lookup "transactionId" o
|
||||
|
||||
@@ -31,7 +31,7 @@ import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import Data.Text.Encoding (decodeUtf8)
|
||||
import Data.X509
|
||||
import Simplex.Chat.PaymentService (ServicePayment (..), appleTransactionId, googlePurchaseRef)
|
||||
import Simplex.Chat.PaymentService (ServicePayment (..), appleTransactionRef, googlePurchaseRef)
|
||||
import Simplex.Chat.PaymentService.Types (CurrencyAmount (..))
|
||||
import System.Directory (createDirectoryIfMissing)
|
||||
import System.FilePath (takeDirectory, (</>))
|
||||
@@ -220,7 +220,7 @@ testAppleVerdict = do
|
||||
jws <- signedBy chain $ transactionPayload [] []
|
||||
appleVerdict (rootCert chain) jws
|
||||
`shouldReturn` Right VerifiedStoreTransaction {transactionRef = "2000000900000001", productId = "BADGE_SUPPORTER_01", quantity = 1, testPurchase = False, paid = Just (CurrencyAmount 700, "USD")}
|
||||
appleTransactionId jws `shouldBe` Just "2000000900000001"
|
||||
appleTransactionRef jws `shouldBe` Just "2000000900000001"
|
||||
|
||||
testAppleRootNotTrusted :: IO ()
|
||||
testAppleRootNotTrusted = do
|
||||
|
||||
Reference in new issue
Block a user