Skip to content

Commit

Permalink
Merge pull request #86 from nmattia/nm/retrieve-all-subsc
Browse files Browse the repository at this point in the history
Retrieve all subscriptions
  • Loading branch information
dmjio authored Jan 23, 2018
2 parents 31a97a1 + e073c48 commit d98f4b9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 7 deletions.
29 changes: 24 additions & 5 deletions stripe-core/src/Web/Stripe/Subscription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ module Web.Stripe.Subscription
, cancelSubscription
, GetSubscriptions
, getSubscriptions
, GetSubscriptionsByCustomerId
, getSubscriptionsByCustomerId
-- * Types
, ApplicationFeePercent (..)
, AtPeriodEnd (..)
Expand Down Expand Up @@ -179,14 +181,13 @@ instance StripeHasParam CancelSubscription AtPeriodEnd
type instance StripeReturn CancelSubscription = Subscription

------------------------------------------------------------------------------
-- | Retrieve active `Subscription`s
-- | Retrieve all active `Subscription`s
getSubscriptions
:: CustomerId -- ^ The `CustomerId` of the `Subscription`s to retrieve
-> StripeRequest GetSubscriptions
:: StripeRequest GetSubscriptions
getSubscriptions
customerid = request
= request
where request = mkStripeRequest GET url params
url = "customers" </> getCustomerId customerid </> "subscriptions"
url = "subscriptions"
params = []

data GetSubscriptions
Expand All @@ -195,3 +196,21 @@ instance StripeHasParam GetSubscriptions ExpandParams
instance StripeHasParam GetSubscriptions (EndingBefore SubscriptionId)
instance StripeHasParam GetSubscriptions Limit
instance StripeHasParam GetSubscriptions (StartingAfter SubscriptionId)

------------------------------------------------------------------------------
-- | Retrieve a customer's `Subscription`s
getSubscriptionsByCustomerId
:: CustomerId
-> StripeRequest GetSubscriptionsByCustomerId
getSubscriptionsByCustomerId
customerid = request
where request = mkStripeRequest GET url params
url = "customers" </> getCustomerId customerid </> "subscriptions"
params = []

data GetSubscriptionsByCustomerId
type instance StripeReturn GetSubscriptionsByCustomerId = StripeList Subscription
instance StripeHasParam GetSubscriptionsByCustomerId ExpandParams
instance StripeHasParam GetSubscriptionsByCustomerId (EndingBefore SubscriptionId)
instance StripeHasParam GetSubscriptionsByCustomerId Limit
instance StripeHasParam GetSubscriptionsByCustomerId (StartingAfter SubscriptionId)
34 changes: 32 additions & 2 deletions stripe-tests/tests/Web/Stripe/Test/Subscription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ subscriptionTests stripe = do
Month
(PlanName "sample plan")
void $ createSubscription cid planid
sub <- getSubscriptions cid -&- ExpandParams ["data.customer"]
sub <- getSubscriptionsByCustomerId cid -&- ExpandParams ["data.customer"]
void $ deletePlan planid
void $ deleteCustomer cid
return sub
Expand All @@ -87,7 +87,37 @@ subscriptionTests stripe = do
Month
(PlanName "sample plan")
void $ createSubscription cid planid
sub <- getSubscriptions cid
sub <- getSubscriptionsByCustomerId cid
void $ deletePlan planid
void $ deleteCustomer cid
return sub
result `shouldSatisfy` isRight
it "Succesfully retrieves all Subscriptions expanded" $ do
planid <- makePlanId
result <- stripe $ do
Customer { customerId = cid } <- createCustomer
void $ createPlan planid
(Amount 0) -- free plan
USD
Month
(PlanName "sample plan")
void $ createSubscription cid planid
sub <- getSubscriptions -&- ExpandParams ["data.customer"]
void $ deletePlan planid
void $ deleteCustomer cid
return sub
result `shouldSatisfy` isRight
it "Succesfully retrieves all Subscriptions" $ do
planid <- makePlanId
result <- stripe $ do
Customer { customerId = cid } <- createCustomer
void $ createPlan planid
(Amount 0) -- free plan
USD
Month
(PlanName "sample plan")
void $ createSubscription cid planid
sub <- getSubscriptions
void $ deletePlan planid
void $ deleteCustomer cid
return sub
Expand Down

0 comments on commit d98f4b9

Please sign in to comment.