@@ -6,6 +6,7 @@ module Web.Connexpay.Payments.Types where
6import Data.Aeson
6import Data.Aeson
7import Data.Aeson.TH
7import Data.Aeson.TH
8import Data.Fixed
8import Data.Fixed
9import Data.Int (Int32)
10import Data.Int (Int32)
10import Data.Maybe
11import Data.Maybe
11import Data.Text (Text)
12import Data.Text (Text)
@@ -116,6 +117,30 @@ instance ToJSON RiskData where
116maskRiskData :: LogMasker RiskData
117maskRiskData :: LogMasker RiskData
117maskRiskData = id
118maskRiskData = id
121+ = Authorized AuthResponse
122+ -- ^ Transaction has been created and authorized successfully
123+ | Declined AuthResponse
124+ -- ^ Transaction has been created, but not authorized,
125+ -- e.g. declined by internal Connexpay fraud checks
126+ | Ambiguous AuthResponse
127+ -- ^ We can't interpret the result, e.g. wasProcess=true,
128+ -- but transaction status is not approved.
129+ -- Something for further investigation.
130+ deriving stock (Show)
132+postProcessAuthResponse :: AuthResponse -> AuthorizeResult
133+postProcessAuthResponse resp = resp & case (completed, statusOk) of
134+ (True, True) -> Authorized
135+ (False, False) -> Declined
138+ -- Connexpay documentation is not very clear about 'wasProcessed' semantics
139+ -- when it is missing, so we are intentionally strict here with the idea
140+ -- to warn about all 'Ambiguous' cases and adjust this code accordingly.
141+ completed = resp.wasProcessed == Just True
142+ statusOk = resp.status `elem` [TransactionApproved, TransactionApprovedWarning]
119data AuthResponse = AuthResponse
144data AuthResponse = AuthResponse
120 { guid :: AuthOnlyGuid
145 { guid :: AuthOnlyGuid
121 , status :: TransactionStatus
146 , status :: TransactionStatus
@@ -123,6 +148,7 @@ data AuthResponse = AuthResponse
123 , processorResponseMessage :: Maybe Text
148 , processorResponseMessage :: Maybe Text
124 , addressVerificationCode :: Maybe Text
149 , addressVerificationCode :: Maybe Text
125 , cvvVerificationCode :: Maybe Text
150 , cvvVerificationCode :: Maybe Text
151+ , wasProcessed :: Maybe Bool
126 } deriving stock (Show)
152 } deriving stock (Show)
128-- | Transaction status in Connexpay
154-- | Transaction status in Connexpay
@@ -139,7 +165,7 @@ data TransactionStatus
139 -- ^ Processor errored out
165 -- ^ Processor errored out
140 | TransactionOther Text
166 | TransactionOther Text
141 -- ^ In case they return something unexpected
167 -- ^ In case they return something unexpected
142− deriving stock (Show)
168+ deriving stock (Eq, Show)
144instance FromJSON TransactionStatus where
170instance FromJSON TransactionStatus where
145 parseJSON = withText "TransactionStatus" $ pure . \case
171 parseJSON = withText "TransactionStatus" $ pure . \case