Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a card modal #169

Closed
mjallday opened this issue May 29, 2013 · 1 comment
Closed

Add a card modal #169

mjallday opened this issue May 29, 2013 · 1 comment
Assignees

Comments

@mjallday
Copy link
Contributor

NOTE: Design should follow existing modals until we implement #158

Original html:

<div class="modal hidden card" id="add-a-card">
    <form class="form-horizontal" method="post" action="${ uri(account.cards_uri) }">
    ${ csrf_token() | n }
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h3>add new card</h3>
    </div>
    <div class="modal-body">
    % for index, field in enumerate(this.create_a_card.items):
        <%forms:inline_row field="${ field }">
        ${ field.label }
        <div class="controls">
        % if index:
            ${ field(autocomplete='off') }
        % else:
            ${ field(autofocus='autofocus') }
        % endif
        </div>
        </%forms:inline_row>
    % endfor
    </div>
    <div class="modal-footer">
        <button class="btn btn-bal">create</button>
    </div>
    </form>
</div>

Original JavaScript

function validateAccountCreateForm(e) {

    var $form = $(this);
    var accountType = $('#type-account_type').val();

    if (accountType.indexOf('buyer') === -1 || $('#cct-card_uri').val()) {
        //  we need to tokenize credit card before we submit the rest which
        //  means we need to validate the rest of the buyer's details first
        return;
    }

    e.preventDefault();

    $form.find('#buyer-information').find('.row').removeClass('error');

    var cardData = {
        name:$form.find('#cc-card_name').val(),
        card_number:$form.find('#cc-card_number').val(),
        expiration_month:$form.find('#cc-expiration_month').val(),
        expiration_year:$form.find('#cc-expiration_year').val(),
        security_code:$form.find('#cc-security_code').val(),
        phone_number:$form.find('#cc-phone_number').val()
    };

    if (!cardData.phone_number) {
        delete cardData.phone_number;
    }

    if (!cardData.name || cardData.name.length < 2) {
        $form.find('#cc-card_name').closest('.row').addClass('error');
    }

    if (!balanced.card.isCardNumberValid(cardData.card_number)) {
        $form.find('#cc-card_number').closest('.row').addClass('error');
    }
    if (!balanced.card.isExpirationValid(cardData.expiration_month, cardData.expiration_year)) {
        $form.find('#cc-expiration_month').closest('.row').addClass('error');
    }
    if (!balanced.card.isSecurityCodeValid(cardData.card_number, cardData.security_code)) {
        $form.find('#cc-security_code').closest('.row').addClass('error');
    }

    if ($form.find('#buyer-information').find('.error').length) {
        //  errors!
        return;
    }
    formUtils.disable($form);

    balanced.card.create(cardData, onAccountCardTokenized);
}
@mjallday
Copy link
Contributor Author

This should tokenize the card via balanced.js and associate to an existing customer

@mjallday mjallday closed this as completed Jun 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants