@@ -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)