git.iko.soy/typeable/connexpay
on master help sign in
Parse more field from the /capture response.
fb68123Nick
connexpay/src/Web/Connexpay/Payments.hs+21−2
@@ -5,6 +5,7 @@ module Web.Connexpay.Payments ( CreditCard(..)
5 , AuthResponse(..)
5 , AuthResponse(..)
6 , authorisePayment
6 , authorisePayment
7 , voidPayment
7 , voidPayment
8+ , CaptureResponse(..)
8 , capturePayment
9 , capturePayment
9 , cancelPayment
10 , cancelPayment
10 ) where
11 ) where
@@ -137,10 +138,28 @@ data CPTransaction = CPTransaction { expectedPayments :: Int32 }
137instance ToJSON CPTransaction where
138instance ToJSON CPTransaction where
138 toJSON t = object [ "ExpectedPayments" .= t.expectedPayments ]
139 toJSON t = object [ "ExpectedPayments" .= t.expectedPayments ]
139
140
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+
140-- | Capture payment, previously authorised through 'authorisePayment'.
156-- | Capture payment, previously authorised through 'authorisePayment'.
141capturePayment :: SaleGuid -- ^ Sales GUID, obtained from 'authorisePayment'.
157capturePayment :: SaleGuid -- ^ Sales GUID, obtained from 'authorisePayment'.
142− -> ConnexpayM ()
158+ -> ConnexpayM CaptureResponse
143−capturePayment pid = sendRequest_ "Captures" body
159+capturePayment pid =
160+ do resp <- sendRequestJson "Captures" body
161+ let rbody = responseBody resp
162+ pure rbody
144 where body = [ "AuthOnlyGuid" .= show pid
163 where body = [ "AuthOnlyGuid" .= show pid
145 , "ConnexPayTransaction" .= CPTransaction 1 ]
164 , "ConnexPayTransaction" .= CPTransaction 1 ]
146
165
connexpay/src/Web/Connexpay/Types.hs+1
@@ -20,6 +20,7 @@ import Network.HTTP.Types
20type BearerToken = Text
20type BearerToken = Text
21type DeviceGuid = UUID
21type DeviceGuid = UUID
22type SaleGuid = UUID
22type SaleGuid = UUID
23+type CaptureGuid = UUID
23
24
24data Connexpay = Connexpay { logAction :: Text -> IO ()
25data Connexpay = Connexpay { logAction :: Text -> IO ()
25 , manager :: Manager
26 , manager :: Manager