mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-07 03:18:40 +00:00
badge service: rename storeReceipt to toStoreReceipt
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+5
-5
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user