<commit_before><%= content_for :page_title, 'ACH Payment Example' %>
<div class="container">
  <div class="row text-center">
    <div class="col-md-12 topspace text-center">
      <h1 class="page-header">
        Enter your bank details
      </h1>
    </div>
  </div>
  <div class="row">
    <div class="col-md-6 col-md-offset-3">
      <%= render 'layouts/messages' %>
      <div class="alert alert-warning">
        <strong>Hint:</strong> Test routing and account numbers can be found <a href="https://stripe.com/docs/ach#testing-ach">in the ACH docs</a>.
      </div>
      <div class="panel panel-default">
        <div class="panel-body text-left">
          <form action="/banks" method="POST" id="bank-form">
            <%= hidden_field_tag :authenticity_token, form_authenticity_token %>
            <div class="errors"></div>
            <div class="row">
              <div class="col-md-8">
                <div class="form-group">
                  <label>Bank Country</label>
                  <select class="form-control input-lg" id="country" data-stripe="country">
                    <option value="US">United States</option>
                    <option value="AU">Australia</option>
                    <option value="AT">Austria</option>
                    <option value="BE">Belgium</option>
                    <option value="BR">Brazil</option>
                    <option value="CA">Canada</option>
                    <option value="DK">Denmark</option>
                    <option value="FI">Finland</option>
                    <option value="FR">France</option>
                    <option value="DE">Germany</option>
                    <option value="HK">Hong Kong</option>
                    <option value="IE">Ireland</option>
                    <option value="IT">Italy</option>
                    <option value="JP">Japan</option>
                    <option value="LU">Luxembourg</option>
                    <option value="MX">Mexico</option>
                    <option value="NZ">New Zealand</option>
                    <option value="NL">Netherlands</option>
                    <option value="NO">Norway</option>
                    <option value="PT">Portugal</option>
                    <option value="SG">Singapore</option>
                    <option value="ES">Spain</option>
                    <option value="SE">Sweden</option>
                    <option value="CH">Switzerland</option>
                  </select>
                </div>
              </div>
              <div class="col-md-4">
                <div class="form-group">
                  <label>Account Currency</label>
                  <select class="form-control input-lg" id="currency" data-stripe="currency">
                    <option value="usd">USD</option>
                    <option value="aud">AUD</option>
                    <option value="brl">BRL</option>
                    <option value="cad">CAD</option>
                    <option value="eur">EUR</option>
                    <option value="gbp">GBP</option>
                    <option value="hkd">HKD</option>
                    <option value="jpy">JPY</option>
                    <option value="mxn">MXN</option>
                    <option value="nzd">NZD</option>
                    <option value="sgd">SGD</option>
                  </select>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-md-6">
                <div class="form-group">
                  <label>Full Legal Name</label>
                  <input class="form-control input-lg account_holder_name" id="account_holder_name" type="text" data-stripe="account_holder_name" placeholder="<NAME>" autocomplete="off">
                </div>
              </div>
              <div class="col-md-6">
                <div class="form-group">
                  <label>Account Type</label>
                  <select class="form-control input-lg account_holder_type" id="account_holder_type" data-stripe="account_holder_type">
                    <option value="individual">Individual</option>
                    <option value="company">Company</option>
                  </select>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-md-6" id="routing_number_div">
                <div class="form-group">
                  <label id="routing_number_label">Routing Number</label>
                  <input class="form-control input-lg bank_account" id="routing_number" type="tel" size="12" data-stripe="routing_number" placeholder="111000025" autocomplete="off">
                </div>
              </div>
              <div class="col-md-6">
                <div class="form-group">
                  <label id="account_number_label">Account Number</label>
                  <input class="form-control input-lg bank_account" id="account_number" type="tel" size="20" data-stripe="account_number" placeholder="000123456789" autocomplete="off">
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-md-12">
                <button class="btn btn-lg btn-block btn-custom btn-primary submit" type="submit">
                  <span class="fa fa-bank"></span> Add bank account
                </button>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- Stripe.js to collect payment details -->
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<!-- Jquery payment library for nicer formatting -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.payment/1.4.1/jquery.payment.js"></script>
<script>
  // Set your Stripe publishable API key here
  Stripe.setPublishableKey('<%= ENV['PUBLISHABLE_KEY'] %>');

  $(function() {
    var $form = $('#bank-form');
    $form.submit(function(event) {
      // Clear any errors
      $form.find('.has-error').removeClass('has-error');

      // Disable the submit button to prevent repeated clicks:
      $form.find('.submit').prop('disabled', true).html("<i class='fa fa-spinner fa-spin'></i> Creating account...");

      // Request a token from Stripe:
      Stripe.bankAccount.createToken($form, stripeResponseHandler);
      
      // Prevent the form from being submitted:
      return false;
    });

    // Switch or hide 'routing number' depending on currency
    $('#currency').change(function(){
      $('#routing_number_div').show();
      $('#account_number_label').text('Account Number').next('input').attr('placeholder', '');
      $('#routing_number').attr('data-stripe', 'routing_number');
      switch (this.value) {
        case "usd":
          $('#routing_number_label').text('Routing Number').next('input').attr('placeholder', '111000000');
          break;
        case "eur":
          // No routing number needed
          $('#routing_number_div').hide();
          $('#routing_number').removeAttr('data-stripe');
          $('#account_number_label').text('IBAN').next('input').attr('placeholder','XX9828737432389');
          break;
        case "cad":
          $('#routing_number_label').text('Transit & Institution Number');
          break;
        case "gbp":
          $('#routing_number_label').text('Sort Code').next('input').attr('placeholder', '12-34-56');
          break;
        case "mxn":
          $('#routing_number_label').text('CLABE');
          break;
        case 'aud': case "nzd":
          $('#routing_number_label').text('BSB').next('input').attr('placeholder', '123456');
          break;
        case 'sgd': case "jpy": case "brl": case "hkd":
          $('#routing_number_label').text('Bank / Branch Code');
          break;
      }
    });
  });

  function stripeResponseHandler(status, response) {
    alert("debug1");
    var $form = $('#bank-form');

    if (response.error) {
      // Show the errors on the form
      $form.find('.errors').text(response.error.message).addClass('alert alert-danger');
      $form.find('.' + response.error.param).parent('.form-group').addClass('has-error');
      $form.find('button').prop('disabled', false).text('Add bank account'); // Re-enable submission
    } 
    else { // Token was created!
      alert("debug2");
      $form.find('.submit').html("<i class='fa fa-check'></i> Account added");
      
      // Get the token ID:
      var token = response.id;

      // Insert the token and name into the form so it gets submitted to the server:<commit_msg>get rid of publishable key whitespace<commit_after><%= content_for :page_title, 'ACH Payment Example' %>
<div class="container">
  <div class="row text-center">
    <div class="col-md-12 topspace text-center">
      <h1 class="page-header">
        Enter your bank details
      </h1>
    </div>
  </div>
  <div class="row">
    <div class="col-md-6 col-md-offset-3">
      <%= render 'layouts/messages' %>
      <div class="alert alert-warning">
        <strong>Hint:</strong> Test routing and account numbers can be found <a href="https://stripe.com/docs/ach#testing-ach">in the ACH docs</a>.
      </div>
      <div class="panel panel-default">
        <div class="panel-body text-left">
          <form action="/banks" method="POST" id="bank-form">
            <%= hidden_field_tag :authenticity_token, form_authenticity_token %>
            <div class="errors"></div>
            <div class="row">
              <div class="col-md-8">
                <div class="form-group">
                  <label>Bank Country</label>
                  <select class="form-control input-lg" id="country" data-stripe="country">
                    <option value="US">United States</option>
                    <option value="AU">Australia</option>
                    <option value="AT">Austria</option>
                    <option value="BE">Belgium</option>
                    <option value="BR">Brazil</option>
                    <option value="CA">Canada</option>
                    <option value="DK">Denmark</option>
                    <option value="FI">Finland</option>
                    <option value="FR">France</option>
                    <option value="DE">Germany</option>
                    <option value="HK">Hong Kong</option>
                    <option value="IE">Ireland</option>
                    <option value="IT">Italy</option>
                    <option value="JP">Japan</option>
                    <option value="LU">Luxembourg</option>
                    <option value="MX">Mexico</option>
                    <option value="NZ">New Zealand</option>
                    <option value="NL">Netherlands</option>
                    <option value="NO">Norway</option>
                    <option value="PT">Portugal</option>
                    <option value="SG">Singapore</option>
                    <option value="ES">Spain</option>
                    <option value="SE">Sweden</option>
                    <option value="CH">Switzerland</option>
                  </select>
                </div>
              </div>
              <div class="col-md-4">
                <div class="form-group">
                  <label>Account Currency</label>
                  <select class="form-control input-lg" id="currency" data-stripe="currency">
                    <option value="usd">USD</option>
                    <option value="aud">AUD</option>
                    <option value="brl">BRL</option>
                    <option value="cad">CAD</option>
                    <option value="eur">EUR</option>
                    <option value="gbp">GBP</option>
                    <option value="hkd">HKD</option>
                    <option value="jpy">JPY</option>
                    <option value="mxn">MXN</option>
                    <option value="nzd">NZD</option>
                    <option value="sgd">SGD</option>
                  </select>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-md-6">
                <div class="form-group">
                  <label>Full Legal Name</label>
                  <input class="form-control input-lg account_holder_name" id="account_holder_name" type="text" data-stripe="account_holder_name" placeholder="<NAME>" autocomplete="off">
                </div>
              </div>
              <div class="col-md-6">
                <div class="form-group">
                  <label>Account Type</label>
                  <select class="form-control input-lg account_holder_type" id="account_holder_type" data-stripe="account_holder_type">
                    <option value="individual">Individual</option>
                    <option value="company">Company</option>
                  </select>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-md-6" id="routing_number_div">
                <div class="form-group">
                  <label id="routing_number_label">Routing Number</label>
                  <input class="form-control input-lg bank_account" id="routing_number" type="tel" size="12" data-stripe="routing_number" placeholder="111000025" autocomplete="off">
                </div>
              </div>
              <div class="col-md-6">
                <div class="form-group">
                  <label id="account_number_label">Account Number</label>
                  <input class="form-control input-lg bank_account" id="account_number" type="tel" size="20" data-stripe="account_number" placeholder="000123456789" autocomplete="off">
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-md-12">
                <button class="btn btn-lg btn-block btn-custom btn-primary submit" type="submit">
                  <span class="fa fa-bank"></span> Add bank account
                </button>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- Stripe.js to collect payment details -->
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<!-- Jquery payment library for nicer formatting -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.payment/1.4.1/jquery.payment.js"></script>
<script>
  // Set your Stripe publishable API key here
  Stripe.setPublishableKey('<%=ENV['PUBLISHABLE_KEY']%>');

  $(function() {
    var $form = $('#bank-form');
    $form.submit(function(event) {
      // Clear any errors
      $form.find('.has-error').removeClass('has-error');

      // Disable the submit button to prevent repeated clicks:
      $form.find('.submit').prop('disabled', true).html("<i class='fa fa-spinner fa-spin'></i> Creating account...");

      // Request a token from Stripe:
      Stripe.bankAccount.createToken($form, stripeResponseHandler);
      
      // Prevent the form from being submitted:
      return false;
    });

    // Switch or hide 'routing number' depending on currency
    $('#currency').change(function(){
      $('#routing_number_div').show();
      $('#account_number_label').text('Account Number').next('input').attr('placeholder', '');
      $('#routing_number').attr('data-stripe', 'routing_number');
      switch (this.value) {
        case "usd":
          $('#routing_number_label').text('Routing Number').next('input').attr('placeholder', '111000000');
          break;
        case "eur":
          // No routing number needed
          $('#routing_number_div').hide();
          $('#routing_number').removeAttr('data-stripe');
          $('#account_number_label').text('IBAN').next('input').attr('placeholder','XX9828737432389');
          break;
        case "cad":
          $('#routing_number_label').text('Transit & Institution Number');
          break;
        case "gbp":
          $('#routing_number_label').text('Sort Code').next('input').attr('placeholder', '12-34-56');
          break;
        case "mxn":
          $('#routing_number_label').text('CLABE');
          break;
        case 'aud': case "nzd":
          $('#routing_number_label').text('BSB').next('input').attr('placeholder', '123456');
          break;
        case 'sgd': case "jpy": case "brl": case "hkd":
          $('#routing_number_label').text('Bank / Branch Code');
          break;
      }
    });
  });

  function stripeResponseHandler(status, response) {
    var $form = $('#bank-form');

    if (response.error) {
      // Show the errors on the form
      $form.find('.errors').text(response.error.message).addClass('alert alert-danger');
      $form.find('.' + response.error.param).parent('.form-group').addClass('has-error');
      $form.find('button').prop('disabled', false).text('Add bank account'); // Re-enable submission
    } 
    else { // Token was created!
      $form.find('.submit').html("<i class='fa fa-check'></i> Account added");
      
      // Get the token ID:
      var token = response.id;

      // Insert the token and name into the form so it gets submitted to the server:
{'fraction_non_alphanumeric': 0.1608954179783141, 'fraction_numerical': 0.009094088842252535, 'mean_word_length': 1.9567390554981041, 'pattern_counts': {'":': 18, '<': 353, '<?xml version=': 0, '>': 353, 'https://': 6, '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': '7432726', 'n_tokens_mistral': 4927, 'n_tokens_neox': 4623, 'n_words': 935}