Automattic\WooCommerce\Internal\Admin\Settings
PaymentsProviders::get_payment_extension_suggestion_provider_instance
Get the payment extension suggestion (PES) provider instance.
Method of the class: PaymentsProviders{}
No Hooks.
Returns
PaymentGateway. The payment extension suggestion provider instance. Will return the general provider of no specific provider is found.
Usage
$PaymentsProviders = new PaymentsProviders(); $PaymentsProviders->get_payment_extension_suggestion_provider_instance( $pes_id ): PaymentGateway;
- $pes_id(string) (required)
- The payment extension suggestion ID.
PaymentsProviders::get_payment_extension_suggestion_provider_instance() PaymentsProviders::get payment extension suggestion provider instance code WC 10.7.0
public function get_payment_extension_suggestion_provider_instance( string $pes_id ): PaymentGateway {
if ( isset( $this->instances[ $pes_id ] ) ) {
return $this->instances[ $pes_id ];
}
/**
* The provider class for the payment extension suggestion (PES).
*
* @var class-string<PaymentGateway>|null $provider_class
*/
$provider_class = null;
if ( isset( $this->payment_extension_suggestions_providers_class_map[ $pes_id ] ) ) {
if ( ! is_subclass_of( $this->payment_extension_suggestions_providers_class_map[ $pes_id ], PaymentGateway::class ) ) {
wc_doing_it_wrong(
__METHOD__,
sprintf(
/* translators: %s: Payment extension suggestion ID. */
esc_html__( 'The provider class for payment extension suggestion ID "%s" must extend the PaymentGateway class.', 'woocommerce' ),
$pes_id
),
'10.4.0'
);
// Return the generic provider as a fallback.
} else {
$provider_class = $this->payment_extension_suggestions_providers_class_map[ $pes_id ];
}
}
// 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[ $pes_id ] = new $provider_class( $this->proxy );
return $this->instances[ $pes_id ];
}