module Web.Stripe.Coupon
(
createCoupon
, getCoupon
, getCoupons
, updateCoupon
, deleteCoupon
, Duration (..)
, AmountOff (..)
, CouponId (..)
, Coupon (..)
, Currency (..)
, DurationInMonths (..)
, MaxRedemptions (..)
, PercentOff (..)
, RedeemBy (..)
, StripeList (..)
, StripeDeleteResult (..)
) where
import Web.Stripe.Client.Internal (Method (POST, DELETE, GET), Stripe,
StripeRequest (..), callAPI, toMetaData,
getParams, toText, (</>), toTextLower)
import Web.Stripe.Types (AmountOff (..), Coupon (..),
CouponId (..), Currency (..),
Duration(..), DurationInMonths (..),
EndingBefore, Limit, MetaData,
MaxRedemptions (..),
PercentOff (..), RedeemBy (..),
StartingAfter,
StripeDeleteResult (..),
StripeList (..))
createCoupon
:: Maybe CouponId
-> Duration
-> Maybe AmountOff
-> Maybe Currency
-> Maybe DurationInMonths
-> Maybe MaxRedemptions
-> Maybe PercentOff
-> Maybe RedeemBy
-> MetaData
-> Stripe Coupon
createCoupon
couponid
duration
amountOff
currency
durationInMonths
maxRedemptions
percentOff
redeemBy
metadata = callAPI request
where request = StripeRequest POST url params
url = "coupons"
params = toMetaData metadata ++ getParams [
("id", (\(CouponId x) -> x) `fmap` couponid )
, ("duration", toText `fmap` Just duration )
, ("amount_off", (\(AmountOff x) -> toText x) `fmap` amountOff )
, ("currency", toTextLower `fmap` currency)
, ("duration_in_months", (\(DurationInMonths x) -> toText x) `fmap` durationInMonths )
, ("max_redemptions", (\(MaxRedemptions x) -> toText x) `fmap` maxRedemptions )
, ("percent_off", (\(PercentOff x) -> toText x) `fmap` percentOff )
, ("redeem_by", (\(RedeemBy x) -> toText x) `fmap` redeemBy )
]
getCoupon
:: CouponId
-> Stripe Coupon
getCoupon
(CouponId couponid) = callAPI request
where request = StripeRequest GET url params
url = "coupons" </> couponid
params = []
getCoupons
:: Maybe Limit
-> StartingAfter CouponId
-> EndingBefore CouponId
-> Stripe (StripeList Coupon)
getCoupons
limit
startingAfter
endingBefore
= callAPI request
where request = StripeRequest GET url params
url = "coupons"
params = getParams [
("limit", toText `fmap` limit )
, ("starting_after", (\(CouponId x) -> x) `fmap` startingAfter)
, ("ending_before", (\(CouponId x) -> x) `fmap` endingBefore)
]
updateCoupon
:: CouponId
-> MetaData
-> Stripe Coupon
updateCoupon
(CouponId couponid)
metadata = callAPI request
where request = StripeRequest POST url params
url = "coupons" </> couponid
params = toMetaData metadata
deleteCoupon
:: CouponId
-> Stripe StripeDeleteResult
deleteCoupon
(CouponId couponid) = callAPI request
where request = StripeRequest DELETE url params
url = "coupons" </> couponid
params = []