Automattic\WooCommerce\Internal\Admin\Settings
PaymentProviders::get_gateway_provider_instance
Get the payment gateway provider instance.
Method of the class: PaymentProviders{}
No Hooks.
Returns
PaymentGateway
. The payment gateway provider instance. Will return the general provider of no specific provider is found.
Usage
// private - for code of main (parent) class only $result = $this->get_gateway_provider_instance( $gateway_id ): PaymentGateway;
- $gateway_id(string) (required)
- The gateway ID.
PaymentProviders::get_gateway_provider_instance() PaymentProviders::get gateway provider instance code WC 9.8.5
private function get_gateway_provider_instance( string $gateway_id ): PaymentGateway { if ( isset( $this->instances[ $gateway_id ] ) ) { return $this->instances[ $gateway_id ]; } /** * The provider class for the gateway. * * @var PaymentGateway|null $provider_class */ $provider_class = null; if ( isset( $this->payment_gateways_providers_class_map[ $gateway_id ] ) ) { $provider_class = $this->payment_gateways_providers_class_map[ $gateway_id ]; } else { // Check for wildcard mappings. foreach ( $this->payment_gateways_providers_class_map as $gateway_id_pattern => $mapped_class ) { // Try to see if we have a wildcard mapping and if the gateway ID matches it. // Use the first found match. if ( false !== strpos( $gateway_id_pattern, '*' ) ) { $gateway_id_pattern = str_replace( '*', '.*', $gateway_id_pattern ); if ( preg_match( '/^' . $gateway_id_pattern . '$/', $gateway_id ) ) { $provider_class = $mapped_class; break; } } } } // If the gateway ID is not mapped to a provider class, return the generic provider. if ( is_null( $provider_class ) ) { if ( ! isset( $this->instances['generic'] ) ) { $this->instances['generic'] = new PaymentGateway(); } return $this->instances['generic']; } $this->instances[ $gateway_id ] = new $provider_class(); return $this->instances[ $gateway_id ]; }