diff --git a/apps/simplex-badge-service/src/BadgeService/StoreReceipts.hs b/apps/simplex-badge-service/src/BadgeService/StoreReceipts.hs index 952a4d0152..41adbdf056 100644 --- a/apps/simplex-badge-service/src/BadgeService/StoreReceipts.hs +++ b/apps/simplex-badge-service/src/BadgeService/StoreReceipts.hs @@ -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} diff --git a/apps/simplex-badge-service/src/BadgeService/StoreReceipts/Mock.hs b/apps/simplex-badge-service/src/BadgeService/StoreReceipts/Mock.hs index 5de05fbf99..35da09d5d6 100644 --- a/apps/simplex-badge-service/src/BadgeService/StoreReceipts/Mock.hs +++ b/apps/simplex-badge-service/src/BadgeService/StoreReceipts/Mock.hs @@ -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" diff --git a/src/Simplex/Chat/Library/Commands.hs b/src/Simplex/Chat/Library/Commands.hs index f5c48c7e2c..725869f885 100644 --- a/src/Simplex/Chat/Library/Commands.hs +++ b/src/Simplex/Chat/Library/Commands.hs @@ -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 diff --git a/src/Simplex/Chat/PaymentService.hs b/src/Simplex/Chat/PaymentService.hs index 91b7a9fde1..a0d6b425fe 100644 --- a/src/Simplex/Chat/PaymentService.hs +++ b/src/Simplex/Chat/PaymentService.hs @@ -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 diff --git a/tests/Bots/BadgeService/StoreVerifierTests.hs b/tests/Bots/BadgeService/StoreVerifierTests.hs index be4e6f2e26..dbb984724e 100644 --- a/tests/Bots/BadgeService/StoreVerifierTests.hs +++ b/tests/Bots/BadgeService/StoreVerifierTests.hs @@ -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