$(function () {
  $(document).on('change', 'input[name="payment_method"]', function() {
      const paymentMethod = $(this).val();

      // Do a GET request with X-Requested-With header, with the payment method specified.
      // If the request is successful, replace #checkouttotal with the response.
      $.ajax({
          url: window.location.href,
          type: 'GET',
          headers: {
              'X-Requested-With': 'XMLHttpRequest'
          },
          data: {
              payment_method: paymentMethod
          },
          success: function(response) {
            $('#checkouttotal').replaceWith(response);
          }
      });
  });
});
