diff --git a/PaymentServer.cabal b/PaymentServer.cabal index b29d04b62e5fc4d000c50e788f836720f41335e3..4bba8eea5a2d1bc944ac946fb030c539a3bc978e 100644 --- a/PaymentServer.cabal +++ b/PaymentServer.cabal @@ -17,6 +17,7 @@ library hs-source-dirs: src exposed-modules: PaymentServer.Processors.Stripe , PaymentServer.Persistence + , PaymentServer.Server , PaymentServer.Main build-depends: base >= 4.7 && < 5 , aeson diff --git a/src/PaymentServer/Main.hs b/src/PaymentServer/Main.hs index cf965e608f1e8b3f4c7653f51911cbb5693dcb84..adbc78b7754d89481363380c483f17064f42c9fe 100644 --- a/src/PaymentServer/Main.hs +++ b/src/PaymentServer/Main.hs @@ -1,7 +1,4 @@ -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE TypeOperators #-} - +-- | This module implements the main entrypoint to the PaymentServer. module PaymentServer.Main ( main ) where @@ -9,13 +6,6 @@ module PaymentServer.Main import Data.Default ( def ) -import Servant - ( Proxy(Proxy) - , Server - , Application - , serve - , (:>) - ) import Network.Wai.Handler.Warp ( run ) @@ -28,25 +18,12 @@ import Network.Wai.Middleware.RequestLogger.JSON ( formatAsJSON ) import PaymentServer.Persistence - ( VoucherDatabase - , memory + ( memory ) -import PaymentServer.Processors.Stripe - ( StripeAPI - , stripeServer +import PaymentServer.Server + ( paymentServerApp ) -type PaymentServerAPI = "v1" :> "stripe" :> StripeAPI - -paymentServer :: VoucherDatabase d => d -> Server PaymentServerAPI -paymentServer = stripeServer - -paymentServerAPI :: Proxy PaymentServerAPI -paymentServerAPI = Proxy - -paymentServerApp :: VoucherDatabase d => d -> Application -paymentServerApp = (serve paymentServerAPI) . paymentServer - main :: IO () main = do db <- memory diff --git a/src/PaymentServer/Server.hs b/src/PaymentServer/Server.hs new file mode 100644 index 0000000000000000000000000000000000000000..f4ecaf3eb1f62a307e9a8dbc9651b05b6447855e --- /dev/null +++ b/src/PaymentServer/Server.hs @@ -0,0 +1,39 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE TypeOperators #-} + +-- | This module exposes a Servant-based Network.Wai server for payment +-- interactions. +module PaymentServer.Server + ( paymentServerApp + ) where + +import Servant + ( Proxy(Proxy) + , Server + , Application + , serve + , (:>) + ) +import PaymentServer.Processors.Stripe + ( StripeAPI + , stripeServer + ) +import PaymentServer.Persistence + ( VoucherDatabase + ) + +-- | This is the complete type of the server API. +type PaymentServerAPI = "v1" :> "stripe" :> StripeAPI + +-- | Create a server which uses the given database. +paymentServer :: VoucherDatabase d => d -> Server PaymentServerAPI +paymentServer = stripeServer + +paymentServerAPI :: Proxy PaymentServerAPI +paymentServerAPI = Proxy + +-- | Create a Servant Application which serves the payment server API using +-- the given database. +paymentServerApp :: VoucherDatabase d => d -> Application +paymentServerApp = (serve paymentServerAPI) . paymentServer