How to get an instance of a plugin I am attempting to use a pre-configured instance of a plugin.  The plugin is of type @CommercePaymentGateway.  

I am currently trying to use something like:

/** @var PaymentGatewayManager $manager */
$manager = \Drupal::service('plugin.manager.commerce_payment_gateway');
$manager-&gt;getInstance(['module' =&gt; 'commerce_paypal']);


But I'm getting the error Error: Call to a member function getInstance() on null.  However, using kint(), $manager is clearly an instance of Drupal\commerce_payment\PaymentGatewayManager.

I see what I think is the instance configuration in the config table under commerce_payment.commerce_payment_gateway.paypal_ec.  But that paypal_ec part is specific to my site.

How do I get an instance of a plugin?
It turns out, in my case, I'm asking the wrong question.  All that I need is the parent config entity (@bojanz pointed this out in slack), so I was over-complicating the issue:

$gateway = \Drupal::entityTypeManager()
  -&gt;getStorage('commerce_payment_gateway')-&gt;loadByProperties([
    'plugin' =&gt; 'paypal_express_checkout',
]);


This will return an array of gateways, get a specific one:

// Get the first one
$plugin = reset($gateway);
$plugin = $plugin-&gt;getPlugin();


Now you have the $plugin to be used elsewhere.