<commit_before>import traceback

import stripe
from aspen import json, log, Response
from gittip import billing

# ========================================================================== ^L

if not user.ANON:
    stripe_customer_id = user.stripe_customer_id
    if not stripe_customer_id:
        status = "missing"
    else:
        working = not bool(user.last_bill_result)
        status = "working" if working else "failing"

    try:
        customer = billing.Customer(stripe_customer_id)
    except:  # stripe is unavailable? could be a bad stripe_customer_id?
        log(traceback.format_exc())
        stripe_down = True
    else:
        assert stripe_customer_id == customer['id']
        stripe_down = False

    username = user.id
# ========================================================================== ^L
{% extends templates/base.html %}


{% block body %}
{% if user.ANON %}
<div id="their-voice">

<h2 class="first">Credit Card</h2>

<p>Sign in <a href="{{ github_oauth_url('/credit-card.html') }}">with
GitHub</a>, and then you&rsquo;ll be able to add or change your credit card.
Thanks! :-)</p>

</div>

{% else %}
<script>
    $(document).ready(function()
    {
        Gittip.initPayment("{{ stripe.publishable_api_key }}", "{{ user.id }}");
    });
</script>
<style>
    #feedback {
        position: absolute;
        width: 220px;
        left: 360px;
    }
    #feedback H3 {
        margin-top: 0;
    }
    #feedback .details P {
        font-size: 9pt;
        line-height: 12pt;
        margin: 0;
        padding: 0 0 0 1em;
        text-indent: -1em;
    }
    FORM {
        width: 300px;
    }
    {% if not stripe_customer_id %}
    #delete {
        display: none;
    }
    {% end %}
</style>
<div id="their-voice">

    <h2 class="first">You are <a href="/{{ user.id }}/">{{ user.id }}</a>.</h2>
    <h2>Your <b>credit card</b> is <span id="status">{{ status }}</span>.</h2>
    
    {% if stripe_down %}

    <p>We had a problem contacting <a href="https://stripe.com/">our payment
    processor</a>. Could I ask if you&rsquo;d be willing to try again
    later? Thanksorry. :-(</p>

    {% else %}

    <p>When you don&rsquo;t have enough in your Gittip account to cover your
    tips, we {% if stripe_customer_id %}will{% else %}can{% end %} pull money
    in using {% if stripe_customer_id %}this{% else %}a{% end %} credit card.
    If your credit card is missing or fails then your tips won&rsquo;t go
    through for that week.<p>

    {% if stripe_customer_id %}
    <p>Your current card is <b>{{ customer['last4'] }}</b>.</p>

    <h2>Change your card on file.</h2>
    {% end %}

    <form id="payment">
        <div id="feedback">{% if user.last_bill_result %}
        <h3><span>Darn it all!</span></h3>
        <div class="details">
        <p>{{ json.loads(user.last_bill_result)['error']['message'] }}</p>
        </div>
        {% end %}</div>


        <h3>Required</h3>

        <div class="float card_number">
            <label for="card_number">Credit Card Number</label>
            <input id="card_number" />
        </div>

        <div class="float expiry not-first">
            <label for="expiry">Expiration</label>
            <input id="expiry" />
        </div>

        <div class="float cvv not-first">
            <label for="cvv">CVV</label>
            <input id="cvv" />
        </div>

        <div class="clear"></div>


        <h3>Optional</h3>

        <label for="name">Full Name on Card</label>
        <input id="name" value="{{ customer['name'] }}" />

        <div class="clear"></div>

        <label for="address_1">Address 1</label>
        <input id="address_1" value="{{ customer['address_line1'] }}" />

        <label for="address_2">Address 2</label>
        <input id="address_2" value="{{ customer['address_line2'] }}" />


        <div class="half left">
            <label for="state">State or Province</label>
            <input id="state" value="{{ customer['state'] }}" />
        </div>

        <div class="half right">
            <label for="zip">ZIP or Postal Code</label>
            <input id="zip" value="{{ customer['zip'] }}" />
        </div>

        <div class="clear"></div>

        <div class="full">
            <img src="/assets/{{ __version__ }}/cards.png" />
            <button class="selected" id="save"
            type="submit">Save</button>
        </div>
        {% end %}
    </form>

    <div id="delete"> 
    <h2>Delete credit card.</h2>

    <p>Your credit card details will immediately be completely purged from
    Gittip.</p>

    <form action="credit-card.json">
        <input type="hidden" name="action" value="delete"> 
        <button>Delete my credit card</button>
    </form>
    </div>

</div>
{% end %}
{% end %}
<commit_msg>Fix bug where state and ZIP weren't filled in (#58)<commit_after>import traceback

import stripe
from aspen import json, log, Response
from gittip import billing

# ========================================================================== ^L

if not user.ANON:
    stripe_customer_id = user.stripe_customer_id
    if not stripe_customer_id:
        status = "missing"
    else:
        working = not bool(user.last_bill_result)
        status = "working" if working else "failing"

    try:
        customer = billing.Customer(stripe_customer_id)
    except:  # stripe is unavailable? could be a bad stripe_customer_id?
        log(traceback.format_exc())
        stripe_down = True
    else:
        assert stripe_customer_id == customer['id']
        stripe_down = False

    username = user.id
# ========================================================================== ^L
{% extends templates/base.html %}


{% block body %}
{% if user.ANON %}
<div id="their-voice">

<h2 class="first">Credit Card</h2>

<p>Sign in <a href="{{ github_oauth_url('/credit-card.html') }}">with
GitHub</a>, and then you&rsquo;ll be able to add or change your credit card.
Thanks! :-)</p>

</div>

{% else %}
<script>
    $(document).ready(function()
    {
        Gittip.initPayment("{{ stripe.publishable_api_key }}", "{{ user.id }}");
    });
</script>
<style>
    #feedback {
        position: absolute;
        width: 220px;
        left: 360px;
    }
    #feedback H3 {
        margin-top: 0;
    }
    #feedback .details P {
        font-size: 9pt;
        line-height: 12pt;
        margin: 0;
        padding: 0 0 0 1em;
        text-indent: -1em;
    }
    FORM {
        width: 300px;
    }
    {% if not stripe_customer_id %}
    #delete {
        display: none;
    }
    {% end %}
</style>
<div id="their-voice">

    <h2 class="first">You are <a href="/{{ user.id }}/">{{ user.id }}</a>.</h2>
    <h2>Your <b>credit card</b> is <span id="status">{{ status }}</span>.</h2>
    
    {% if stripe_down %}

    <p>We had a problem contacting <a href="https://stripe.com/">our payment
    processor</a>. Could I ask if you&rsquo;d be willing to try again
    later? Thanksorry. :-(</p>

    {% else %}

    <p>When you don&rsquo;t have enough in your Gittip account to cover your
    tips, we {% if stripe_customer_id %}will{% else %}can{% end %} pull money
    in using {% if stripe_customer_id %}this{% else %}a{% end %} credit card.
    If your credit card is missing or fails then your tips won&rsquo;t go
    through for that week.<p>

    {% if stripe_customer_id %}
    <p>Your current card is <b>{{ customer['last4'] }}</b>.</p>

    <h2>Change your card on file.</h2>
    {% end %}

    <form id="payment">
        <div id="feedback">{% if user.last_bill_result %}
        <h3><span>Darn it all!</span></h3>
        <div class="details">
        <p>{{ json.loads(user.last_bill_result)['error']['message'] }}</p>
        </div>
        {% end %}</div>


        <h3>Required</h3>

        <div class="float card_number">
            <label for="card_number">Credit Card Number</label>
            <input id="card_number" />
        </div>

        <div class="float expiry not-first">
            <label for="expiry">Expiration</label>
            <input id="expiry" />
        </div>

        <div class="float cvv not-first">
            <label for="cvv">CVV</label>
            <input id="cvv" />
        </div>

        <div class="clear"></div>


        <h3>Optional</h3>

        <label for="name">Full Name on Card</label>
        <input id="name" value="{{ customer['name'] }}" />

        <div class="clear"></div>

        <label for="address_1">Address 1</label>
        <input id="address_1" value="{{ customer['address_line1'] }}" />

        <label for="address_2">Address 2</label>
        <input id="address_2" value="{{ customer['address_line2'] }}" />


        <div class="half left">
            <label for="state">State or Province</label>
            <input id="state" value="{{ customer['address_state'] }}" />
        </div>

        <div class="half right">
            <label for="zip">ZIP or Postal Code</label>
            <input id="zip" value="{{ customer['address_zip'] }}" />
        </div>

        <div class="clear"></div>

        <div class="full">
            <img src="/assets/{{ __version__ }}/cards.png" />
            <button class="selected" id="save"
            type="submit">Save</button>
        </div>
        {% end %}
    </form>

    <div id="delete"> 
    <h2>Delete credit card.</h2>

    <p>Your credit card details will immediately be completely purged from
    Gittip.</p>

    <form action="credit-card.json">
        <input type="hidden" name="action" value="delete"> 
        <button>Delete my credit card</button>
    </form>
    </div>

</div>
{% end %}
{% end %}

{'fraction_non_alphanumeric': 0.192628071636818, 'fraction_numerical': 0.009579341940857976, 'mean_word_length': 2.45255212077642, 'pattern_counts': {'":': 0, '<': 219, '<?xml version=': 0, '>': 219, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3266530', 'n_tokens_mistral': 3255, 'n_tokens_neox': 2950, 'n_words': 789}