@@ -1,6 +1,7 @@
11{-# LANGUAGE OverloadedStrings #-}
22module Web.Connexpay.Types where
33
4+import Web.Connexpay.Data
45import Web.Connexpay.Utils
56
67import Control.Concurrent.Async
@@ -9,7 +10,6 @@ import Control.Monad.Except (MonadError, ExceptT, runExceptT, throwError)
910import Control.Monad.IO.Class
1011import Control.Monad.Reader
1112import Data.Aeson
12−import Data.Aeson.Types (typeMismatch)
1313import Data.Text (Text)
1414import Data.Text qualified as Text
1515import Data.UUID (UUID)
@@ -32,38 +32,6 @@ data Connexpay = Connexpay { logAction :: Text -> IO ()
3232 , password :: Text
3333 }
3434
35−-- | Payment failure types.
36−-- This type describes failures that related to either credit card being invalid,
37−-- client account having insufficient funds, and other non-technical conditions.
38−-- FIXME: this list is not exhaustive. Add more values whenever we encounter them.
39−data PaymentFailure = CVVFailed -- ^ CVV verification failure
40− | CardInvalid -- ^ Credit card details are invalid
41− | InvalidAmount -- ^ Money amount is invalid
42− | LocalTransaction -- ^ Special case for transactions that were registered but did't go through somehow.
43− deriving (Eq, Show)
44−
45−-- | Guess failure type from HTTP code and supplied error string.
46−guessFailure :: Int -> Text -> Maybe PaymentFailure
47−guessFailure 422 "Error code D2020. CVV2 verification failed." = Just CVVFailed
48−guessFailure 422 "Error code D2005. Invalid Card." = Just CardInvalid
49−guessFailure 422 "Amount field don't allow a value greater than $999,999.99" = Just InvalidAmount
50−guessFailure _ _ = Nothing
51−
52−-- | Error response from Connexpay
53−data ErrorMessage = ErrorMessage { message :: Text
54− , errorId :: Text }
55−
56−instance FromJSON ErrorMessage where
57− parseJSON (Object o) = ErrorMessage <$> o .: "message"
58− <*> o .: "errorId"
59− parseJSON v = typeMismatch "ErrorMessage" v
60−
61−data PaymentError = ParseError String
62− | InvalidUrl String String
63− | HttpFailure HttpExceptionContent
64− | PaymentFailure PaymentFailure
65− deriving (Show)
66−
6735newtype ConnexpayM a = ConnexpayM (ReaderT Connexpay (ExceptT PaymentError IO) a)
6836 deriving (Functor, Applicative, Monad, MonadIO, MonadReader Connexpay, MonadError PaymentError)
6937