mirror of
https://github.com/typeable/connexpay.git
synced 2024-10-03 23:17:07 +03:00
Parse more field from the /capture response.
This commit is contained in:
parent
abfd81b42a
commit
fb6812305d
@ -5,6 +5,7 @@ module Web.Connexpay.Payments ( CreditCard(..)
|
||||
, AuthResponse(..)
|
||||
, authorisePayment
|
||||
, voidPayment
|
||||
, CaptureResponse(..)
|
||||
, capturePayment
|
||||
, cancelPayment
|
||||
) where
|
||||
@ -137,10 +138,28 @@ data CPTransaction = CPTransaction { expectedPayments :: Int32 }
|
||||
instance ToJSON CPTransaction where
|
||||
toJSON t = object [ "ExpectedPayments" .= t.expectedPayments ]
|
||||
|
||||
-- | Response for the payment capture request
|
||||
data CaptureResponse = CaptureResponse { captureGuid :: CaptureGuid
|
||||
, saleGuid :: SaleGuid
|
||||
, saleStatus :: TransactionStatus
|
||||
} deriving (Show)
|
||||
|
||||
instance FromJSON CaptureResponse where
|
||||
parseJSON (Object o) =
|
||||
do cguid <- o .: "guid"
|
||||
sale <- o .: "sale"
|
||||
saleGuid <- sale .: "guid"
|
||||
status <- sale .: "status"
|
||||
pure (CaptureResponse cguid saleGuid status)
|
||||
parseJSON v = typeMismatch "CaptureResponse" v
|
||||
|
||||
-- | Capture payment, previously authorised through 'authorisePayment'.
|
||||
capturePayment :: SaleGuid -- ^ Sales GUID, obtained from 'authorisePayment'.
|
||||
-> ConnexpayM ()
|
||||
capturePayment pid = sendRequest_ "Captures" body
|
||||
-> ConnexpayM CaptureResponse
|
||||
capturePayment pid =
|
||||
do resp <- sendRequestJson "Captures" body
|
||||
let rbody = responseBody resp
|
||||
pure rbody
|
||||
where body = [ "AuthOnlyGuid" .= show pid
|
||||
, "ConnexPayTransaction" .= CPTransaction 1 ]
|
||||
|
||||
|
@ -20,6 +20,7 @@ import Network.HTTP.Types
|
||||
type BearerToken = Text
|
||||
type DeviceGuid = UUID
|
||||
type SaleGuid = UUID
|
||||
type CaptureGuid = UUID
|
||||
|
||||
data Connexpay = Connexpay { logAction :: Text -> IO ()
|
||||
, manager :: Manager
|
||||
|
Loading…
Reference in New Issue
Block a user