@@ -11,7 +11,7 @@ import Effect.Aff.Class (class MonadAff)
1111import Effect.Console (log )
1212import Halogen as H
1313import 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 )
1515import Halogen.Query.HalogenM (HalogenM )
1616
1717import 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
153219spyM :: ∀ m a . Applicative m => String -> a -> m Unit
0 commit comments