<commit_before><%= render "spree/checkout/payment/gateway", payment_method: payment_method %>

<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script type="text/javascript">
  Stripe.setPublishableKey("<%= payment_method.preferred_publishable_key %>");
</script>

<script>
  Spree.stripePaymentMethod = $('#payment_method_' + <%= payment_method.id %>);

  var mapCC, stripeResponseHandler;

  mapCC = function(ccType) {
    if (ccType === 'MasterCard') {
      return 'mastercard';
    } else if (ccType === 'Visa') {
      return 'visa';
    } else if (ccType === 'American Express') {
      return 'amex';
    } else if (ccType === 'Discover') {
      return 'discover';
    } else if (ccType === 'Diners Club') {
      return 'dinersclub';
    } else if (ccType === 'JCB') {
      return 'jcb';
    }
  };

  stripeResponseHandler = function(status, response) {
    var paymentMethodId, token;
    if (response.error) {
      $('#stripeError').html(response.error.message);
      var param_map = {
        number:    '#card_number',
        exp_month: '#card_expiry',
        exp_year:  '#card_expiry',
        cvc:       '#card_code'
      }
      if (response.error.param)
        Spree.stripePaymentMethod.find(param_map[response.error.param]).addClass('error');

      return $('#stripeError').show();
    } else {
      Spree.stripePaymentMethod.find('#card_number, #card_expiry, #card_code').prop("disabled", true);
      Spree.stripePaymentMethod.find(".ccType").prop("disabled", false);
      Spree.stripePaymentMethod.find(".ccType").val(mapCC(response.card.brand));
      token = response['id'];
      paymentMethodId = Spree.stripePaymentMethod.prop('id').split("_")[2];
      Spree.stripePaymentMethod.append("<input type='hidden' class='stripeToken' name='payment_source[" + paymentMethodId + "][gateway_payment_profile_id]' value='" + token + "'/>");
      Spree.stripePaymentMethod.append("<input type='hidden' class='stripeToken' name='payment_source[" + paymentMethodId + "][last_digits]' value='" + response.card.last4 + "'/>");
      Spree.stripePaymentMethod.append("<input type='hidden' class='stripeToken' name='payment_source[" + paymentMethodId + "][month]' value='" + response.card.exp_month + "'/>");
      Spree.stripePaymentMethod.append("<input type='hidden' class='stripeToken' name='payment_source[" + paymentMethodId + "][year]' value='" + response.card.exp_year + "'/>");
      return Spree.stripePaymentMethod.parents("form").trigger('submit');
    }
  };

  $(document).ready(function() {
    Spree.stripePaymentMethod.prepend("<div id='stripeError' class='errorExplanation' style='display:none'></div>");
    return $('#checkout_form_payment [data-hook=buttons]').click(function() {<commit_msg>Add boostrap "has-error" class to the parent of field with error.<commit_after><%= render "spree/checkout/payment/gateway", payment_method: payment_method %>

<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script type="text/javascript">
  Stripe.setPublishableKey("<%= payment_method.preferred_publishable_key %>");
</script>

<script>
  Spree.stripePaymentMethod = $('#payment_method_' + <%= payment_method.id %>);

  var mapCC, stripeResponseHandler;

  mapCC = function(ccType) {
    if (ccType === 'MasterCard') {
      return 'mastercard';
    } else if (ccType === 'Visa') {
      return 'visa';
    } else if (ccType === 'American Express') {
      return 'amex';
    } else if (ccType === 'Discover') {
      return 'discover';
    } else if (ccType === 'Diners Club') {
      return 'dinersclub';
    } else if (ccType === 'JCB') {
      return 'jcb';
    }
  };

  stripeResponseHandler = function(status, response) {
    var paymentMethodId, token;
    if (response.error) {
      $('#stripeError').html(response.error.message);
      var param_map = {
        number:    '#card_number',
        exp_month: '#card_expiry',
        exp_year:  '#card_expiry',
        cvc:       '#card_code'
      }
      if (response.error.param) {
        errorField = Spree.stripePaymentMethod.find(param_map[response.error.param])
        errorField.addClass('error');
        errorField.parent().addClass('has-error');
      }

      return $('#stripeError').show();
    } else {
      Spree.stripePaymentMethod.find('#card_number, #card_expiry, #card_code').prop("disabled", true);
      Spree.stripePaymentMethod.find(".ccType").prop("disabled", false);
      Spree.stripePaymentMethod.find(".ccType").val(mapCC(response.card.brand));
      token = response['id'];
      paymentMethodId = Spree.stripePaymentMethod.prop('id').split("_")[2];
      Spree.stripePaymentMethod.append("<input type='hidden' class='stripeToken' name='payment_source[" + paymentMethodId + "][gateway_payment_profile_id]' value='" + token + "'/>");
      Spree.stripePaymentMethod.append("<input type='hidden' class='stripeToken' name='payment_source[" + paymentMethodId + "][last_digits]' value='" + response.card.last4 + "'/>");
      Spree.stripePaymentMethod.append("<input type='hidden' class='stripeToken' name='payment_source[" + paymentMethodId + "][month]' value='" + response.card.exp_month + "'/>");
      Spree.stripePaymentMethod.append("<input type='hidden' class='stripeToken' name='payment_source[" + paymentMethodId + "][year]' value='" + response.card.exp_year + "'/>");
      return Spree.stripePaymentMethod.parents("form").trigger('submit');
    }
  };

  $(document).ready(function() {
    Spree.stripePaymentMethod.prepend("<div id='stripeError' class='errorExplanation' style='display:none'></div>");
    return $('#checkout_form_payment [data-hook=buttons]').click(function() {
{'fraction_non_alphanumeric': 0.17888045205721348, 'fraction_numerical': 0.0010595090941197245, 'mean_word_length': 4.2250922509225095, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '3869375', 'n_tokens_mistral': 1799, 'n_tokens_neox': 1760, 'n_words': 287}