Apply discount together with free shipping

I slightly changed the code from the guide, for the sake of simplicity. Checked, works.
We are planning to launch the action in the near future.
But yes, alas, this is only for shops of the “Shopify Plus” plan, unfortunately I cannot suggest another variant at the moment.
I’ll just leave it here, hopefully someone will come in handy.

CONDITIONS_FOR_DISCOUNT = [
  {
    codes: ['SOMECODE', 'OTHERCODE'],
    d_type: :percent, # :percent/:money
    d_value: 100,
    d_message: 'Free shipping'
  }
]

CONDITIONS_FOR_DISCOUNT.each do |condition|
  next unless Input.cart.discount_code && condition[:codes].include?(Input.cart.discount_code.code.upcase.strip)
  
  Input.shipping_rates.each do |shipping_rate|
    discount_amount = if condition[:d_type] == :percent
      condition[:d_value] * 0.01 * shipping_rate.price
    else
      Money.new(cents: 100) * condition[:d_value]
    end
    shipping_rate.apply_discount(discount_amount, message: condition[:d_message])
  end
end

Output.shipping_rates = Input.shipping_rates

** script type ‘Shipping’