Skip to content

Commit 8734e05

Browse files
committed
stripe invoices api
1 parent f839fa4 commit 8734e05

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

nix/shell.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ in
1919
pkgs.gleam
2020
pkgs.erlang
2121
pkgs.elixir
22+
pkgs.libwebp
2223
newpkgs.litecli
2324
misc.nix-bundle
2425
bak.bak-status

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ module Stripe.Client
6565
createCheckoutSession,
6666
retrieveCheckoutSession,
6767

68+
-- * Invoices
69+
InvoiceId (..),
70+
InvoiceStatus (..),
71+
Invoice (..),
72+
retrieveInvoice,
73+
cancelInvoice,
74+
listInvoices,
75+
6876
-- * Events
6977
retrieveEvent,
7078
listEvents,
@@ -157,6 +165,10 @@ EP (retrieveSubscription, SubscriptionId, Subscription)
157165
EP (cancelSubscription, SubscriptionId, Subscription)
158166
EP (listSubscriptions, Maybe CustomerId, (StripeList Subscription))
159167

168+
EP (retrieveInvoice, InvoiceId, Invoice)
169+
EP (cancelInvoice, InvoiceId, Invoice)
170+
EP (listInvoices, Maybe CustomerId, (StripeList Invoice))
171+
160172
EP (createCheckoutSession, CheckoutSessionCreate, CheckoutSession)
161173
EP (retrieveCheckoutSession, CheckoutSessionId, CheckoutSession)
162174

@@ -173,6 +185,10 @@ EP (listEvents, Maybe EventId, (StripeList Event))
173185
:<|> cancelSubscription'
174186
:<|> listSubscriptions'
175187
)
188+
:<|> ( retrieveInvoice'
189+
:<|> cancelInvoice'
190+
:<|> listInvoices'
191+
)
176192
:<|> (createCheckoutSession' :<|> retrieveCheckoutSession')
177193
:<|> (createCustomerPortal')
178194
:<|> (retrieveEvent' :<|> listEvents') =

pub/stripe-servant/src/Stripe/Api.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type StripeApiInternal =
1515
:<|> "products" :> ProductApi
1616
:<|> "prices" :> PriceApi
1717
:<|> "subscriptions" :> SubscriptionApi
18+
:<|> "invoices" :> InvoicesApi
1819
:<|> "checkout" :> "sessions" :> CheckoutApi
1920
:<|> "billing_portal" :> "sessions" :> CustomerPortalApi
2021
:<|> "events" :> EventApi
@@ -61,6 +62,17 @@ type SubscriptionApi =
6162
:> QueryParam "customer" CustomerId
6263
:> Get '[JSON] (StripeList Subscription)
6364

65+
type InvoicesApi =
66+
StripeAuth
67+
:> Capture ":invoice_id" InvoiceId
68+
:> Get '[JSON] Invoice
69+
:<|> StripeAuth
70+
:> Capture ":invoice_id" InvoiceId
71+
:> Delete '[JSON] Invoice
72+
:<|> StripeAuth
73+
:> QueryParam "customer" CustomerId
74+
:> Get '[JSON] (StripeList Invoice)
75+
6476
type CheckoutApi =
6577
StripeAuth
6678
:> ReqBody '[FormUrlEncoded] CheckoutSessionCreate

pub/stripe-servant/src/Stripe/Resources.hs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ module Stripe.Resources
4545
CheckoutSessionCreate (..),
4646
CheckoutSessionCreateLineItem (..),
4747

48+
-- * Invoices
49+
InvoiceId (..),
50+
InvoiceStatus (..),
51+
Invoice (..),
52+
4853
-- * Events
4954
EventId (..),
5055
Event (..),
@@ -314,6 +319,30 @@ data CustomerPortalCreate = CustomerPortalCreate
314319
}
315320
deriving (Eq, Ord, Show, Read, Data, Generic)
316321

322+
newtype InvoiceId = InvoiceId
323+
{ unInvoiceId :: T.Text
324+
}
325+
deriving (Eq, Ord, Show, Read, Data, Generic, ToJSON, FromJSON, ToHttpApiData)
326+
327+
data InvoiceStatus
328+
= -- Tmp
329+
InvDraft
330+
| InvOpen
331+
| -- Fin
332+
InvPaid
333+
| InvUncollectible
334+
| InvVoid
335+
deriving stock (Eq, Ord, Show, Read, Data, Generic, Enum, Bounded)
336+
337+
data Invoice = Invoice
338+
{ invId :: InvoiceId,
339+
invCustomer :: CustomerId,
340+
invAmountPaid :: Int,
341+
invCurrency :: T.Text,
342+
invStatus :: InvoiceStatus
343+
}
344+
deriving (Eq, Ord, Show, Read, Data, Generic)
345+
317346
$(deriveJSON (jsonOpts 2) ''StripeList)
318347
$(deriveJSON (jsonOpts 1) ''Customer)
319348
$(deriveJSON (jsonOpts 2) ''EventData)
@@ -327,6 +356,8 @@ $(deriveJSON (jsonOpts 2) ''SubscriptionItem)
327356
$(deriveJSON (jsonOpts 2) ''SubscriptionStatus)
328357
$(deriveJSON (jsonOpts 1) ''Subscription)
329358
$(deriveJSON (jsonOpts 2) ''CustomerPortal)
359+
$(deriveJSON (jsonOpts 3) ''InvoiceStatus)
360+
$(deriveJSON (jsonOpts 3) ''Invoice)
330361

331362
instance ToForm CustomerCreate where
332363
toForm = genericToForm (formOptions 2)

0 commit comments

Comments
 (0)