git.iko.soy/typeable/connexpay
on master help sign in
Void via auth or sale guids
commit2ae6bfcbc1e93d3f2d2c1f553bf0700fff29b5c0 authorYuras Shumovich <shumovichy@gmail.com> dateThu 22 Aug 2024, 10:32 (2 years ago) parent84ee284
4 files changed+22−10
README.org+5−1 connexpay/src/Tool.hs+7−4 connexpay/src/Web/Connexpay/Payments.hs+9−5 connexpay/src/Web/Connexpay/Types.hs+1
README.org+5−1
@@ -35,8 +35,12 @@ Examples:
3535
3636 - ~stack run -- -c ./config.yaml auth CARDNUMBER "NAME" MMYY CVV SUM~
3737 - ~stack run -- -c ./config.yaml capture SALEGUID~
38− - ~stack run -- -c ./config.yaml void SALEGUID~
38+ - ~stack run -- -c ./config.yaml void-auth AUTHONLYGUID~
39+ - ~stack run -- -c ./config.yaml void-sale SALEGUID~
40+ - ~stack run -- -c ./config.yaml void-sale SALEGUID SUM~
3941 - ~stack run -- -c ./config.yaml cancel SALEGUID~
42+ - ~stack run -- -c ./config.yaml return SALEGUID~
43+ - ~stack run -- -c ./config.yaml return SALEGUID SUM~
4044
4145Configuration file must include the values provided to you by Connexpay:
4246
connexpay/src/Tool.hs+7−4
@@ -33,8 +33,9 @@ data Config = Config { login :: Text
3333instance FromJSON Config
3434
3535data Command = AuthSale CreditCard Centi
36− | VoidSale SaleGuid
37− | CaptureSale SaleGuid
36+ | VoidAuth AuthOnlyGuid
37+ | VoidSale SaleGuid (Maybe Centi)
38+ | CaptureSale AuthOnlyGuid
3839 | CancelSale SaleGuid
3940 | ReturnSale SaleGuid (Maybe Centi)
4041 | TestAuth
@@ -47,7 +48,8 @@ cmdParser :: Parser CmdLine
4748cmdParser = CmdLine <$> strOption (short 'c' <> metavar "FILE" <> help "Configuration file path")
4849 <*> subparser operation
4950 where operation = command "auth" (info (AuthSale <$> cc <*> amt) (progDesc "Authorise payment"))
50− <> command "void" (info (VoidSale <$> guid) (progDesc "Void payment"))
51+ <> command "void-auth" (info (VoidAuth <$> guid) (progDesc "Void payment"))
52+ <> command "void-sale" (info (VoidSale <$> guid <*> optional amt) (progDesc "Void payment"))
5153 <> command "capture" (info (CaptureSale <$> guid) (progDesc "Capture payment"))
5254 <> command "cancel" (info (CancelSale <$> guid) (progDesc "Cancel payment"))
5355 <> command "return" (info (ReturnSale <$> guid <*> optional amt) (progDesc "return payment"))
@@ -84,7 +86,8 @@ doThing (AuthSale cc amt) = liftIO . print =<< authorisePayment cc usd pnr vendo
8486 where usd = Money amt
8587 pnr = Just "PNRPNR"
8688 vendor = Just "Typeable payment"
87−doThing (VoidSale guid) = liftIO . print =<< voidPayment guid Nothing
89+doThing (VoidAuth guid) = liftIO . print =<< voidPayment (VoidAuthorized guid)
90+doThing (VoidSale guid amt) = liftIO . print =<< voidPayment (VoidCaptured guid (Money <$> amt))
8891doThing (CaptureSale guid) = liftIO . print =<< capturePayment guid
8992doThing (CancelSale guid) = liftIO . print =<< cancelPayment guid
9093doThing (ReturnSale guid amt) = liftIO . print =<< returnPayment guid (Money <$> amt)
connexpay/src/Web/Connexpay/Payments.hs+9−5
@@ -4,6 +4,7 @@
44module Web.Connexpay.Payments ( CreditCard(..)
55 , AuthResponse(..)
66 , authorisePayment
7+ , VoidRequest(..)
78 , voidPayment
89 , CaptureResponse(..)
910 , capturePayment
@@ -105,7 +106,7 @@ sendRequestJson = sendRequest' jsonResponse
105106sendRequest_ :: Text -> [Pair] -> ConnexpayM ()
106107sendRequest_ ep = void . sendRequest' ignoreResponse ep
107108
108−data AuthResponse = AuthResponse { paymentGuid :: SaleGuid
109+data AuthResponse = AuthResponse { paymentGuid :: AuthOnlyGuid
109110 , status :: TransactionStatus
110111 , processorStatusCode :: Maybe Text
111112 , processorMessage :: Maybe Text
@@ -148,13 +149,16 @@ authorisePayment cc amt invoice vendor =
148149 -- should the need arise.
149150 tell [ "RiskData" .= KeyMap.empty @() ]
150151
152+data VoidRequest = VoidAuthorized AuthOnlyGuid | VoidCaptured SaleGuid (Maybe (Money USD))
153+
151154-- | Void payment
152−voidPayment :: SaleGuid -- ^ Sales GUID, obtained from 'authorisePayment'.
153− -> Maybe (Money USD) -- ^ Optionally, you may only void a partial sum, with the rest being subsequently charged.
155+voidPayment :: VoidRequest
154156 -> ConnexpayM ()
155−voidPayment pid amt = sendRequest_ "void" body
157+voidPayment (VoidAuthorized pid) = sendRequest_ "void" body
158+ where body = [ "AuthOnlyGuid" .= show pid ]
159+voidPayment (VoidCaptured pid amt) = sendRequest_ "void" body
156160 where body = execWriter $
157− do tell [ "AuthOnlyGuid" .= show pid ]
161+ do tell [ "SaleGuid" .= show pid ]
158162 whenJust amt $ \m ->
159163 tell [ "Amount" .= getAmount m ]
160164
connexpay/src/Web/Connexpay/Types.hs+1
@@ -19,6 +19,7 @@ import Network.HTTP.Types
1919
2020type BearerToken = Text
2121type DeviceGuid = UUID
22+type AuthOnlyGuid = UUID
2223type SaleGuid = UUID
2324type CaptureGuid = UUID
2425