git.iko.soy/typeable/connexpay
on master help sign in
Parse more field from the /capture response.
commitfb6812305d13f38c5e3fe0282451c58b1183eec5 authorNick <nick@typeable.io> dateMon 5 Aug 2024, 05:12 (2 years ago) parentabfd81b
2 files changed+22−2
connexpay/src/Web/Connexpay/Payments.hs+21−2 connexpay/src/Web/Connexpay/Types.hs+1
connexpay/src/Web/Connexpay/Payments.hs+21−2
@@ -5,6 +5,7 @@ module Web.Connexpay.Payments ( CreditCard(..)
55 , AuthResponse(..)
66 , authorisePayment
77 , voidPayment
8+ , CaptureResponse(..)
89 , capturePayment
910 , cancelPayment
1011 ) where
@@ -137,10 +138,28 @@ data CPTransaction = CPTransaction { expectedPayments :: Int32 }
137138instance ToJSON CPTransaction where
138139 toJSON t = object [ "ExpectedPayments" .= t.expectedPayments ]
139140
141+-- | Response for the payment capture request
142+data CaptureResponse = CaptureResponse { captureGuid :: CaptureGuid
143+ , saleGuid :: SaleGuid
144+ , saleStatus :: TransactionStatus
145+ } deriving (Show)
146+
147+instance FromJSON CaptureResponse where
148+ parseJSON (Object o) =
149+ do cguid <- o .: "guid"
150+ sale <- o .: "sale"
151+ saleGuid <- sale .: "guid"
152+ status <- sale .: "status"
153+ pure (CaptureResponse cguid saleGuid status)
154+ parseJSON v = typeMismatch "CaptureResponse" v
155+
140156-- | Capture payment, previously authorised through 'authorisePayment'.
141157capturePayment :: SaleGuid -- ^ Sales GUID, obtained from 'authorisePayment'.
142− -> ConnexpayM ()
143−capturePayment pid = sendRequest_ "Captures" body
158+ -> ConnexpayM CaptureResponse
159+capturePayment pid =
160+ do resp <- sendRequestJson "Captures" body
161+ let rbody = responseBody resp
162+ pure rbody
144163 where body = [ "AuthOnlyGuid" .= show pid
145164 , "ConnexPayTransaction" .= CPTransaction 1 ]
146165
connexpay/src/Web/Connexpay/Types.hs+1
@@ -20,6 +20,7 @@ import Network.HTTP.Types
2020type BearerToken = Text
2121type DeviceGuid = UUID
2222type SaleGuid = UUID
23+type CaptureGuid = UUID
2324
2425data Connexpay = Connexpay { logAction :: Text -> IO ()
2526 , manager :: Manager