The following block can be simplified:
$types = array_intersect_key($types, array_flip($availableTypes));
See also:
collectTypes()
Magento_BraintreeTwo
validator.js
Magento_Braintree
cc-form.js