{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
module Web.Stripe.Coupon
(
CreateCoupon
, createCoupon
, GetCoupon
, getCoupon
, UpdateCoupon
, updateCoupon
, DeleteCoupon
, deleteCoupon
, GetCoupons
, getCoupons
, AmountOff (..)
, Coupon (..)
, CouponId (..)
, Currency (..)
, Duration (..)
, DurationInMonths (..)
, EndingBefore (..)
, Limit (..)
, MaxRedemptions (..)
, MetaData (..)
, PercentOff (..)
, RedeemBy (..)
, StartingAfter (..)
, StripeDeleteResult (..)
, StripeList (..)
) where
import Data.Text (Text)
import Web.Stripe.StripeRequest (Method (GET, POST, DELETE), Param(..),
StripeHasParam, StripeRequest (..),
StripeReturn, ToStripeParam(..),
mkStripeRequest)
import Web.Stripe.Util ((</>))
import Web.Stripe.Types (AmountOff (..), Coupon (..),
CouponId (..), Currency (..),
Duration(..), DurationInMonths (..),
EndingBefore(..), Limit(..),
MaxRedemptions (..), MetaData(..),
PercentOff (..), RedeemBy (..),
StartingAfter(..),
StripeDeleteResult (..),
StripeList (..))
createCoupon
:: Maybe CouponId
-> Duration
-> StripeRequest CreateCoupon
createCoupon
mcouponid
duration = request
where request = mkStripeRequest POST url params
url = "coupons"
params = case mcouponid of
Just (CouponId name) ->
toStripeParam (Param ("id"::Text, name)) $
toStripeParam duration $
[]
Nothing -> []
data CreateCoupon
type instance StripeReturn CreateCoupon = Coupon
instance StripeHasParam CreateCoupon AmountOff
instance StripeHasParam CreateCoupon Currency
instance StripeHasParam CreateCoupon DurationInMonths
instance StripeHasParam CreateCoupon MaxRedemptions
instance StripeHasParam CreateCoupon MetaData
instance StripeHasParam CreateCoupon PercentOff
instance StripeHasParam CreateCoupon RedeemBy
getCoupon
:: CouponId
-> StripeRequest GetCoupon
getCoupon
(CouponId couponid) = request
where request = mkStripeRequest GET url params
url = "coupons" </> couponid
params = []
data GetCoupon
type instance StripeReturn GetCoupon = Coupon
updateCoupon
:: CouponId
-> StripeRequest UpdateCoupon
updateCoupon
(CouponId couponid)
= request
where request = mkStripeRequest POST url params
url = "coupons" </> couponid
params = []
data UpdateCoupon
type instance StripeReturn UpdateCoupon = Coupon
instance StripeHasParam UpdateCoupon MetaData
deleteCoupon
:: CouponId
-> StripeRequest DeleteCoupon
deleteCoupon
(CouponId couponid) = request
where request = mkStripeRequest DELETE url params
url = "coupons" </> couponid
params = []
data DeleteCoupon
type instance StripeReturn DeleteCoupon = StripeDeleteResult
getCoupons
:: StripeRequest GetCoupons
getCoupons
= request
where request = mkStripeRequest GET url params
url = "coupons"
params = []
data GetCoupons
type instance StripeReturn GetCoupons = (StripeList Coupon)
instance StripeHasParam GetCoupons (EndingBefore CouponId)
instance StripeHasParam GetCoupons Limit
instance StripeHasParam GetCoupons (StartingAfter CouponId)