For a quick fix, change $memType['auto_renew'] to ($memType['auto_renew'] ?? 0) for the first one, and
change $membershiptTypeValue['auto_renew'] to !empty($membershiptTypeValue['auto_renew']) for the second one.
This was resolved via the setting for Anon user noted by Iowa boy and the User Login Block noted by Karin. I did not add the options in permissions for Auth Users - did not make any difference to operations.
I think 1 will take care of #2
Profile listings and forms are NOT for your public users. Only trusted users. You want to change that one
Here are the permission you need for Anonymous and Authenticed Users
CiviCRM: profile create
CiviCRM: profile edit
CiviCRM: profile view
CiviContribute: make online contributions
There is an extension that does that: https://github.com/Project60/org.project60.membership
It can do much more than only connecting memberships and contributions via the UI so make sure that it's not an overkill for your purposes ;)
Unfortunately, there is no coherent documentation so for some features you may want to contact the maintainer (Björn from ...
Note that the token <contribution_id> is the payment id that was created after you submitted the contribution form. <contact_id> is the id of the contact to which ...
For those who want to do this via the UI I believe this is as simple as going to civicrm/admin/financial/financialType?reset=1 and mousing over or clicking on Edit for each Financial Type and the ID will show in the url
For anyone else looking for this, you can use the getFields action on the Contribution entity to locate the options for the Financial Type ID.
$fields = \Civi\Api4\Contribution::getFields()
->addWhere('options', '!=', FALSE)