Automattic\WooCommerce\Admin\Features\PaymentGatewaySuggestions

PaymentGatewaysController::handle_successfull_connection()public staticWC 1.0

Handle a successful gateway connection.

{} It's a method of the class: PaymentGatewaysController{}

No Hooks.

Return

null. Nothing.

Usage

$result = PaymentGatewaysController::handle_successfull_connection( $gateway_id );
$gateway_id(string) (required)
Gateway ID.

Code of PaymentGatewaysController::handle_successfull_connection() WC 7.1.0

public static function handle_successfull_connection( $gateway_id ) {
	// phpcs:disable WordPress.Security.NonceVerification
	if ( ! isset( $_GET['success'] ) || 1 !== intval( $_GET['success'] ) ) {
		return;
	}
	// phpcs:enable WordPress.Security.NonceVerification

	$payment_gateways = WC()->payment_gateways()->payment_gateways();
	$payment_gateway  = isset( $payment_gateways[ $gateway_id ] ) ? $payment_gateways[ $gateway_id ] : null;

	if ( ! $payment_gateway ) {
		return;
	}

	$payment_gateway->update_option( 'enabled', 'yes' );

	TransientNotices::add(
		array(
			'user_id' => get_current_user_id(),
			'id'      => 'payment-gateway-connection-return-' . str_replace( ',', '-', $gateway_id ),
			'status'  => 'success',
			'content' => sprintf(
				/* translators: the title of the payment gateway */
				__( '%s connected successfully', 'woocommerce' ),
				$payment_gateway->method_title
			),
		)
	);

	wc_admin_record_tracks_event(
		'tasklist_payment_connect_method',
		array(
			'payment_method' => $gateway_id,
		)
	);

	wp_safe_redirect( wc_admin_url() );
}