From 730562a17d82a738f4a609964e04add852311ed5 Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Thu, 1 Oct 2026 16:18:16 +0400 Subject: [PATCH] badge service: rename storeReceipt to toStoreReceipt --- apps/simplex-badge-service/src/BadgeService/Service.hs | 2 +- .../src/BadgeService/StoreReceipts.hs | 6 +++--- tests/BadgeTests.hs | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/simplex-badge-service/src/BadgeService/Service.hs b/apps/simplex-badge-service/src/BadgeService/Service.hs index af815a8645..c424afa7d0 100644 --- a/apps/simplex-badge-service/src/BadgeService/Service.hs +++ b/apps/simplex-badge-service/src/BadgeService/Service.hs @@ -375,7 +375,7 @@ badgeServiceResponse key verifier cc sigKey reqData = case J.fromJSON (J.Object Just k -> redeemCode key cc k masterKey code Nothing -> pure $ errorResponse BSEBadRequest BSCPurchaseBadge {masterKey, payment, upgrade} - | Just receipt_ <- storeReceipt verifier payment -> case (purchaseKey, upgrade) of + | Just receipt_ <- toStoreReceipt verifier payment -> case (purchaseKey, upgrade) of (Just k, Nothing) -> either storeRefusalResponse (purchaseWithReceipt key cc k masterKey) receipt_ -- store upgrades are not built, and ignoring one would credit its months at the discounted price (Just _, Just _) -> pure $ errorResponse BSEBadRequest diff --git a/apps/simplex-badge-service/src/BadgeService/StoreReceipts.hs b/apps/simplex-badge-service/src/BadgeService/StoreReceipts.hs index 7c1d8d4c0e..e0644ad291 100644 --- a/apps/simplex-badge-service/src/BadgeService/StoreReceipts.hs +++ b/apps/simplex-badge-service/src/BadgeService/StoreReceipts.hs @@ -9,7 +9,7 @@ module BadgeService.StoreReceipts StoreVerifier (..), StoreReceipt (..), noStoreVerifier, - storeReceipt, + toStoreReceipt, ) where @@ -66,8 +66,8 @@ noStoreVerifier = StoreVerifier {verifyApple = Nothing, verifyGoogle = Nothing, -- | Nothing for a payment no store made. Exceptions are not logged, since they can quote the receipt -- or, from Google, a URL holding the token. -storeReceipt :: StoreVerifier -> ServicePayment -> Maybe (Either StoreRefusal StoreReceipt) -storeReceipt StoreVerifier {verifyApple, verifyGoogle, verifyTimeout} = \case +toStoreReceipt :: StoreVerifier -> ServicePayment -> Maybe (Either StoreRefusal StoreReceipt) +toStoreReceipt StoreVerifier {verifyApple, verifyGoogle, verifyTimeout} = \case SPApple {jws} -> Just $ case appleTransactionId jws of Nothing -> Left $ SRInvalid "names no transaction" Just ref -> Right $ StoreReceipt (StoreTransactionRef PPApple ref) $ maybe unconfigured (\verify -> offline $ first SRInvalid $ verify jws) verifyApple diff --git a/tests/BadgeTests.hs b/tests/BadgeTests.hs index a253c425bd..e31817e562 100644 --- a/tests/BadgeTests.hs +++ b/tests/BadgeTests.hs @@ -10,7 +10,7 @@ module BadgeTests (badgeTests) where import BadgeService.Service (badgeErrorRetryAfter, shownServiceRequest, survive) -import BadgeService.StoreReceipts (StoreReceipt (..), StoreRefusal (..), StoreVerifier (..), VerifiedStoreTransaction (..), storeReceipt) +import BadgeService.StoreReceipts (StoreReceipt (..), StoreRefusal (..), StoreVerifier (..), VerifiedStoreTransaction (..), toStoreReceipt) import BadgeService.StoreReceipts.Mock (mockStoreVerifier) import Control.Concurrent (forkIO, killThread, threadDelay) import Control.Concurrent.MVar (newEmptyMVar, putMVar, takeMVar) @@ -867,17 +867,17 @@ testShownServiceRequest = do testGoogleProductIdPath :: IO () testGoogleProductIdPath = do - let refused productId = case storeReceipt uncalledVerifier SPGoogle {productId, token = validPlayToken} of + let refused productId = case toStoreReceipt uncalledVerifier SPGoogle {productId, token = validPlayToken} of Just (Left SRInvalid {}) -> True _ -> False mapM_ (\p -> refused p `shouldBe` True) ["badge_legend_01/tokens/other?", "badge_legend_01?x", "badge_legend_01#x", "..", "../badge_legend_01", "Badge_legend_01", ""] - case storeReceipt uncalledVerifier SPGoogle {productId = "badge_supporter_01", token = validPlayToken} of + case toStoreReceipt uncalledVerifier SPGoogle {productId = "badge_supporter_01", token = validPlayToken} of Just (Right StoreReceipt {txRef = StoreTransactionRef {provider}}) -> provider `shouldBe` PPGoogle _ -> expectationFailure "a valid product id and token were refused" testGoogleTokenPath :: IO () testGoogleTokenPath = do - let unsent token = case storeReceipt uncalledVerifier SPGoogle {productId = "badge_supporter_01", token} of + let unsent token = case toStoreReceipt uncalledVerifier SPGoogle {productId = "badge_supporter_01", token} of Just (Left SRUnreachable {}) -> True _ -> False mapM_ (\t -> unsent t `shouldBe` True) ["a/b", "../x", "t?x", "t#x", "t x", ""] @@ -892,7 +892,7 @@ testMockVouchesForClaim :: IO () testMockVouchesForClaim = do let part = safeDecodeUtf8 . B64U.encodeUnpadded . encodeUtf8 signed = T.intercalate "." [part "{\"alg\":\"ES256\"}", part "{\"transactionId\":\"2000000812345671\",\"productId\":\"BADGE_SUPPORTER_01\"}", "c2lnbmVk"] - vouchesForClaim payment = case storeReceipt mockStoreVerifier payment of + vouchesForClaim payment = case toStoreReceipt mockStoreVerifier payment of Just (Right StoreReceipt {txRef = StoreTransactionRef {transactionRef = providerRef}, verifyReceipt}) -> verifyReceipt >>= \case Right VerifiedStoreTransaction {transactionRef, testPurchase} -> (transactionRef, testPurchase) `shouldBe` (providerRef, False)