module Network.Pagarme (baseUrl
, withApiKey
, getTransactions
, byPage
, byConfirmedStatus
, byStatus
) where
import qualified Data.ByteString.Lazy as BS
import Network.Wreq
import Control.Lens
import qualified Data.Text as T
import Data.Map as Map
import Data.Aeson (Value)
import qualified Data.Aeson.Types as A
type SingleResult = Response A.Object
type ResultSet = Response [A.Object]
baseUrl :: String
baseUrl = "https://api.pagar.me/1/"
getJSON :: A.FromJSON a => Options -> String -> IO (Response a)
getJSON requestOptions path = asJSON =<< getWith requestOptions (baseUrl ++ path)
toText :: Show a => a -> T.Text
toText = T.pack . show
getOne requestOptions path = do
r <- getJSON requestOptions path :: IO SingleResult
return $ r ^. responseBody
getAll requestOptions path = do
r <- getJSON requestOptions path :: IO ResultSet
return $ r ^. responseBody
byPage pageNumber requestOptions = requestOptions & param "page" .~ [toText pageNumber]
& param "count" .~ ["100"]
byStatus status requestOptions = requestOptions & param "status" .~ [status]
byConfirmedStatus = byStatus "paid"
withApiKey key requestOptions = requestOptions & param "api_key" .~ [key]
getTransactions requestOptions = getAll requestOptions "transactions"