namespace WPForms\Integrations\Square\Admin;
use WPForms\Admin\Notice;
use WPForms\Integrations\Square\Helpers;
use WPForms\Integrations\Square\Connection;
use WPForms\Integrations\Square\WebhooksHealthCheck;
* Square related admin notices.
private function hooks() {
add_action( 'wpforms_settings_init', [ $this, 'display_notice' ] );
* Display admin error notice if something wrong with the Square settings.
public function display_notice() {
$connection = Connection::get();
$this->maybe_display_notice( $connection );
* Maybe display admin notices in the settings area.
* @param Connection $connection Connection data.
private function maybe_display_notice( Connection $connection ) {
$all_notices = array_filter(
$this->maybe_get_notice( $connection ),
$this->maybe_get_webhook_notice(),
if ( empty( $all_notices ) ) {
esc_html__( 'There Are Some Problems With Your Square Connection', 'wpforms-lite' )
foreach ( $all_notices as $notice ) {
$message .= '<br/>' . $notice;
Notice::error( $message );
* Maybe get admin error notice if a connection exists, but is not ready to use.
* @param Connection $connection Connection object.
private function maybe_get_notice( Connection $connection ): string {
if ( ! $connection->is_configured() ) {
return esc_html__( 'Square account connection is missing required data. You must reconnect your Square account.', 'wpforms-lite' );
if ( ! $connection->is_valid() ) {
return esc_html__( 'Square account connection is invalid. You must reconnect your Square account.', 'wpforms-lite' );
if ( $connection->is_expired() ) {
return esc_html__( 'Square account connection is expired. Tokens must be refreshed.', 'wpforms-lite' );
if ( empty( Helpers::get_location_id() ) ) {
return esc_html__( 'Business Location is required to process Square payments.', 'wpforms-lite' );
if ( $connection->is_currency_matched() ) {
return sprintf( /* translators: %1$s - Selected currency on the WPForms Settings admin page; %2$s - Currency of a business location. */
esc_html__( 'The currency you have set (%1$s) does not match the currency of your Square business location (%2$s). Please choose a different business location or update your WPForms currency to %2$s.', 'wpforms-lite' ),
esc_html( wpforms_get_currency() ),
esc_html( $connection->get_currency() )
* Maybe get webhook notice if connection is not set.
private function maybe_get_webhook_notice(): string {
// Bail out if webhooks are not enabled.
if ( ! Helpers::is_webhook_enabled() ) {
// Bail out if webhooks are configured and active.
if ( Helpers::is_webhook_configured() ) {
// If ENDPOINT_OPTION is set, it says that webhooks were configured previously. We have another notice for this case.
if ( get_option( WebhooksHealthCheck::ENDPOINT_OPTION ) ) {
return esc_html__( 'Webhooks are enabled, but not yet connected.', 'wpforms-lite' );
* Get a notice if a license is insufficient not to be charged a fee.
* @param string $classes Additional notice classes.
public static function get_fee_notice( string $classes = '' ): string {
if ( ! Helpers::is_application_fee_supported() ) {
$is_allowed_license = Helpers::is_allowed_license_type();
$is_active_license = Helpers::is_license_active();
if ( $is_allowed_license && $is_active_license ) {
if ( ! $is_allowed_license ) {
$notice = self::get_non_pro_license_level_notice();
} elseif ( ! $is_active_license ) {
$notice = self::get_non_active_license_notice();
if ( wpforms_is_admin_page( 'builder' ) ) {
return sprintf( '<p class="wpforms-square-notice-info wpforms-alert wpforms-alert-info ' . wpforms_sanitize_classes( $classes ) . '">%s</p>', $notice );
return sprintf( '<div class="wpforms-square-notice-info ' . wpforms_sanitize_classes( $classes ) . '"><p>%s</p></div>', $notice );
* Get a fee notice for a non-active license.
* If the license is NOT set/activated, show the notice to activate it.
* Otherwise, show the notice to renew it.
private static function get_non_active_license_notice(): string {
$setting_page_url = add_query_arg(
'page' => 'wpforms-settings',
// The license is not set/activated at all.
if ( empty( wpforms_get_license_key() ) ) {
wp_kses( /* translators: %s - general admin settings page URL. */
__( '<strong>Pay-as-you-go Pricing</strong><br>3%% fee per-transaction + Square fees. <a href="%s">Activate your license</a> to remove additional fees and unlock powerful features.', 'wpforms-lite' ),
esc_url( $setting_page_url )
wp_kses( /* translators: %s - general admin settings page URL. */
__( '<strong>Pay-as-you-go Pricing</strong><br> 3%% fee per-transaction + Square fees. <a href="%s">Renew your license</a> to remove additional fees and unlock powerful features.', 'wpforms-lite' ),
esc_url( $setting_page_url )
* Get a fee notice for license levels below the `pro`.
* Show the notice to upgrade to Pro.
private static function get_non_pro_license_level_notice(): string {
$utm_content = 'Square Pro - Remove Fees';
$utm_medium = wpforms_is_admin_page( 'builder' ) ? 'Payment Settings' : 'Settings - Payments';
$upgrade_link = wpforms()->is_pro() ? wpforms_admin_upgrade_link( $utm_medium, $utm_content ) : wpforms_utm_link( 'https://wpforms.com/lite-upgrade/', $utm_medium, $utm_content );
wp_kses( /* translators: %s - WPForms.com Upgrade page URL. */
__( '<strong>Pay-as-you-go Pricing</strong><br> 3%% fee per-transaction + Square fees. <a href="%s" target="_blank">Upgrade to Pro</a> to remove additional fees and unlock powerful features.', 'wpforms-lite' ),