{-# LANGUAGE OverloadedStrings #-}
module Mollie.API.Customers
( customersPath
, newCustomer
, createCustomer
, getCustomer
, getCustomers
, createCustomerPayment
, getCustomerPayments
, NewCustomer (..)
, Customer (..)
, Mode (..)
, PaymentStatus (..)
, PaymentMethod (..)
, RecurringType (..)
, NewPayment (..)
, Payment (..)
, PaymentLinks (..)
, List (..)
, ListLinks (..)
, ResponseError (..)
) where
import Data.Monoid
import qualified Data.Text as Text
import Mollie.API.Internal
import Mollie.API.Payments
import Mollie.API.Types
import qualified Network.HTTP.Types as HTTP
customersPath :: Text.Text
customersPath = "customers"
newCustomer :: Text.Text
-> Text.Text
-> NewCustomer
newCustomer name email = NewCustomer
{ newCustomer_name = name
, newCustomer_email = email
, newCustomer_locale = Nothing
, newCustomer_metadata = Nothing
}
createCustomer :: NewCustomer -> Mollie (Either ResponseError Customer)
createCustomer newCustomer = do
result <- send HTTP.methodPost path newCustomer
return $ decodeResult result
where
path = customersPath
getCustomer :: Text.Text
-> Mollie (Either ResponseError Customer)
getCustomer customerId = get path
where
path = Text.intercalate "/" [customersPath, customerId]
getCustomers :: Int
-> Int
-> Mollie (Either ResponseError (List Customer))
getCustomers offset count = get path
where
path = customersPath <> query
query = "?offset=" <> showT offset <> "&count=" <> showT count
createCustomerPayment :: Text.Text
-> NewPayment -> Mollie (Either ResponseError Payment)
createCustomerPayment customerId newPayment = do
result <- send HTTP.methodPost path newPayment
return $ decodeResult result
where
path = Text.intercalate "/" [customersPath, customerId, paymentsPath]
getCustomerPayments :: Text.Text
-> Int
-> Int
-> Mollie (Either ResponseError (List Payment))
getCustomerPayments customerId offset count = get path
where
path = (Text.intercalate "/" [customersPath, customerId, paymentsPath]) <> query
query = "?offset=" <> showT offset <> "&count=" <> showT count