TLDR: Free your code. Protect your execution
Let me present a contrarian view.
What about assuming that your code is not your competitive advantage but your ability to execute is? There are hundreds of millions of lines of open source code on Github, much of which "your code" possibly borrows from or relies upon. Many of the companies and individuals who publish said software are killing it both in and out of Nigeria. So what's with the hullabaloo about protecting code?
From my experience, the only people that ascribe a lot of value to raw code are software developers or people who can't see disruption coming across the corner. Most business customers I meet are more interested in the solution provider so they value attributes such as technical competence, support infrastructure, branding, proximity, in at least one odd case, your capital base.
If you must protect the code, one option is to structure it such that it requires an encrypted library in order to run, then issue the decryption key when the license has been paid for.