Skip to content

Commit df1e188

Browse files
committed
console: More work on Stripe Customer, Card, and BillingDetails. #376
1 parent cf8bed0 commit df1e188

File tree

2 files changed

+89
-15
lines changed

2 files changed

+89
-15
lines changed

console/src/Statebox/Console.purs

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Effect.Aff.Class (class MonadAff)
1111
import Effect.Console (log)
1212
import Halogen as H
1313
import Halogen (ComponentHTML)
14-
import Halogen.HTML (HTML, p, text, div, ul, li, h2, table, tr, th, td)
14+
import Halogen.HTML (HTML, p, text, br, div, ul, li, h2, h3, table, tr, th, td)
1515
import Halogen.Query.HalogenM (HalogenM)
1616

1717
import Statebox.Console.DAO as DAO
@@ -100,6 +100,8 @@ render state =
100100
[ p [] [ text $ if state.status == Ok then "" else "status: " <> show state.status ]
101101
, h2 [] [ text "Customer" ]
102102
, div [] (maybe [] (pure <<< customerHtml) state.customer)
103+
, h3 [] [ text "Customer's payment methods" ]
104+
, div [] (state.paymentMethods <#> paymentMethodHtml)
103105
, h2 [] [ text "Invoices" ]
104106
, div []
105107
(state.accounts <#> \account -> table []
@@ -122,14 +124,17 @@ customerHtml c =
122124
, td [] [ text $ fold c.name ]
123125
]
124126
, tr [] [ th [] [ text "email" ]
125-
, td [] [ text $ c.email ]
127+
, td [] [ text $ fold c.email ]
126128
]
127129
, tr [] [ th [] [ text "phone" ]
128130
, td [] [ text $ fold c.phone ]
129131
]
130132
, tr [] [ th [] [ text "description" ]
131133
, td [] [ text $ fold c.description ]
132134
]
135+
, tr [] [ th [] [ text "address" ]
136+
, td [] [ maybe (text "no address") addressHtml c.address ]
137+
]
133138
, tr [] [ th [] [ text "balance" ]
134139
, td [] [ text $ c.currency <> " " <> show c.balance <> " cents" ]
135140
]
@@ -148,6 +153,67 @@ taxIdDataHtml x =
148153
, td [] [ text x.type ]
149154
]
150155

156+
paymentMethodHtml :: m. MonadAff m => Stripe.PaymentMethod -> ComponentHTML Action ChildSlots m
157+
paymentMethodHtml pm =
158+
table []
159+
[ tr [] [ td [] [ text "type" ]
160+
, td [] [ text pm.type ]
161+
]
162+
, tr [] [ td [] [ text "card" ]
163+
, td [] [ maybe (text "no card") cardHtml pm.card ]
164+
]
165+
]
166+
167+
billingDetailsHtml :: m. MonadAff m => Stripe.BillingDetails -> ComponentHTML Action ChildSlots m
168+
billingDetailsHtml bd =
169+
table []
170+
[ tr [] [ th [] [ text "name" ]
171+
, td [] [ text $ fold bd.name ]
172+
]
173+
, tr [] [ th [] [ text "email" ]
174+
, td [] [ text $ fold bd.email ]
175+
]
176+
, tr [] [ th [] [ text "phone" ]
177+
, td [] [ text $ fold bd.phone ]
178+
]
179+
, tr [] [ th [] [ text "address" ]
180+
, td [] [ maybe (text "no address") addressHtml bd.address ]
181+
]
182+
]
183+
184+
addressHtml :: m. MonadAff m => Stripe.Address -> ComponentHTML Action ChildSlots m
185+
addressHtml a =
186+
table []
187+
[ tr [] [ th [] [ text "address" ]
188+
, td [] [ text $ fold a.line1, br [], text $ fold a.line2 ]
189+
]
190+
, tr [] [ th [] [ text "city" ]
191+
, td [] [ text $ fold a.city ]
192+
]
193+
, tr [] [ th [] [ text "postal code" ]
194+
, td [] [ text $ fold a.postal_code ]
195+
]
196+
, tr [] [ th [] [ text "state" ]
197+
, td [] [ text $ fold a.state ]
198+
]
199+
, tr [] [ th [] [ text "country" ]
200+
, td [] [ text $ fold a.country ]
201+
]
202+
]
203+
204+
cardHtml :: m. MonadAff m => Stripe.Card -> ComponentHTML Action ChildSlots m
205+
cardHtml c =
206+
text $ c.country <> " " <> c.brand <> " " <>
207+
formatCCNumber c <>
208+
" EXP " <> formatExpiryDate c <>
209+
" (" <> c.funding <> ")"
210+
where
211+
formatCCNumber :: Stripe.Card -> String
212+
formatCCNumber card = "**** **** **** " <> card.last4
213+
214+
formatExpiryDate :: Stripe.Card -> String
215+
formatExpiryDate card = show c.exp_month <> "/" <> show c.exp_year
216+
151217
--------------------------------------------------------------------------------
152218

153219
spyM :: m a. Applicative m => String -> a -> m Unit

console/src/Stripe.purs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ type Customer =
88
, id :: CustomerId
99
, name :: Maybe String
1010
, description :: Maybe String
11-
, email :: Email
11+
, email :: Maybe Email
1212
, phone :: Maybe String
13+
, address :: Maybe Address
1314
, balance :: Amount
1415
, currency :: Currency
1516
, invoice_prefix :: String
@@ -44,21 +45,25 @@ type PaymentMethodId = String
4445
type PaymentMethodType = String
4546

4647
type BillingDetails =
47-
{ name :: Maybe String
48-
, phone :: Maybe Phone
49-
, email :: Maybe Email
50-
, address :: Maybe Address
48+
{ name :: Maybe String
49+
, phone :: Maybe Phone
50+
, email :: Maybe Email
51+
, address :: Maybe Address
5152
}
5253

54+
type BillingDetailsId = String
55+
56+
-- | https://stripe.com/docs/api/cards
5357
type Card =
54-
{ fingerprint :: String
55-
, brand :: CardBrand
56-
, last4 :: String -- ^ last four digits of the card number.
57-
, exp_month :: MonthNr
58-
, exp_year :: Year
59-
, country :: Country
60-
, funding :: String
61-
}
58+
{ fingerprint :: String
59+
, brand :: CardBrand
60+
, last4 :: String -- ^ last four digits of the card number.
61+
, exp_month :: MonthNr
62+
, exp_year :: Year
63+
, country :: Country
64+
, funding :: String
65+
}
66+
6267

6368
-- | Uniquely identifies this particular card number. You can use this attribute to check whether two
6469
-- | customers who’ve signed up with you are using the same card number, for example.
@@ -70,6 +75,9 @@ type CardBrand = String
7075
-- | One of `"credit"` | `"debit"` | `"prepeaid"` | `"unknown"`.
7176
type Funding = String
7277

78+
-- | If a CVC was provided, results of the check: `"pass"` | `"fail"` | `"unavailable"` | `"unchecked"`.
79+
type CVCCheckType = String
80+
7381
--------------------------------------------------------------------------------
7482

7583
-- | https://stripe.com/docs/api/invoices/object

0 commit comments

Comments
 (0)