Automattic\WooCommerce\Internal\Admin\Settings

PaymentProviders::enhance_payment_gateway_detailsprivateWC 1.0

Enhance the payment gateway details with additional information from other sources.

Method of the class: PaymentProviders{}

No Hooks.

Returns

Array. The enhanced gateway details.

Usage

// private - for code of main (parent) class only
$result = $this->enhance_payment_gateway_details( $gateway_details, $payment_gateway, $country_code ): array;
$gateway_details(array) (required)
The gateway details to enhance.
$payment_gateway(WC_Payment_Gateway) (required)
The payment gateway object.
$country_code(string) (required)
The country code for which the details are being enhanced. This should be a ISO 3166-1 alpha-2 country code.

PaymentProviders::enhance_payment_gateway_details() code WC 9.8.5

private function enhance_payment_gateway_details( array $gateway_details, WC_Payment_Gateway $payment_gateway, string $country_code ): array {
	// We discriminate between offline payment methods and gateways.
	$gateway_details['_type'] = $this->is_offline_payment_method( $payment_gateway->id ) ? self::TYPE_OFFLINE_PM : self::TYPE_GATEWAY;

	$plugin_slug = $gateway_details['plugin']['slug'];
	// The payment gateway plugin might use a non-standard directory name.
	// Try to normalize it to the common slug to avoid false negatives when matching.
	$normalized_plugin_slug = Utils::normalize_plugin_slug( $plugin_slug );

	// If we have a matching suggestion, hoist details from there.
	// The suggestions only know about the normalized (aka official) plugin slug.
	$suggestion = $this->get_extension_suggestion_by_plugin_slug( $normalized_plugin_slug, $country_code );
	if ( ! is_null( $suggestion ) ) {
		// Enhance the suggestion details.
		$suggestion = $this->enhance_extension_suggestion( $suggestion );

		// The title, description, icon, and image from the suggestion take precedence over the ones from the gateway.
		// This is temporary until we update the partner extensions.
		// Do not override the title and description for certain suggestions because theirs are more descriptive
		// (like including the payment method when registering multiple gateways for the same provider).
		if ( ! in_array(
			$suggestion['id'],
			array(
				ExtensionSuggestions::PAYPAL_FULL_STACK,
				ExtensionSuggestions::PAYPAL_WALLET,
				ExtensionSuggestions::MOLLIE,
				ExtensionSuggestions::MONEI,
				ExtensionSuggestions::ANTOM,
				ExtensionSuggestions::MERCADO_PAGO,
				ExtensionSuggestions::AMAZON_PAY,
				ExtensionSuggestions::SQUARE,
				ExtensionSuggestions::PAYONEER,
				ExtensionSuggestions::AIRWALLEX,
				ExtensionSuggestions::COINBASE, // We don't have suggestion details yet.
				ExtensionSuggestions::AUTHORIZE_NET, // We don't have suggestion details yet.
				ExtensionSuggestions::BOLT, // We don't have suggestion details yet.
				ExtensionSuggestions::DEPAY, // We don't have suggestion details yet.
				ExtensionSuggestions::ELAVON, // We don't have suggestion details yet.
				ExtensionSuggestions::EWAY, // We don't have suggestion details yet.
				ExtensionSuggestions::FORTISPAY, // We don't have suggestion details yet.
				ExtensionSuggestions::NEXI, // We don't have suggestion details yet.
				ExtensionSuggestions::PAYPAL_ZETTLE, // We don't have suggestion details yet.
				ExtensionSuggestions::RAPYD, // We don't have suggestion details yet.
				ExtensionSuggestions::PAYPAL_BRAINTREE, // We don't have suggestion details yet.
			),
			true
		) ) {
			if ( ! empty( $suggestion['title'] ) ) {
				$gateway_details['title'] = $suggestion['title'];
			}

			if ( ! empty( $suggestion['description'] ) ) {
				$gateway_details['description'] = $suggestion['description'];
			}
		}

		if ( ! empty( $suggestion['icon'] ) ) {
			$gateway_details['icon'] = $suggestion['icon'];
		}

		if ( ! empty( $suggestion['image'] ) ) {
			$gateway_details['image'] = $suggestion['image'];
		}

		if ( empty( $gateway_details['links'] ) ) {
			$gateway_details['links'] = $suggestion['links'];
		}
		if ( empty( $gateway_details['tags'] ) ) {
			$gateway_details['tags'] = $suggestion['tags'];
		}
		if ( empty( $gateway_details['plugin'] ) ) {
			$gateway_details['plugin'] = $suggestion['plugin'];
		}
		if ( empty( $gateway_details['_incentive'] ) && ! empty( $suggestion['_incentive'] ) ) {
			$gateway_details['_incentive'] = $suggestion['_incentive'];
		}

		// Attach the suggestion ID to the gateway details so we can reference it with precision.
		$gateway_details['_suggestion_id'] = $suggestion['id'];
	}

	// Get the gateway's corresponding plugin details.
	$plugin_data = PluginsHelper::get_plugin_data( $plugin_slug );
	if ( ! empty( $plugin_data ) ) {
		// If there are no links, try to get them from the plugin data.
		if ( empty( $gateway_details['links'] ) ) {
			if ( is_array( $plugin_data ) && ! empty( $plugin_data['PluginURI'] ) ) {
				$gateway_details['links'] = array(
					array(
						'_type' => ExtensionSuggestions::LINK_TYPE_ABOUT,
						'url'   => esc_url( $plugin_data['PluginURI'] ),
					),
				);
			} elseif ( ! empty( $gateway_details['plugin']['_type'] ) &&
						ExtensionSuggestions::PLUGIN_TYPE_WPORG === $gateway_details['plugin']['_type'] ) {

				// Fallback to constructing the WPORG plugin URI from the normalized plugin slug.
				$gateway_details['links'] = array(
					array(
						'_type' => ExtensionSuggestions::LINK_TYPE_ABOUT,
						'url'   => 'https://wordpress.org/plugins/' . $normalized_plugin_slug,
					),
				);
			}
		}
	}

	return $gateway_details;
}