Skip to content

Commit cf8bed0

Browse files
committed
console: Get and render tax info for customer. #376
* Define additional fields and types. * Render them. * Factor Stripe API array wrapper out into separate type ArrayWrapper.
1 parent 4b5c2ed commit cf8bed0

File tree

3 files changed

+52
-36
lines changed

3 files changed

+52
-36
lines changed

console/src/Statebox/Console.purs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,19 @@ customerHtml c =
133133
, tr [] [ th [] [ text "balance" ]
134134
, td [] [ text $ c.currency <> " " <> show c.balance <> " cents" ]
135135
]
136+
, tr [] [ th [] [ text "tax" ]
137+
, td [] [ taxIdsHtml c.tax_ids ]
138+
]
139+
]
140+
141+
taxIdsHtml :: m. MonadAff m => Stripe.ArrayWrapper Stripe.TaxIdData -> ComponentHTML Action ChildSlots m
142+
taxIdsHtml x =
143+
table [] (taxIdDataHtml <$> x.data)
144+
145+
taxIdDataHtml :: m. MonadAff m => Stripe.TaxIdData -> ComponentHTML Action ChildSlots m
146+
taxIdDataHtml x =
147+
tr [] [ td [] [ text x.value ]
148+
, td [] [ text x.type ]
136149
]
137150

138151
--------------------------------------------------------------------------------

console/src/Statebox/Console/DAO.purs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@ mkUrl suffix = "http://localhost" <> suffix
1919

2020
--------------------------------------------------------------------------------
2121

22-
type InvoicesResponse =
23-
{ object :: String
24-
, "data" :: Array Stripe.Invoice
25-
}
26-
27-
listInvoices :: Aff (Affjax.Error \/ String \/ InvoicesResponse)
22+
listInvoices :: Aff (Affjax.Error \/ String \/ Stripe.ArrayWrapper Stripe.Invoice)
2823
listInvoices = listInvoices' # map (map (_.body >>> spy "invoices body dump" >>> decodeJson))
2924

3025
listInvoices' :: Aff (Affjax.Error \/ Response Json)
@@ -48,14 +43,7 @@ fetchCustomer' =
4843

4944
--------------------------------------------------------------------------------
5045

51-
type PaymentMethodsResponse =
52-
{ object :: Stripe.ObjectTag
53-
, "data" :: Array Stripe.PaymentMethod
54-
, has_more :: Boolean
55-
, url :: Stripe.URLSuffix
56-
}
57-
58-
listPaymentMethods :: Aff (Affjax.Error \/ String \/ PaymentMethodsResponse)
46+
listPaymentMethods :: Aff (Affjax.Error \/ String \/ Stripe.ArrayWrapper Stripe.PaymentMethod)
5947
listPaymentMethods = listPaymentMethods' # map (map (_.body >>> spy "paymentMethods dump" >>> decodeJson))
6048

6149
listPaymentMethods' :: Aff (Affjax.Error \/ Response Json)

console/src/Stripe.purs

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ module Stripe where
22

33
import Data.Maybe (Maybe)
44

5-
6-
-- | Stripe populates this with things like `"customer"`, `"object"`, `"list"` and so on.
7-
type ObjectTag = String
8-
9-
--------------------------------------------------------------------------------
10-
115
-- | https://stripe.com/docs/api/customers/object
126
type Customer =
137
{ object :: ObjectTag
@@ -20,8 +14,10 @@ type Customer =
2014
, currency :: Currency
2115
, invoice_prefix :: String
2216
, invoice_settings :: InvoiceSettings
23-
, subscriptions :: SubscriptionsInfo
17+
, subscriptions :: { | ArrayWrapperRow Subscription ( total_count :: Int ) }
2418
, delinquent :: Boolean
19+
, tax_ids :: ArrayWrapper TaxIdData
20+
, tax_exempt :: TaxExemptType
2521
}
2622

2723
type CustomerId = String
@@ -94,16 +90,6 @@ type InvoiceId = String
9490

9591
--------------------------------------------------------------------------------
9692

97-
type SubscriptionsInfo =
98-
{ object :: ObjectTag
99-
, has_more :: Boolean
100-
, total_count :: Int
101-
, url :: URLSuffix -- ^ e.g. "/v1/customers/:customerId:/subscriptions"
102-
, data :: Array Subscription
103-
}
104-
105-
--------------------------------------------------------------------------------
106-
10793
type Subscription =
10894
{ id :: SubscriptionId
10995
, customer :: CustomerId
@@ -112,11 +98,7 @@ type Subscription =
11298
, current_period_start :: Timestamp
11399
, current_period_end :: Timestamp
114100
, latest_invoice :: Maybe InvoiceId
115-
, items :: { object :: ObjectTag
116-
, data :: Array SubscriptionItem
117-
, url :: URLSuffix
118-
, has_more :: Boolean
119-
}
101+
, items :: ArrayWrapper SubscriptionItem
120102
}
121103

122104
type SubscriptionId = String
@@ -161,6 +143,23 @@ type ProductId = String
161143

162144
--------------------------------------------------------------------------------
163145

146+
type TaxIdData =
147+
{ type :: TaxIdType
148+
, value :: String
149+
}
150+
151+
-- | One of `"eu_vat"` | `"nz_gst"` | `"au_abn"` | `"in_gst"` | `"no_vat"` |
152+
-- | `"za_vat"` | `"ch_vat"` | `"mx_rfc"` | `"sg_uen"` | `"ru_inn"` |
153+
-- | `"ca_bn"` | `"hk_br"` | `"es_cif"` | `"tw_vat"` | `"th_vat"` |
154+
-- | `"jp_cn"` | `"li_uid"` | `"my_itn"` | `"us_ein"` | `"kr_brn"` |
155+
-- | `"ca_qst"` | `"my_sst"`.
156+
type TaxIdType = String
157+
158+
-- | One of `"none"`, `"exempt"`, or `"reverse`".
159+
type TaxExemptType = String
160+
161+
--------------------------------------------------------------------------------
162+
164163
type Address =
165164
{ postal_code :: Maybe PostalCode
166165
, city :: Maybe String
@@ -203,3 +202,19 @@ type MonthNr = Int
203202

204203
-- | Year, starting from zero, i.e. the year 2020 is represented as `2020`.
205204
type Year = Int
205+
206+
--------------------------------------------------------------------------------
207+
208+
-- | Stripe populates this with things like `"customer"`, `"object"`,
209+
-- | `"list"` and so on.
210+
type ObjectTag = String
211+
212+
type ArrayWrapperRow a r =
213+
( object :: ObjectTag
214+
, data :: Array a
215+
, has_more :: Boolean
216+
, url :: URLSuffix
217+
| r
218+
)
219+
220+
type ArrayWrapper a = { | ArrayWrapperRow a () }

0 commit comments

Comments
 (0)