{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
module Web.Stripe.Plan
(
CreatePlan
, createPlan
, GetPlan
, getPlan
, UpdatePlan
, updatePlan
, DeletePlan
, deletePlan
, GetPlans
, getPlans
, Amount (..)
, Currency (..)
, EndingBefore (..)
, Interval (..)
, IntervalCount (..)
, Limit (..)
, MetaData (..)
, Plan (..)
, PlanId (..)
, PlanName (..)
, StartingAfter (..)
, StatementDescription(..)
, StripeDeleteResult (..)
, StripeList (..)
, TrialPeriodDays (..)
) where
import Data.Text (Text)
import Web.Stripe.StripeRequest (Method (GET, POST, DELETE), Param(..),
StripeHasParam, StripeRequest (..),
StripeReturn, ToStripeParam(..),
mkStripeRequest)
import Web.Stripe.Types (PlanId (..) , Plan (..), PlanName(..),
Interval (..), StripeList(..),
IntervalCount (..), TrialPeriodDays (..),
Limit(..), StartingAfter(..),
EndingBefore(..), StripeDeleteResult(..),
Currency (..), Amount(..),
StatementDescription(..), MetaData(..))
import Web.Stripe.Util ((</>))
createPlan
:: PlanId
-> Amount
-> Currency
-> Interval
-> PlanName
-> StripeRequest CreatePlan
createPlan
(PlanId planid)
amount
currency
interval
name = request
where request = mkStripeRequest POST url params
url = "plans"
params = toStripeParam (Param ("id" :: Text, planid)) $
toStripeParam amount $
toStripeParam currency $
toStripeParam interval $
toStripeParam name $
[]
data CreatePlan
type instance StripeReturn CreatePlan = Plan
instance StripeHasParam CreatePlan IntervalCount
instance StripeHasParam CreatePlan TrialPeriodDays
instance StripeHasParam CreatePlan MetaData
instance StripeHasParam CreatePlan StatementDescription
getPlan
:: PlanId
-> StripeRequest GetPlan
getPlan
(PlanId planid) = request
where request = mkStripeRequest GET url params
url = "plans" </> planid
params = []
data GetPlan
type instance StripeReturn GetPlan = Plan
updatePlan
:: PlanId
-> StripeRequest UpdatePlan
updatePlan
(PlanId planid)
= request
where request = mkStripeRequest POST url params
url = "plans" </> planid
params = []
data UpdatePlan
type instance StripeReturn UpdatePlan = Plan
instance StripeHasParam UpdatePlan PlanName
instance StripeHasParam UpdatePlan MetaData
instance StripeHasParam UpdatePlan StatementDescription
deletePlan
:: PlanId
-> StripeRequest DeletePlan
deletePlan
(PlanId planid) = request
where request = mkStripeRequest DELETE url params
url = "plans" </> planid
params = []
data DeletePlan
type instance StripeReturn DeletePlan = StripeDeleteResult
getPlans :: StripeRequest GetPlans
getPlans = request
where request = mkStripeRequest GET url params
url = "plans"
params = []
data GetPlans
type instance StripeReturn GetPlans = (StripeList Plan)
instance StripeHasParam GetPlans (EndingBefore PlanId)
instance StripeHasParam GetPlans Limit
instance StripeHasParam GetPlans (StartingAfter PlanId)