 
     render_payment_methods: ->
 
+    render_error: ->
+        if @state.error
+            <ErrorDisplay error={@state.error} onClose={=>@setState(error:'')} />
+
     render: ->
         <Panel header={@render_header()}>
-            {@render_add_payment_method() if @state.adding_payment_method}
+            {@render_error()}
+            {@render_add_payment_method() if @state.state in ['add_new', 'submit']}
             {@render_payment_methods()}
         </Panel>
 

            </Col>
            <Col xs=8>
                <ButtonToolbar style={float: "right"}>
                    <Button onClick={=>@setState(adding_payment_method: false, new_payment_info:{})}>Cancel</Button>
                    <Button onClick={@submit_credit_card} bsStyle='primary'>Add Credit Card</Button>
                </ButtonToolbar>
            </Col>

        flux  : rtypes.object.isRequired

    getInitialState: ->
        new_payment_info : {}
        state : 'view'   #  'delete' <--> 'view' <--> 'add_new' <--> 'submit_new'
        error : ''

    submit_credit_card: ->
        response = undefined
        async.series([
            (cb) =>  # see https://stripe.com/docs/stripe.js#createToken
                Stripe.card.createToken @state.new_payment_info, (status, _response) =>
                    if status != 200
                        cb(_response.error.message)
                    else
                        response = _response
                        cb()
            (cb) =>
                salvus_client.stripe_create_source
                    token : response.id
                    cb    : cb
        ], (err) =>
            if err
                @setState(error: err, state:'add_new')
            else
                @setState(error:'', state:'view')
        )


    add_payment_method: ->
        @setState(state:'add_new', new_payment_info:{name : @props.flux.getStore('account').get_fullname()})

    render_payment_method_field: (field, control) ->
        if field == 'State' and @state.new_payment_info.country != "United States"
            return
        <Row key={field}>
            <Col xs=4>
                {field}
