@@ -5,6 +5,7 @@ module Web.Connexpay.Payments ( CreditCard(..)
5 , AuthResponse(..)
5 , AuthResponse(..)
6 , authorisePayment
6 , authorisePayment
7 , voidPayment
7 , voidPayment
8 , capturePayment
9 , capturePayment
9 , cancelPayment
10 , cancelPayment
@@ -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 ]
141+-- | Response for the payment capture request
142+data CaptureResponse = CaptureResponse { captureGuid :: CaptureGuid
143+ , saleGuid :: SaleGuid
144+ , saleStatus :: TransactionStatus
147+instance FromJSON CaptureResponse where
148+ parseJSON (Object o) =
149+ do cguid <- o .: "guid"
151+ saleGuid <- sale .: "guid"
152+ status <- sale .: "status"
153+ pure (CaptureResponse cguid saleGuid status)
154+ parseJSON v = typeMismatch "CaptureResponse" v
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
144 where body = [ "AuthOnlyGuid" .= show pid
163 where body = [ "AuthOnlyGuid" .= show pid
145 , "ConnexPayTransaction" .= CPTransaction 1 ]
164 , "ConnexPayTransaction" .= CPTransaction 1 ]