Automattic\WooCommerce\Internal\Admin\Settings
PaymentsProviders::get_payment_gateway_provider_instance
Get the payment gateway provider instance.
Метод класса: PaymentsProviders{}
Хуков нет.
Возвращает
PaymentGateway. The payment gateway provider instance. Will return the general provider of no specific provider is found.
Использование
$PaymentsProviders = new PaymentsProviders(); $PaymentsProviders->get_payment_gateway_provider_instance( $gateway_id ): PaymentGateway;
- $gateway_id(строка) (обязательный)
- The gateway ID.
Код PaymentsProviders::get_payment_gateway_provider_instance() PaymentsProviders::get payment gateway provider instance WC 10.7.0
public function get_payment_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 class-string<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;
}
}
}
}
// Check that the provider class extends the PaymentGateway class.
if ( ! is_null( $provider_class ) && ! is_subclass_of( $provider_class, PaymentGateway::class ) ) {
wc_doing_it_wrong(
__METHOD__,
sprintf(
/* translators: %s: Gateway ID. */
esc_html__( 'The provider class for gateway ID "%s" must extend the PaymentGateway class.', 'woocommerce' ),
$gateway_id
),
'10.4.0'
);
// Return the generic provider as a fallback.
$provider_class = null;
}
// 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( $this->proxy );
}
return $this->instances['generic'];
}
$this->instances[ $gateway_id ] = new $provider_class( $this->proxy );
return $this->instances[ $gateway_id ];
}