git.iko.soy/typeable/connexpay
on master help sign in
Fix token update code.
commit9ff4728d4007bd79ba79351c46d15f44802916f0 authorNick <nick@typeable.io> dateWed 5 Jun 2024, 14:45 (2 years ago) parent762da31
3 files changed+10−6
connexpay/src/Tool.hs+7−4 connexpay/src/Web/Connexpay/Init.hs+2−1 stack.yaml+1−1
connexpay/src/Tool.hs+7−4
@@ -2,6 +2,7 @@
22{-# LANGUAGE OverloadedStrings #-}
33module Main where
44
5+import Control.Concurrent (yield)
56import Control.Monad
67import Control.Monad.IO.Class
78import Data.Aeson
@@ -34,6 +35,7 @@ instance FromJSON Config
3435data Command = AuthSale CreditCard Centi
3536 | VoidSale SaleGuid
3637 | CaptureSale SaleGuid
38+ | TestAuth
3739
3840data CmdLine = CmdLine { configPath :: FilePath
3941 , operation :: Command
@@ -45,6 +47,7 @@ cmdParser = CmdLine <$> strOption (short 'c' <> metavar "FILE" <> help "Configur
4547 where operation = command "auth" (info (AuthSale <$> cc <*> amt) (progDesc "Authorise payment"))
4648 <> command "void" (info (VoidSale <$> guid) (progDesc "Void payment"))
4749 <> command "capture" (info (CaptureSale <$> guid) (progDesc "Void payment"))
50+ <> command "test-auth" (info (pure TestAuth) (progDesc "Test token authorisation"))
4851 amt = argument auto (metavar "Payment amount")
4952 cc = CreditCard <$> argument str mempty
5053 <*> fmap pure (argument str mempty)
@@ -55,8 +58,6 @@ cmdParser = CmdLine <$> strOption (short 'c' <> metavar "FILE" <> help "Configur
5558 pure (read (take 2 s), read (drop 2 s))
5659 guid = argument auto (metavar "Payment UUID")
5760
58−
59−
6061writeLog :: Text -> IO ()
6162writeLog msg = Text.putStrLn ("Connexpay log: " <> msg)
6263
@@ -75,8 +76,10 @@ main = do cmdLine <- execParser (info cmdParser mempty)
7576 Right cpi -> print =<< runConnexpay cpi (doThing cmdLine.operation)
7677
7778doThing :: Command -> ConnexpayM ()
78−doThing (AuthSale cc amt) = liftIO . print =<< authorisePayment cc usd (Just pnr) Nothing
79+doThing (AuthSale cc amt) = liftIO . print =<< authorisePayment cc usd pnr vendor
7980 where usd = Money amt
80− pnr = "PNRPNR"
81+ pnr = Just "PNRPNR"
82+ vendor = Just "Typeable"
8183doThing (VoidSale guid) = liftIO . print =<< voidPayment guid Nothing
8284doThing (CaptureSale guid) = liftIO . print =<< capturePayment guid
85+doThing TestAuth = liftIO (forever yield)
connexpay/src/Web/Connexpay/Init.hs+2−1
@@ -8,6 +8,7 @@ import Web.Connexpay.Utils
88
99import Control.Concurrent
1010import Control.Concurrent.Async
11+import Control.Monad (void)
1112import Control.Monad.Except (catchError)
1213import Control.Monad.IO.Class
1314import Control.Monad.Reader (asks)
@@ -49,7 +50,7 @@ updateToken w = liftIO (threadDelay w') >> upd
4950 upd = do (tok, ts) <- authenticate
5051 logf <- asks (.logAction)
5152 tokVar <- asks (.bearerToken)
52− liftIO (putMVar tokVar tok)
53+ liftIO (void $ swapMVar tokVar tok)
5354 liftIO (logf "Connexpay token update success")
5455 updateToken (ts - 5)
5556 `catchError` \err -> do
stack.yaml+1−1
@@ -1,4 +1,4 @@
1−resolver: lts-22.13
1+resolver: lts-22.24
22
33packages:
44- connexpay