Skip to content

Commit 20e2cc3

Browse files
committed
console: Factor out common fields form Stripe data structures. #376
1 parent c14a37b commit 20e2cc3

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

console/src/Statebox/Console.purs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,22 @@ paymentMethodHtml pm =
170170
]
171171

172172
billingDetailsHtml :: m. MonadAff m => Stripe.BillingDetails -> ComponentHTML Action ChildSlots m
173-
billingDetailsHtml bd =
173+
billingDetailsHtml bd = nameAddressPhoneHtml bd
174+
175+
nameAddressPhoneHtml :: r m. MonadAff m => { | Stripe.NameAddressPhoneRow () } -> ComponentHTML Action ChildSlots m
176+
nameAddressPhoneHtml x =
174177
table []
175178
[ tr [] [ th [] [ text "name" ]
176-
, td [] [ text $ fold bd.name ]
179+
, td [] [ text $ fold x.name ]
177180
]
178181
, tr [] [ th [] [ text "email" ]
179-
, td [] [ text $ fold bd.email ]
182+
, td [] [ text $ fold x.email ]
180183
]
181184
, tr [] [ th [] [ text "phone" ]
182-
, td [] [ text $ fold bd.phone ]
185+
, td [] [ text $ fold x.phone ]
183186
]
184187
, tr [] [ th [] [ text "address" ]
185-
, td [] [ maybe (text "no address") addressHtml bd.address ]
188+
, td [] [ maybe (text "no address") addressHtml x.address ]
186189
]
187190
]
188191

console/src/Stripe.purs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ import Data.Maybe (Maybe)
66
type Customer =
77
{ object :: ObjectTag
88
, id :: CustomerId
9-
, name :: Maybe String
109
, description :: Maybe String
11-
, email :: Maybe Email
12-
, phone :: Maybe String
13-
, address :: Maybe Address
1410
, balance :: Amount
1511
, currency :: Currency
1612
, invoice_prefix :: String
@@ -19,6 +15,7 @@ type Customer =
1915
, delinquent :: Boolean
2016
, tax_ids :: ArrayWrapper TaxIdData
2117
, tax_exempt :: TaxExemptType
18+
| NameAddressPhoneRow ()
2219
}
2320

2421
type CustomerId = String
@@ -44,12 +41,7 @@ type PaymentMethodId = String
4441
-- | One of `"card"` | `"fpx"` | `"ideal"` | `"sepa_debit"`. See https://stripe.com/docs/api/payment_methods/object.
4542
type PaymentMethodType = String
4643

47-
type BillingDetails =
48-
{ name :: Maybe String
49-
, phone :: Maybe Phone
50-
, email :: Maybe Email
51-
, address :: Maybe Address
52-
}
44+
type BillingDetails = { | NameAddressPhoneRow () }
5345

5446
type BillingDetailsId = String
5547

@@ -168,6 +160,17 @@ type TaxExemptType = String
168160

169161
--------------------------------------------------------------------------------
170162

163+
-- TODO include or exclude 'name' field?
164+
type NameAddressPhoneRow r =
165+
( name :: Maybe String
166+
, phone :: Maybe Phone
167+
, email :: Maybe Email
168+
, address :: Maybe Address
169+
| r
170+
)
171+
172+
--------------------------------------------------------------------------------
173+
171174
type Address =
172175
{ postal_code :: Maybe PostalCode
173176
, city :: Maybe String

0 commit comments

Comments
 (0)