module Mollie.API.Mandates
( mandatesPath
, newMandate
, createCustomerMandate
, getCustomerMandate
, getCustomerMandates
, PaymentMethod (..)
, NewMandate (..)
, MandateStatus (..)
, MandateDetails (..)
, Mandate (..)
, ListLinks (..)
, List (..)
, ResponseError (..)
) where
import Data.Monoid
import qualified Data.Text as Text
import Mollie.API.Customers
import Mollie.API.Internal
import Mollie.API.Types
import qualified Network.HTTP.Types as HTTP
mandatesPath :: Text.Text
mandatesPath = "mandates"
newMandate :: PaymentMethod
-> Text.Text
-> Text.Text
-> NewMandate
newMandate method consumerName consumerAccount = NewMandate
{ newMandate_method = method
, newMandate_consumerName = consumerName
, newMandate_consumerAccount = consumerAccount
, newMandate_consumerBic = Nothing
, newMandate_signatureDate = Nothing
, newMandate_mandateReference = Nothing
}
createCustomerMandate :: Text.Text
-> NewMandate -> Mollie (Either ResponseError Mandate)
createCustomerMandate customerId newMandate = do
result <- send HTTP.methodPost path newMandate
return $ decodeResult result
where
path = Text.intercalate "/" [customersPath, customerId, mandatesPath]
getCustomerMandate :: Text.Text
-> Text.Text
-> Mollie (Either ResponseError Mandate)
getCustomerMandate customerId mandateId = get path
where
path = Text.intercalate "/" [customersPath, customerId, mandatesPath, mandateId]
getCustomerMandates :: Text.Text
-> Int
-> Int
-> Mollie (Either ResponseError (List Mandate))
getCustomerMandates customerId offset count = get path
where
path = (Text.intercalate "/" [customersPath, customerId, mandatesPath]) <> query
query = "?offset=" <> showT offset <> "&count=" <> showT count