The issue is that you’re using a deprecated method of applying a discount code to your checkout.
Use this
baseURL/discount/DISCOUNT_CODE?redirect=/checkout
instead of this
/checkout?discount=DISCOUNT_CODE
Something like that:
let baseUrl = window.location.protocol + "//" + window.location.hostname;
checkout.attr('href', `${baseUrl}/discount/${discountCode}?redirect=/checkout`);