git.iko.soy/typeable/connexpay
on 9300166 help sign in
3 files changed+9−37
since splitsnapshots
unifiedsplit
connexpay/src/Web/Connexpay/Payments.hs+6−8 connexpay/src/Web/Connexpay/Payments/Types.hs+1−27 connexpay/src/Web/Connexpay/Types.hs+2−2
connexpay/src/Web/Connexpay/Payments.hs+6−8
@@ -5,7 +5,6 @@ module Web.Connexpay.Payments
55 , ExpirationDate(..)
66 , Customer(..)
77 , RiskData(..)
8− , AuthorizeResult(..)
98 , AuthResponse(..)
109 , TransactionStatus(..)
1110 , authorisePayment
@@ -27,13 +26,12 @@ import Web.Connexpay.Types
2726
2827-- | Authorise a credit card payment.
2928authorisePayment
30− :: Connexpay -> Env -> AuthRequest -> IO (Response AuthError AuthorizeResult)
31−authorisePayment connexpay env raw =
32− bimapResponse (guessErrorType guessAuthError) postProcessAuthResponse <$>
33− doRequest connexpay env "authonlys" RequestBody
34− { raw
35− , logMasker = maskAuthRequest
36− }
29+ :: Connexpay -> Env -> AuthRequest -> IO (Response AuthError AuthResponse)
30+authorisePayment connexpay env raw = guessResponseErrorType guessAuthError <$>
31+ doRequest connexpay env "authonlys" RequestBody
32+ { raw
33+ , logMasker = maskAuthRequest
34+ }
3735
3836-- | Void payment
3937voidPayment :: Connexpay -> Env -> VoidRequest -> IO (Response () ())
connexpay/src/Web/Connexpay/Payments/Types.hs+1−27
@@ -6,7 +6,6 @@ module Web.Connexpay.Payments.Types where
66import Data.Aeson
77import Data.Aeson.TH
88import Data.Fixed
9−import Data.Function
109import Data.Int (Int32)
1110import Data.Maybe
1211import Data.Text (Text)
@@ -117,30 +116,6 @@ instance ToJSON RiskData where
117116maskRiskData :: LogMasker RiskData
118117maskRiskData = id
119118
120−data AuthorizeResult
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)
131−
132−postProcessAuthResponse :: AuthResponse -> AuthorizeResult
133−postProcessAuthResponse resp = resp & case (completed, statusOk) of
134− (True, True) -> Authorized
135− (False, False) -> Declined
136− _ -> Ambiguous
137− where
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]
143−
144119data AuthResponse = AuthResponse
145120 { guid :: AuthOnlyGuid
146121 , status :: TransactionStatus
@@ -148,7 +123,6 @@ data AuthResponse = AuthResponse
148123 , processorResponseMessage :: Maybe Text
149124 , addressVerificationCode :: Maybe Text
150125 , cvvVerificationCode :: Maybe Text
151− , wasProcessed :: Maybe Bool
152126 } deriving stock (Show)
153127
154128-- | Transaction status in Connexpay
@@ -165,7 +139,7 @@ data TransactionStatus
165139 -- ^ Processor errored out
166140 | TransactionOther Text
167141 -- ^ In case they return something unexpected
168− deriving stock (Eq, Show)
142+ deriving stock (Show)
169143
170144instance FromJSON TransactionStatus where
171145 parseJSON = withText "TransactionStatus" $ pure . \case
connexpay/src/Web/Connexpay/Types.hs+2−2
@@ -67,8 +67,8 @@ bimapResponse f g = \case
6767 BadRequest body -> BadRequest body
6868 MissingOrExpiredToken -> MissingOrExpiredToken
6969
70−guessErrorType :: (Error () -> e) -> Error () -> Error e
71−guessErrorType mkErr e = e { errorType = mkErr e }
70+guessResponseErrorType :: (Error () -> e) -> Response () a -> Response e a
71+guessResponseErrorType mkErr = bimapResponse (\e -> e { errorType = mkErr e }) id
7272
7373data Error e = Error
7474 { message :: Text