Skip to content

Commit 4bd5acc

Browse files
committed
Merge branch 'master' of github.com-functora:functora/functora.github.io
2 parents 000ad81 + e0041bf commit 4bd5acc

File tree

5 files changed

+331
-226
lines changed

5 files changed

+331
-226
lines changed

nix/tools.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,5 @@ in [
6868
styleTest
6969
prettier
7070
pkgs.alejandra
71+
pkgs.haskellPackages.cpphs
7172
]

pub/stripe-hs/src/Stripe/Client.hs

Lines changed: 96 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,105 @@
1-
{-# OPTIONS_GHC -cpp -pgmPcpphs -optP--cpp #-}
21
{-# LANGUAGE CPP #-}
2+
{-# OPTIONS_GHC -cpp -pgmPcpphs -optP--cpp #-}
3+
34
module Stripe.Client
45
( -- * Basics
5-
ApiKey, StripeClient, makeStripeClient, ClientError(..)
6+
ApiKey,
7+
StripeClient,
8+
makeStripeClient,
9+
ClientError (..),
10+
611
-- * Helper types
7-
, TimeStamp(..), StripeList(..)
12+
TimeStamp (..),
13+
StripeList (..),
14+
815
-- * Customers
9-
, createCustomer, retrieveCustomer, updateCustomer, listCustomers
10-
, CustomerId(..), Customer(..), CustomerCreate(..), CustomerUpdate(..)
16+
createCustomer,
17+
retrieveCustomer,
18+
updateCustomer,
19+
listCustomers,
20+
CustomerId (..),
21+
Customer (..),
22+
CustomerCreate (..),
23+
CustomerUpdate (..),
24+
1125
-- * Product catalog
12-
, ProductId(..), PriceId(..), Product(..), Price(..), PriceRecurring(..)
13-
, ProductCreate(..), PriceCreate(..), PriceCreateRecurring(..)
14-
, createProduct, retrieveProduct
15-
, createPrice, retrievePrice, listPrices
26+
ProductId (..),
27+
PriceId (..),
28+
Product (..),
29+
Price (..),
30+
PriceRecurring (..),
31+
ProductCreate (..),
32+
PriceCreate (..),
33+
PriceCreateRecurring (..),
34+
createProduct,
35+
retrieveProduct,
36+
createPrice,
37+
retrievePrice,
38+
listPrices,
39+
1640
-- * Subscriptions
17-
, SubscriptionId(..), SubscriptionItemId(..), Subscription(..), SubscriptionItem(..), SubscriptionCreate(..), SubscriptionCreateItem(..)
18-
, createSubscription, retrieveSubscription, listSubscriptions
41+
SubscriptionId (..),
42+
SubscriptionItemId (..),
43+
SubscriptionStatus (..),
44+
Subscription (..),
45+
SubscriptionItem (..),
46+
SubscriptionCreate (..),
47+
SubscriptionCreateItem (..),
48+
createSubscription,
49+
retrieveSubscription,
50+
listSubscriptions,
51+
1952
-- * Customer Portal
20-
, CustomerPortalId(..), CustomerPortal(..), CustomerPortalCreate(..)
21-
, createCustomerPortal
53+
CustomerPortalId (..),
54+
CustomerPortal (..),
55+
CustomerPortalCreate (..),
56+
createCustomerPortal,
57+
2258
-- * Checkout
23-
, CheckoutSessionId(..), CheckoutSession(..), CheckoutSessionCreate(..), CheckoutSessionCreateLineItem(..)
24-
, createCheckoutSession, retrieveCheckoutSession
59+
CheckoutSessionId (..),
60+
CheckoutSessionStatus (..),
61+
CheckoutSession (..),
62+
CheckoutSessionCreate (..),
63+
CheckoutSessionCreateLineItem (..),
64+
createCheckoutSession,
65+
retrieveCheckoutSession,
66+
2567
-- * Events
26-
, retrieveEvent, listEvents
27-
, EventId(..), Event(..), EventData(..)
68+
retrieveEvent,
69+
listEvents,
70+
EventId (..),
71+
Event (..),
72+
EventData (..),
2873
)
2974
where
3075

31-
import Stripe.Api
32-
import Stripe.Resources
33-
import Stripe.Client.Internal.Helpers
34-
3576
import Data.Proxy
36-
import Servant.API
37-
import Servant.Client
38-
import Network.HTTP.Client (Manager)
3977
import qualified Data.Text as T
4078
import qualified Data.Text.Encoding as T
79+
import Network.HTTP.Client (Manager)
80+
import Servant.API
81+
import Servant.Client
82+
import Stripe.Api
83+
import Stripe.Client.Internal.Helpers
84+
import Stripe.Resources
4185

4286
-- | Your Stripe API key. Can be obtained from the Stripe dashboard. Format: @sk_<mode>_<redacted>@
4387
type ApiKey = T.Text
4488

4589
-- | Holds a 'Manager' and your API key.
46-
data StripeClient
47-
= StripeClient
48-
{ scBasicAuthData :: BasicAuthData
49-
, scManager :: Manager
50-
, scMaxRetries :: Int
90+
data StripeClient = StripeClient
91+
{ scBasicAuthData :: BasicAuthData,
92+
scManager :: Manager,
93+
scMaxRetries :: Int
5194
}
5295

5396
-- | Construct a 'StripeClient'. Note that the passed 'Manager' must support https (e.g. via @http-client-tls@)
5497
makeStripeClient ::
55-
ApiKey
56-
-> Manager
57-
-> Int
58-
-- ^ Number of automatic retries the library should attempt. See also <https://stripe.com/docs/error-handling#safely-retrying-requests-with-idempotency Stripe Error Handling>
59-
-> StripeClient
98+
ApiKey ->
99+
Manager ->
100+
-- | Number of automatic retries the library should attempt. See also <https://stripe.com/docs/error-handling#safely-retrying-requests-with-idempotency Stripe Error Handling>
101+
Int ->
102+
StripeClient
60103
makeStripeClient k = StripeClient (BasicAuthData (T.encodeUtf8 k) "")
61104

62105
api :: Proxy StripeApi
@@ -80,35 +123,35 @@ stripeBaseUrl = BaseUrl Https "api.stripe.com" 443 ""
80123
N :: StripeClient -> ARG -> ARG2 -> ARG3 -> IO (Either ClientError R);\
81124
N sc a b c = runRequest (scMaxRetries sc) 0 $ runClientM (N##' (scBasicAuthData sc) a b c) (mkClientEnv (scManager sc) stripeBaseUrl)
82125

83-
EP(createCustomer, CustomerCreate, Customer)
84-
EP(retrieveCustomer, CustomerId, Customer)
85-
EP2(updateCustomer, CustomerId, CustomerUpdate, Customer)
86-
EP(listCustomers, Maybe CustomerId, (StripeList Customer))
126+
EP (createCustomer, CustomerCreate, Customer)
127+
EP (retrieveCustomer, CustomerId, Customer)
128+
EP2 (updateCustomer, CustomerId, CustomerUpdate, Customer)
129+
EP (listCustomers, Maybe CustomerId, (StripeList Customer))
87130

88-
EP(createProduct, ProductCreate, Product)
89-
EP(retrieveProduct, ProductId, Product)
131+
EP (createProduct, ProductCreate, Product)
132+
EP (retrieveProduct, ProductId, Product)
90133

91-
EP(createPrice, PriceCreate, Price)
92-
EP(retrievePrice, PriceId, Price)
93-
EP(listPrices, Maybe T.Text, (StripeList Price))
134+
EP (createPrice, PriceCreate, Price)
135+
EP (retrievePrice, PriceId, Price)
136+
EP (listPrices, Maybe T.Text, (StripeList Price))
94137

95-
EP(createSubscription, SubscriptionCreate, Subscription)
96-
EP(retrieveSubscription, SubscriptionId, Subscription)
97-
EP(listSubscriptions, Maybe CustomerId, (StripeList Subscription))
138+
EP (createSubscription, SubscriptionCreate, Subscription)
139+
EP (retrieveSubscription, SubscriptionId, Subscription)
140+
EP (listSubscriptions, Maybe CustomerId, (StripeList Subscription))
98141

99-
EP(createCheckoutSession, CheckoutSessionCreate, CheckoutSession)
100-
EP(retrieveCheckoutSession, CheckoutSessionId, CheckoutSession)
142+
EP (createCheckoutSession, CheckoutSessionCreate, CheckoutSession)
143+
EP (retrieveCheckoutSession, CheckoutSessionId, CheckoutSession)
101144

102-
EP(createCustomerPortal, CustomerPortalCreate, CustomerPortal)
145+
EP (createCustomerPortal, CustomerPortalCreate, CustomerPortal)
103146

104-
EP(retrieveEvent, EventId, Event)
105-
EP(listEvents, Maybe EventId, (StripeList Event))
147+
EP (retrieveEvent, EventId, Event)
148+
EP (listEvents, Maybe EventId, (StripeList Event))
106149

107150
(createCustomer' :<|> retrieveCustomer' :<|> updateCustomer' :<|> listCustomers')
108151
:<|> (createProduct' :<|> retrieveProduct')
109152
:<|> (createPrice' :<|> retrievePrice' :<|> listPrices')
110153
:<|> (createSubscription' :<|> retrieveSubscription' :<|> listSubscriptions')
111154
:<|> (createCheckoutSession' :<|> retrieveCheckoutSession')
112155
:<|> (createCustomerPortal')
113-
:<|> (retrieveEvent' :<|> listEvents')
114-
= client api
156+
:<|> (retrieveEvent' :<|> listEvents') =
157+
client api

0 commit comments

Comments
 (0)