@@ -9,13 +9,12 @@ module Web.Connexpay.Payments ( CreditCard(..)
99 , cancelPayment
1010 ) where
1111
12−import Web.Connexpay.Utils
13−
1412import Control.Monad (void)
1513import Control.Monad.Reader (asks)
1614import Control.Monad.Writer.Strict
1715import Data.Aeson
1816import Data.Aeson.Types (Pair, typeMismatch)
17+import Data.Int (Int32)
1918import Data.Money
2019import Data.Proxy
2120import Data.Text (Text)
@@ -26,6 +25,7 @@ import Network.HTTP.Req
2625
2726import Web.Connexpay.Data
2827import Web.Connexpay.Types
28+import Web.Connexpay.Utils
2929
3030-- | Credit card info
3131-- No 'Show' instance should be made for this type
@@ -61,7 +61,7 @@ sendRequest' resp endpoint body =
6161 do tok <- bearerToken
6262 host <- asks (.url)
6363 let auth = header "Authorization" ("Bearer " <> Text.encodeUtf8 tok)
64− url = http host /: "api" /: "v1" /: endpoint
64+ url = https host /: "api" /: "v1" /: endpoint
6565 jbody <- ReqBodyJson . object <$> addGuid body
6666 req POST url jbody resp auth
6767 where addGuid b = do guid <- asks (.deviceGuid)
@@ -100,9 +100,17 @@ voidPayment pid amt = sendRequest_ "void" body
100100 whenJust amt $ \m ->
101101 tell [ "Amount" .= getAmount m ]
102102
103+-- | Internal data type for Capture requests.
104+data CPTransaction = CPTransaction { expectedPayments :: Int32 }
105+
106+instance ToJSON CPTransaction where
107+ toJSON t = object [ "ExpectedPayments" .= t.expectedPayments ]
108+
109+
103110capturePayment :: SaleGuid -> ConnexpayM ()
104111capturePayment pid = sendRequest_ "Captures" body
105− where body = [ "AuthOnlyGuid" .= show pid ]
112+ where body = [ "AuthOnlyGuid" .= show pid
113+ , "ConnexPayTransaction" .= CPTransaction 1 ]
106114
107115cancelPayment :: SaleGuid -> ConnexpayM ()
108116cancelPayment pid = sendRequest_ "cancel" body