packages feed

stripe 0.8.0 → 0.8.1

raw patch · 4 files changed

+55/−9 lines, 4 filesdep ~http-conduit

Dependency ranges changed: http-conduit

Files

src/Web/Stripe/Coupon.hs view
@@ -7,6 +7,7 @@     , CpnPercentOff(..)     , CpnMaxRedeems(..)     , CpnRedeemBy(..)+    , applyCoupon     , createCoupon     , getCoupon     , getCoupons@@ -35,6 +36,7 @@                                       query_, runStripeT) import           Web.Stripe.Utils    (Count (..), Offset (..), optionalArgs,                                       showByteString, textToByteString)+import           Web.Stripe.Plan     (Plan, amount)  ---------------- -- Data Types --@@ -71,6 +73,15 @@ -- | UTC timestamp specifying the last time at which the coupon can be --   redeemed. newtype CpnRedeemBy = CpnRedeemBy { unCpnRedeemBy :: Int } deriving (Show, Eq)+++applyCoupon :: Maybe Coupon -> Plan -> Int+applyCoupon mCoupon plan =+    (100 - couponOff mCoupon) * amount plan `div` 100+  where+    couponOff :: Maybe Coupon -> Int+    couponOff = maybe 0 (unCpnPercentOff . cpnPercentOff)+  -- | Creates a 'Coupon' in the Stripe system. createCoupon
src/Web/Stripe/Plan.hs view
@@ -2,6 +2,7 @@  module Web.Stripe.Plan     ( Plan(..)+    , amount     , PlanInterval(..)     , PlanId(..)     , PlanTrialDays(..)@@ -61,13 +62,16 @@ --   before the customer is billed. newtype PlanTrialDays = PlanTrialDays { unPlanTrialDays :: Int } deriving (Show, Eq) +amount :: Plan -> Int+amount plan = unAmount $ planAmount plan+ -- | Creates a 'Plan' in the Stripe system. createPlan :: MonadIO m => Plan -> StripeT m () createPlan p = query_ (planRq []) { sMethod = POST, sData = fdata }     where         fdata   = pdata ++ optionalArgs odata         pdata   = [ ("id", textToByteString . unPlanId $ planId p)-                  , ("amount",   showByteString . unAmount  $ planAmount p)+                  , ("amount",   showByteString $ amount p)                   , ("interval", textToByteString . fromPlanInterval $ planInterval p)                   , ("name",     textToByteString $ planName p)                   , ("currency", textToByteString . unCurrency $ planCurrency p)
src/Web/Stripe/Subscription.hs view
@@ -7,9 +7,13 @@     , SubProrate(..)     , SubTrialEnd(..)     , SubAtPeriodEnd(..)+    , SubscriptionList(..)     , createSub+    , getSubscription+    , getSubscriptions     , updateSubRCard     , updateSubToken+    , updateSubscription     , updateSub     , cancelSub @@ -35,7 +39,7 @@                                       showByteString, textToByteString)  import           Control.Applicative ((<$>), (<*>))-import           Data.Aeson          (FromJSON (..), Value (..), (.:), (.:?))+import           Data.Aeson          (FromJSON (..), Value (..), (.:), (.:?), withObject) import qualified Data.ByteString     as B import qualified Data.Text           as T @@ -74,6 +78,11 @@ newtype SubAtPeriodEnd = SubAtPeriodEnd { unSubAtPeriodEnd :: Bool }     deriving (Show, Eq) +data SubscriptionList = SubscriptionList+   { subListCount :: Int+   , subListData :: [Subscription]+   }+ -- | Update the subscription associated with a 'Customer', identified by --   'CustomerId', in the Stripe system. --@@ -94,11 +103,9 @@  -- | Create a new 'Subscription'. Limitations: does not yet support passing --   a card,  quantity, or application fee- createSub :: MonadIO m => CustomerId -> PlanId -> Maybe CpnId           -> Maybe SubTrialEnd           -> StripeT m Subscription-           createSub cid pid mcpnid mste =     snd `liftM` query (subRq cid []) { sMethod = POST, sData = fdata }     where@@ -107,10 +114,25 @@                 , ("trial_end", showByteString . unSubTrialEnd <$> mste)                 ] +getSubscription :: MonadIO m => CustomerId -> SubscriptionId -> StripeT m Subscription+getSubscription cid sid = snd `liftM` query (subsRq cid [unSubscriptionId sid]) { sMethod = GET }++getSubscriptions :: MonadIO m => CustomerId -> StripeT m SubscriptionList+getSubscriptions cid = snd `liftM` query (subsRq cid []) { sMethod = GET }++-- | Update a 'Subscription'+updateSubscription+    :: MonadIO m => CustomerId -> PlanId+    -> Maybe CpnId -> Maybe SubProrate -> Maybe SubTrialEnd+    -> StripeT m Subscription+updateSubscription = updateSub []+ -- | Internal convenience function to update a 'Subscription'.-updateSub :: MonadIO m => [(B.ByteString, B.ByteString)] -> CustomerId -> PlanId-          -> Maybe CpnId -> Maybe SubProrate -> Maybe SubTrialEnd-          -> StripeT m Subscription+-- Try using 'updateSubscription', 'updateSubToken', or 'updateSubRCard'+updateSub+    :: MonadIO m => [(B.ByteString, B.ByteString)] -> CustomerId -> PlanId+    -> Maybe CpnId -> Maybe SubProrate -> Maybe SubTrialEnd+    -> StripeT m Subscription updateSub sdata cid pid mcpnid mspr mste =     snd `liftM` query (subRq cid []) { sMethod = POST, sData = fdata }     where@@ -134,6 +156,10 @@ subRq (CustomerId cid) pcs =     baseSReq { sDestination = "customers":cid:"subscription":pcs } +subsRq :: CustomerId -> [T.Text] -> StripeRequest+subsRq (CustomerId cid) pcs =+    baseSReq { sDestination = "customers":cid:"subscriptions":pcs }+ ------------------ -- JSON Parsing -- ------------------@@ -163,3 +189,8 @@       <*> (     fromSeconds <$> o .:  "current_period_end")       <*> o .:? "discount"     parseJSON _ = mzero++instance FromJSON SubscriptionList where+    parseJSON = withObject "SubscriptionList" $ \o -> SubscriptionList+      <$> o .: "count"+      <*> o .: "data"
stripe.cabal view
@@ -1,5 +1,5 @@ Name:                stripe-Version:             0.8.0+Version:             0.8.1 Synopsis:            A Haskell implementation of the Stripe API. Description:         This is an implementation of the Stripe API as it is                      documented at https:\/\/stripe.com\/docs\/api@@ -39,7 +39,7 @@                         , aeson                >= 0.6.1   && < 0.8                         , unordered-containers >= 0.1.4.6 && < 0.3                         , time                 >= 1.0     && < 1.5-                        , http-conduit         >= 2.0     && < 2.1+                        , http-conduit         >= 2.0     && < 2.2                         , http-types           >= 0.6.11  && < 0.9                         , bytestring           >= 0.9     && < 0.11                         , mtl                  >= 2.1     && < 2.2