<commit_before><% param_prefix = "payment_source[#{payment_method.id}]" %>

<style type="text/css">
  .klarna_credit_box {
    border: 1px solid #0074C8;§
  }
  .header {
    background-color: #0074C8;
    color: white;
    padding: 10px 20px;
  }

  .header h3 {
    float: left;
    margin-right: 20px;
  }
  #klarna_container {
    text-align: center;
    padding: 20px;
  }
  @media only screen and (max-width: 767px) {
    #klarna_container {
      padding: 5px;
    }
    .klarna_credit_box {
      margin: -10px;
    }
  }
</style>

<div class="klarna_credit_box" data-order-id="<%= @order.number %>" data-payment-method-id="<%= payment_method.id %>">
  <div class="header" style="width: 100%, background-color: ">
    <div class="logo">
      <img src="https://www.klarna.com/application/files/3114/5674/1539/Klarna-white-RGB.svg" width="80px">
    </div>
  </div>

  <%= hidden_field_tag "#{param_prefix}[authorization_token]", "", {id: "klarna_authorization_token"} %>
  <div id="klarna_container"></div>
</div>

<script type="text/javascript" id="klarna­credit­lib­x">
/* <![CDATA[ */
 (function(w, d) {
   var url = 'https://credit.klarnacdn.net/lib/v1/api.js';
    n = d.createElement('script');
    c = d.getElementById('klarna­credit­lib­x');
    n.async = !0;
    n.src = url + '?' + (new Date ()).getTime();
    c.parentNode.replaceChild(n, c);
  })(this, document);
 /* ]]> */
</script>

<script type="text/javascript">
  $.fn.klarna = function(options) {
    var settings = $.extend({
      paymentChangedElements: $('input[name="order[payments_attributes][][payment_method_id]"]'),
      paymentId: null,
      sessionUrl: "/checkout/:id/klarna_session",
      submitButton: $('form.edit_order :submit'),
      orderId: null
    }, options);

    if (!settings.orderId && this.data('orderId') !== undefined) {
      settings.orderId = this.data('orderId');
    }

    if (settings.paymentId === null) {
      settings.paymentId = $(this).data('payment-method-id');
    }

    settings.sessionUrl = settings.sessionUrl.replace(":id",settings.orderId);

    settings.authorizationToken = $('#klarna_authorization_token', this);

    // Get a session from the backend and load the form
    var initSession = function() {
      $.ajax({
        method: 'POST',
        url: settings.sessionUrl,
        data: {klarna_payment_method_id: settings.paymentId}
      }).done(function(response) {
        settings.clientToken = response.token
        Klarna.Credit.init ({
          client_token: response.token
        });

        loadKlarnaForm();
      });
    }

    // Loads the Klarna Form
    var loadKlarnaForm = function () {
      if (!settings.clientToken) {
        return;
      }

      Klarna.Credit.load ({
        container: "#klarna_container"
      }, function(res) {
        if (res.show_form) {
          settings.showForm = res.show_form;
        } else {
          console.log(res)
        }
      });
    }

    // Try to authorize
    var authorize = function (approved, notApproved) {
      // First get the current, serialized order
      $.ajax({
        method: 'GET',
        url: "/checkout/state/klarna_order_addresses",
        dataType: 'json'
      }).done(function(result) {
        Klarna.Credit.authorize(result, function(res) {
          if (res.approved === true) {
            settings.authorizationToken.val(res.authorization_token);
            approved(res)
          } else {
            notApproved(res)
          }
        });
      });
    }

    var klarnaSelected = function() {
      return settings.paymentChangedElements.filter(":checked").val() == settings.paymentId;
    }

    // Revert Spree's disableSaveOnClick when authorization is denied
    var enableSaveOnClick = function() {
      $('form.edit_order').find(':submit, :image').attr('disabled', false).addClass('primary').addClass('disabled')
    }

    settings.paymentChangedElements.on('change', function(e) {
      // check if Klarna Credit is selected
      if (klarnaSelected()) {
        initSession();
      }
    })

    $('form.edit_order').on('submit', function (e) {
      var form = this;
      if (klarnaSelected()) {
        e.preventDefault();
        authorize(function (result) {
          form.submit();
        }, function(result) {
          enableSaveOnClick();
        }
        );
      }
    });

    return this;
  };

  $(".klarna_credit_box").klarna();
</script>
<commit_msg>Adding missing payment method id parameter in order address verifier. <commit_after><% param_prefix = "payment_source[#{payment_method.id}]" %>

<style type="text/css">
  .klarna_credit_box {
    border: 1px solid #0074C8;§
  }
  .header {
    background-color: #0074C8;
    color: white;
    padding: 10px 20px;
  }

  .header h3 {
    float: left;
    margin-right: 20px;
  }
  #klarna_container {
    text-align: center;
    padding: 20px;
  }
  @media only screen and (max-width: 767px) {
    #klarna_container {
      padding: 5px;
    }
    .klarna_credit_box {
      margin: -10px;
    }
  }
</style>

<div class="klarna_credit_box" data-order-id="<%= @order.number %>" data-payment-method-id="<%= payment_method.id %>">
  <div class="header" style="width: 100%, background-color: ">
    <div class="logo">
      <img src="https://www.klarna.com/application/files/3114/5674/1539/Klarna-white-RGB.svg" width="80px">
    </div>
  </div>

  <%= hidden_field_tag "#{param_prefix}[authorization_token]", "", {id: "klarna_authorization_token"} %>
  <div id="klarna_container"></div>
</div>

<script type="text/javascript" id="klarna­credit­lib­x">
/* <![CDATA[ */
 (function(w, d) {
   var url = 'https://credit.klarnacdn.net/lib/v1/api.js';
    n = d.createElement('script');
    c = d.getElementById('klarna­credit­lib­x');
    n.async = !0;
    n.src = url + '?' + (new Date ()).getTime();
    c.parentNode.replaceChild(n, c);
  })(this, document);
 /* ]]> */
</script>

<script type="text/javascript">
  $.fn.klarna = function(options) {
    var settings = $.extend({
      paymentChangedElements: $('input[name="order[payments_attributes][][payment_method_id]"]'),
      paymentId: null,
      sessionUrl: "/checkout/:id/klarna_session",
      submitButton: $('form.edit_order :submit'),
      orderId: null
    }, options);

    if (!settings.orderId && this.data('orderId') !== undefined) {
      settings.orderId = this.data('orderId');
    }

    if (settings.paymentId === null) {
      settings.paymentId = $(this).data('payment-method-id');
    }

    settings.sessionUrl = settings.sessionUrl.replace(":id",settings.orderId);

    settings.authorizationToken = $('#klarna_authorization_token', this);

    // Get a session from the backend and load the form
    var initSession = function() {
      $.ajax({
        method: 'POST',
        url: settings.sessionUrl,
        data: {klarna_payment_method_id: settings.paymentId}
      }).done(function(response) {
        settings.clientToken = response.token
        Klarna.Credit.init ({
          client_token: response.token
        });

        loadKlarnaForm();
      });
    }

    // Loads the Klarna Form
    var loadKlarnaForm = function () {
      if (!settings.clientToken) {
        return;
      }

      Klarna.Credit.load ({
        container: "#klarna_container"
      }, function(res) {
        if (res.show_form) {
          settings.showForm = res.show_form;
        } else {
          console.log(res)
        }
      });
    }

    // Try to authorize
    var authorize = function (approved, notApproved) {
      // First get the current, serialized order
      $.ajax({
        method: 'GET',
        url: "/checkout/state/klarna_order_addresses",
        dataType: 'json',
        data: {klarna_payment_method_id: settings.paymentId}
      }).done(function(result) {
        Klarna.Credit.authorize(result, function(res) {
          if (res.approved === true) {
            settings.authorizationToken.val(res.authorization_token);
            approved(res)
          } else {
            notApproved(res)
          }
        });
      });
    }

    var klarnaSelected = function() {
      return settings.paymentChangedElements.filter(":checked").val() == settings.paymentId;
    }

    // Revert Spree's disableSaveOnClick when authorization is denied
    var enableSaveOnClick = function() {
      $('form.edit_order').find(':submit, :image').attr('disabled', false).addClass('primary').addClass('disabled')
    }

    settings.paymentChangedElements.on('change', function(e) {
      // check if Klarna Credit is selected
      if (klarnaSelected()) {
        initSession();
      }
    })

    $('form.edit_order').on('submit', function (e) {
      var form = this;
      if (klarnaSelected()) {
        e.preventDefault();
        authorize(function (result) {
          form.submit();
        }, function(result) {
          enableSaveOnClick();
        }
        );
      }
    });

    return this;
  };

  $(".klarna_credit_box").klarna();
</script>

{'fraction_non_alphanumeric': 0.1592555444110108, 'fraction_numerical': 0.010030090270812437, 'mean_word_length': 2.6098149637972647, 'pattern_counts': {'":': 4, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, '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': '252928', 'n_tokens_mistral': 2956, 'n_tokens_neox': 2814, 'n_words': 521}