{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
module Mollie.API.Payments
( PaymentAPI
, newPayment
, newRecurringPayment
, createPayment
, getPayment
, getPayments
, getPaymentsPaginated
, cancelPayment
) where
import Control.Lens ((&), (.~))
import Data.Default (def)
import qualified Data.Text as Text
import Mollie.API.Internal (HalJSON)
import Mollie.API.Types
import Servant.API
import Servant.API.Generic
newPayment :: Double
-> Text.Text
-> Text.Text
-> NewPayment
newPayment _amount _description _redirectUrl =
(newRecurringPayment _amount _description)
& redirectUrl .~ Just _redirectUrl
& sequenceType .~ Just Oneoff
newRecurringPayment :: Double
-> Text.Text
-> NewPayment
newRecurringPayment _amount _description =
def
& amount .~ (defaultAmount _amount)
& description .~ _description
& redirectUrl .~ Nothing
& webhookUrl .~ Nothing
& method .~ Nothing
& metadata .~ Nothing
& locale .~ Nothing
& sequenceType .~ Just Recurring
& customerId .~ Nothing
& mandateId .~ Nothing
& issuer .~ Nothing
& billingAddress .~ Nothing
& shippingAddress .~ Nothing
& billingEmail .~ Nothing
& dueDate .~ Nothing
& consumerName .~ Nothing
& consumerAccount .~ Nothing
& customerReference .~ Nothing
data PaymentAPI route = PaymentAPI
{ getPaymentsPaginated :: route :- "payments"
:> QueryParam "limit" Int
:> QueryParam "from" PaymentId
:> Get '[HalJSON] (List Payment)
, getPayments :: route :- "payments"
:> Get '[HalJSON] (List Payment)
, createPayment :: route :- "payments"
:> ReqBody '[JSON] NewPayment
:> Post '[HalJSON] Payment
, getPayment :: route :- "payments"
:> Capture "id" PaymentId
:> Get '[HalJSON] Payment
, cancelPayment :: route :- "payments"
:> Capture "id" PaymentId
:> Delete '[HalJSON] Payment
} deriving Generic