' . esc_html__('Settings', 'addtowallet-for-bookly') . '' ); return $links; } /** * @param string $tab design, passes, settings or help; '' for the default. * @param array $args Extra query arguments. */ public static function url($tab = '', $args = []) { $query = ['page' => ATW_Bookly_Settings::PAGE]; if ($tab !== '') { $query['tab'] = $tab; } return add_query_arg($query + $args, admin_url('admin.php')); } /** Tabs, in order. */ private static function tabs() { return [ 'design' => __('Pass design', 'addtowallet-for-bookly'), 'passes' => __('Bookings & passes', 'addtowallet-for-bookly'), 'settings' => __('Settings', 'addtowallet-for-bookly'), 'help' => __('Help', 'addtowallet-for-bookly'), ]; } /** * The tab being shown. 1.0.0's "instructions" and "support" tabs became Help, so old * bookmarks still land somewhere sensible. */ public static function current_tab() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only tab switch. $tab = isset($_GET['tab']) ? sanitize_key(wp_unslash($_GET['tab'])) : ''; if ($tab === 'instructions' || $tab === 'support') { return 'help'; } return array_key_exists($tab, self::tabs()) ? $tab : 'design'; } private static function connected() { $settings = ATW_Bookly_Settings::get(); return $settings['api_key'] !== ''; } /* ------------------------------------------------------------------ assets */ public static function assets($hook) { if ($hook !== 'toplevel_page_' . ATW_Bookly_Settings::PAGE) { return; } $tab = self::current_tab(); wp_enqueue_style('atw-bookly-admin', ATW_BOOKLY_URL . 'assets/css/admin.css', [], ATW_BOOKLY_VERSION); if ($tab === 'design' && self::connected()) { wp_enqueue_media(); wp_enqueue_script('atw-bookly-admin', ATW_BOOKLY_URL . 'assets/js/admin.js', ['jquery'], ATW_BOOKLY_VERSION, true); $settings = ATW_Bookly_Settings::get(); $preview = self::preview_booking(); wp_localize_script( 'atw-bookly-admin', 'AtwBooklyAdmin', [ 'tokens' => ATW_Bookly_Template::tokens(), 'sample' => ATW_Bookly_Template::values($preview), 'sampleType' => isset($preview['hero_key']) ? (string) $preview['hero_key'] : '', 'bookingId' => (string) $preview['booking_id'], 'businessName' => ATW_Bookly_Template::business()['name'], 'defaultLogo' => ATW_Bookly_Settings::site_icon_url(), 'maxBack' => ATW_Bookly_Template::MAX_BACK, 'maxHero' => ATW_Bookly_Template::MAX_HERO_RULES, 'types' => self::hero_targets(), 'insert' => __('Insert a data field', 'addtowallet-for-bookly'), 'insertShort' => __('Data Field', 'addtowallet-for-bookly'), 'chooseLogo' => __('Choose a logo', 'addtowallet-for-bookly'), 'chooseImage' => __('Choose an image', 'addtowallet-for-bookly'), 'useImage' => __('Use this image', 'addtowallet-for-bookly'), 'change' => __('Change', 'addtowallet-for-bookly'), 'chooseLabel' => __('Choose image', 'addtowallet-for-bookly'), 'mainImage' => __('Main image', 'addtowallet-for-bookly'), 'noImage' => __('No image', 'addtowallet-for-bookly'), 'details' => __('Details', 'addtowallet-for-bookly'), 'backDefaults' => [ 'text' => __('Info', 'addtowallet-for-bookly'), 'link' => __('Website', 'addtowallet-for-bookly'), 'phone' => __('Phone', 'addtowallet-for-bookly'), 'email' => __('Email', 'addtowallet-for-bookly'), 'address' => __('Address', 'addtowallet-for-bookly'), ], 'backColour' => $settings['background_color'], ] ); } if ($tab === 'help') { wp_enqueue_script('atw-bookly-support', ATW_BOOKLY_URL . 'assets/js/support.js', [], ATW_BOOKLY_VERSION, true); wp_localize_script( 'atw-bookly-support', 'AtwBooklySupport', [ 'url' => ATW_Bookly_Support::url(), 'nonce' => wp_create_nonce('wp_rest'), 'sending' => __('Sending…', 'addtowallet-for-bookly'), 'sent' => __('Sent. We will be in touch.', 'addtowallet-for-bookly'), ] ); } } /* ----------------------------------------------------------------- notices */ /** * @param string $type success, error, warning or info. * @param string $message Plain text. */ private static function notice($type, $message) { set_transient('atw_bookly_notice_' . get_current_user_id(), [$type, $message], MINUTE_IN_SECONDS); } private static function render_notice() { $key = 'atw_bookly_notice_' . get_current_user_id(); $notice = get_transient($key); if (!is_array($notice) || count($notice) !== 2) { return; } delete_transient($key); $type = in_array($notice[0], ['success', 'error', 'warning', 'info'], true) ? $notice[0] : 'info'; printf( '

%2$s

', esc_attr($type), esc_html((string) $notice[1]) ); } private static function require_admin($nonce_action) { if (!current_user_can('manage_options')) { wp_die(esc_html__('You do not have permission to do that.', 'addtowallet-for-bookly'), '', ['response' => 403]); } check_admin_referer($nonce_action); } /* ---------------------------------------------------------------- handlers */ /** * Saves an API key, but only after AddToWallet has accepted it: the credits endpoint * needs a valid key, so reading the balance is the check. A key that fails is never * stored, so a typo cannot silently stop passes being issued. */ public static function handle_connect() { self::require_admin('atw_bookly_connect'); // phpcs:disable WordPress.Security.NonceVerification.Missing -- checked in require_admin(). $key = isset($_POST['atw_bookly_api_key']) ? trim(sanitize_text_field(wp_unslash($_POST['atw_bookly_api_key']))) : ''; $back = isset($_POST['atw_bookly_return']) && sanitize_key(wp_unslash($_POST['atw_bookly_return'])) === 'settings' ? 'settings' : 'design'; // phpcs:enable WordPress.Security.NonceVerification.Missing if ($key === '') { self::notice('error', __('Paste your API key first.', 'addtowallet-for-bookly')); } else { $credits = ATW_Bookly_Api_Client::get_credits(['api_key' => $key], true); if (is_wp_error($credits)) { $message = $credits->get_error_code() === 'atw_bad_api_key' ? __('AddToWallet did not accept that API key. Check it was copied in full and try again.', 'addtowallet-for-bookly') /* translators: %s: the error from AddToWallet. */ : sprintf(__('Could not check the key with AddToWallet: %s Try again in a moment.', 'addtowallet-for-bookly'), $credits->get_error_message()); self::notice('error', $message); } else { ATW_Bookly_Settings::update(['api_key' => $key]); self::notice('success', __('Connected to AddToWallet. New bookings now get a wallet pass.', 'addtowallet-for-bookly')); } } wp_safe_redirect(self::url($back)); exit; } public static function handle_disconnect() { self::require_admin('atw_bookly_disconnect'); ATW_Bookly_Settings::update(['api_key' => '']); self::notice('success', __('Disconnected. No new passes will be created; passes already issued keep working.', 'addtowallet-for-bookly')); wp_safe_redirect(self::url('design')); exit; } public static function handle_save_design() { self::require_admin('atw_bookly_save_design'); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing -- nonce checked in require_admin(); every value is sanitised below and in ATW_Bookly_Template::sanitize(). $raw = isset($_POST['atw_bookly']) && is_array($_POST['atw_bookly']) ? map_deep(wp_unslash($_POST['atw_bookly']), 'strval') : []; $changes = ['template' => ATW_Bookly_Template::sanitize($raw)]; foreach (['logo_url', 'hero_image'] as $key) { if (isset($raw[$key])) { $changes[$key] = esc_url_raw(trim($raw[$key]), ['http', 'https']); } } if (isset($raw['background_color'])) { $colour = ATW_Bookly_Settings::normalize_hex($raw['background_color']); if ($colour !== '') { $changes['background_color'] = $colour; } } if (isset($raw['barcode_type'])) { $barcode = strtoupper(sanitize_text_field($raw['barcode_type'])); $changes['barcode_type'] = in_array($barcode, ATW_Bookly_Settings::BARCODE_TYPES, true) ? $barcode : 'QR_CODE'; } ATW_Bookly_Settings::update($changes); self::notice('success', __('Pass design saved. Bookings from now on get passes with this design.', 'addtowallet-for-bookly')); wp_safe_redirect(self::url('design')); exit; } public static function handle_save_settings() { self::require_admin('atw_bookly_save_settings'); // phpcs:disable WordPress.Security.NonceVerification.Missing -- checked in require_admin(). $issue = isset($_POST['atw_bookly_allowed']) ? array_map('sanitize_key', (array) wp_unslash($_POST['atw_bookly_allowed'])) : []; $expire = isset($_POST['atw_bookly_expire']) ? array_map('sanitize_key', (array) wp_unslash($_POST['atw_bookly_expire'])) : []; $label = isset($_POST['atw_bookly_button_label']) ? sanitize_text_field(wp_unslash($_POST['atw_bookly_button_label'])) : ''; $label = function_exists('mb_substr') ? mb_substr($label, 0, 60) : substr($label, 0, 60); $debug = empty($_POST['atw_bookly_debug']) ? 0 : 1; // phpcs:enable WordPress.Security.NonceVerification.Missing $issue = array_values(array_intersect(ATW_Bookly_Settings::ISSUABLE_STATUSES, $issue)); ATW_Bookly_Settings::update([ // At least one status has to issue passes, or the plugin does nothing at all. 'allowed_statuses' => $issue ? $issue : ['approved'], // Unlike issuing, none ticked is a valid choice: it turns expiry off. 'expire_statuses' => array_values(array_intersect(ATW_Bookly_Settings::EXPIRABLE_STATUSES, $expire)), 'button_label' => $label !== '' ? $label : ATW_Bookly_Settings::defaults()['button_label'], 'debug' => $debug, ]); if ($issue) { self::notice('success', __('Settings saved.', 'addtowallet-for-bookly')); } else { self::notice('warning', __('Settings saved. At least one status has to issue passes, so Approved stays ticked.', 'addtowallet-for-bookly')); } wp_safe_redirect(self::url('settings')); exit; } /* -------------------------------------------------------------------- page */ public static function page() { if (!current_user_can('manage_options')) { return; } $tab = self::current_tab(); $connected = self::connected(); echo '
'; echo '
'; echo ''; echo '

' . esc_html__('AddToWallet for Bookly', 'addtowallet-for-bookly') . '

'; echo $connected ? '' . esc_html__('Connected', 'addtowallet-for-bookly') . '' : '' . esc_html__('Not connected', 'addtowallet-for-bookly') . ''; echo '

'; self::render_notice(); echo ''; if (!ATW_Bookly_Providers::available()) { echo '

' . esc_html__('Bookly is not active, so this plugin stays dormant until it is.', 'addtowallet-for-bookly') . '

'; } call_user_func([__CLASS__, 'tab_' . $tab]); echo '
'; } /* ---------------------------------------------------------------- connect */ /** The links to create an account and find the API key. */ private static function signup_url() { return untrailingslashit(ATW_BOOKLY_API_BASE) . '/'; } private static function api_key_url() { // The key is shown at the top of the dashboard's sidebar; this page says so. return untrailingslashit(ATW_BOOKLY_API_BASE) . '/api-docs/direct-api/authentication'; } private static function pricing_url() { return untrailingslashit(ATW_BOOKLY_API_BASE) . '/pricing/bookly'; } /** * The API key form. The key is never echoed back: the field is always empty and the * stored key is only ever shown masked. * * @param string $return Tab to come back to. * @param string $button Button label. */ private static function key_form($return, $button) { echo '
'; wp_nonce_field('atw_bookly_connect'); echo ''; echo ''; echo ''; echo '
'; echo '
'; echo '
'; } private static function render_connect() { echo '
'; echo '

' . esc_html__('Connect your account', 'addtowallet-for-bookly') . '

'; echo '

' . wp_kses( sprintf( /* translators: 1: sign-up link, 2: API key page link. */ __('You need an AddToWallet account (create one free). Then copy your API key from the top of the sidebar in the AddToWallet dashboard (where to find it) and paste it here.', 'addtowallet-for-bookly'), esc_url(self::signup_url()), esc_url(self::api_key_url()) ), ['a' => ['href' => [], 'target' => [], 'rel' => []]] ) . '

'; self::key_form('design', __('Connect', 'addtowallet-for-bookly')); echo '

' . esc_html__('The key is checked with AddToWallet before it is saved. It stays on this server and is never sent to visitors\' browsers.', 'addtowallet-for-bookly') . '

'; echo '
'; } /* ---------------------------------------------------------------- design */ /** key => label of Bookly's services, for hero image variations. */ private static function hero_targets() { $provider = ATW_Bookly_Providers::get('bookly'); if (!$provider || !$provider->is_available() || !method_exists($provider, 'hero_targets')) { return []; } return $provider->hero_targets(); } /** * The booking the preview is filled in with: the most recent real one, so the * merchant sees their own data, or a made-up one on a site with no bookings yet. */ private static function preview_booking() { $provider = ATW_Bookly_Providers::get('bookly'); if ($provider && $provider->is_available()) { $latest = $provider->list_bookings(1, 0); if ($latest) { $booking = $latest[0]; $booking['real'] = true; return $booking; } } return ATW_Bookly_Template::sample_booking(); } private static function panel_open($title, $help, $class = '') { echo '

' . esc_html($title) . '

' . esc_html($help) . '

'; } private static function panel_close() { echo '
'; } /** A labelled one-line text input that takes {data fields}. */ private static function text_field($key, $label, $value, $help = '', $placeholder = '', $max = 0, $tokens = true) { $id = 'atw-bookly-' . $key; echo '
'; echo ''; if ($help !== '') { echo '' . esc_html($help) . ''; } echo '
'; } /** * Whether AddToWallet could download a URL: false for localhost, *.local / *.test / * *.localhost / *.internal names and private or loopback IP addresses, which is what a * staging or development site usually has. */ public static function is_public_url($url) { $host = strtolower((string) wp_parse_url((string) $url, PHP_URL_HOST)); if ($host === '' || $host === 'localhost') { return false; } if (preg_match('/\.(local|test|localhost|internal|invalid|example)$/', $host)) { return false; } if (filter_var($host, FILTER_VALIDATE_IP)) { return (bool) filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE); } return true; } /** One back section's inputs. $i is the index, or "__i__" in the template. */ private static function back_row($i, $section) { $base = 'atw_bookly[back][' . $i . ']'; $types = [ 'text' => __('Text', 'addtowallet-for-bookly'), 'link' => __('Link', 'addtowallet-for-bookly'), 'phone' => __('Phone', 'addtowallet-for-bookly'), 'email' => __('Email', 'addtowallet-for-bookly'), 'address' => __('Address', 'addtowallet-for-bookly'), ]; echo '
'; echo ''; echo ''; echo ''; echo ''; echo '
'; } /** * One hero image card. $i is the variation's index ("__i__" in the template), or '' * for the main image every other booking gets. */ private static function hero_card($i, $url, $type_id, $types) { $main = $i === ''; echo '
  • '; if ($main) { echo ''; } else { echo ''; echo ''; } echo '
  • '; } private static function tab_design() { if (!self::connected()) { self::render_connect(); return; } $s = ATW_Bookly_Settings::get(); $t = $s['template']; $tokens = ATW_Bookly_Template::tokens(); $booking = self::preview_booking(); $values = ATW_Bookly_Template::values($booking); $business = ATW_Bookly_Template::business(); $icon = ATW_Bookly_Settings::site_icon_url(); $logo = $s['logo_url'] !== '' ? $s['logo_url'] : $icon; $issued = ATW_Bookly_Pass_Store::count('bookly'); $types = self::hero_targets(); echo '
    '; wp_nonce_field('atw_bookly_save_design'); echo ''; echo '
    '; echo '
    ' . esc_html__('Every new booking gets its own pass.', 'addtowallet-for-bookly') . ' '; /* translators: %s: number of passes. */ echo esc_html(sprintf(_n('%s issued so far.', '%s issued so far.', $issued, 'addtowallet-for-bookly'), number_format_i18n($issued))) . ' '; echo esc_html__('Use "+ Data Field" to put the booking\'s details on it.', 'addtowallet-for-bookly') . '
    '; // Brand. self::panel_open(__('Brand', 'addtowallet-for-bookly'), __('How your business appears at the top of every pass.', 'addtowallet-for-bookly'), 'atw-bookly-brand'); echo '
    '; echo '
    '; echo '
    '; echo ''; echo '
    '; echo ''; echo ''; echo ''; foreach (self::SWATCHES as $swatch) { echo ''; } echo '
    '; echo ''; if ($logo !== '' && !self::is_public_url($logo)) { echo '' . esc_html__('AddToWallet downloads the logo to build each pass, and this address is not reachable from the internet (a local or private address). Passes will fail until the logo is on a public site.', 'addtowallet-for-bookly') . ' '; } if ($icon === '' && $s['logo_url'] === '') { echo '' . esc_html__('Choose a logo: there is no site icon to fall back on, and AddToWallet will not create a pass without one.', 'addtowallet-for-bookly') . ' '; } else { echo esc_html__('A square PNG logo works best; "Use default" uses your site icon.', 'addtowallet-for-bookly') . ' '; } /* translators: %s: the business name from Bookly's settings. */ echo esc_html(sprintf(__('Leave the name blank to use "%s" from Bookly. Text on the pass switches between black and white, whichever reads best.', 'addtowallet-for-bookly'), $business['name'])) . ''; self::panel_close(); // Front. self::panel_open(__('Front', 'addtowallet-for-bookly'), __('The title and up to three short fields people see at a glance.', 'addtowallet-for-bookly')); self::text_field('header', __('Header line', 'addtowallet-for-bookly'), $t['header'], __('A short line above the title, such as the customer\'s name. Optional.', 'addtowallet-for-bookly'), '', 80); /* translators: %s: a data field, {service}. */ self::text_field('title', __('Pass title', 'addtowallet-for-bookly'), $t['title'], sprintf(__('The big line. For example %s, the service booked.', 'addtowallet-for-bookly'), '{service}'), '', 100); echo '
    ' . esc_html__('Fields', 'addtowallet-for-bookly') . '
    '; foreach ($t['fields'] as $i => $field) { echo '
    '; echo ''; echo ''; echo '
    '; } echo '
    ' . esc_html__('A field whose value is empty for a booking is left off, and the others close up.', 'addtowallet-for-bookly') . '
    '; self::panel_close(); // Back. self::panel_open(__('Back', 'addtowallet-for-bookly'), __('Details people see when they open the pass: how to reach you, where to go, what to bring.', 'addtowallet-for-bookly')); echo '
    '; foreach ($t['back'] as $i => $section) { self::back_row($i, $section); } echo '
    '; echo ''; echo ''; /* translators: %d: how many sections. */ echo '' . esc_html(sprintf(__('Up to %d sections. Phone, Email and Address sections can be tapped on the pass. A section that comes out empty for a booking is left off.', 'addtowallet-for-bookly'), ATW_Bookly_Template::MAX_BACK)) . ''; self::panel_close(); // Advanced. self::panel_open(__('Advanced', 'addtowallet-for-bookly'), __('A hero image, the barcode, and the Wallet reminder.', 'addtowallet-for-bookly'), 'atw-bookly-advanced'); echo '
    ' . esc_html__('Hero image', 'addtowallet-for-bookly') . ''; echo '
      '; self::hero_card('', $s['hero_image'], '', $types); foreach ($t['hero_rules'] as $i => $rule) { self::hero_card((string) $i, $rule['url'], (string) $rule['type_id'], $types); } if ($types) { $covered = array_intersect(array_map('strval', array_keys($types)), array_map('strval', wp_list_pluck($t['hero_rules'], 'type_id'))); $full = count($covered) >= count($types) || count($t['hero_rules']) >= ATW_Bookly_Template::MAX_HERO_RULES; echo '
    1. '; } echo '
    '; if ($types) { echo ''; } echo '' . esc_html( $types ? __('The wide image across the pass on iPhone and at the bottom on Android. Optional. Add a variation to give one service its own image; every other booking gets the main one.', 'addtowallet-for-bookly') : __('The wide image across the pass on iPhone and at the bottom on Android. Optional.', 'addtowallet-for-bookly') ) . '
    '; // The hero card editor. echo ''; echo '

    '; echo '
    '; echo '
    '; if ($types) { echo '
    '; echo '
    '; } echo '

    ' . esc_html__('Wide images work best; the pass shows a strip roughly four times as wide as it is tall.', 'addtowallet-for-bookly') . '

    '; echo '
    '; echo ''; echo '
    '; echo '
    '; echo '
    ' . esc_html__('Barcode', 'addtowallet-for-bookly') . ''; echo '
    '; foreach (ATW_Bookly_Settings::BARCODE_TYPES as $type) { echo ''; } echo '
    ' . esc_html__('Encodes the booking number, so staff can scan the customer in. QR suits phone cameras and most scanners.', 'addtowallet-for-bookly') . '
    '; echo '
    ' . esc_html__('Reminder', 'addtowallet-for-bookly') . ''; echo ''; echo '' . esc_html__('iPhone brings the pass up on the lock screen at the appointment time; Google Wallet sends a reminder before it.', 'addtowallet-for-bookly') . '
    '; self::panel_close(); echo '
    '; // .atw-bookly-editor echo '
    '; echo '
    ' . esc_html__('Each new booking uses one pass credit. Saving applies to passes issued from now on.', 'addtowallet-for-bookly') . ''; echo '
    '; echo '
    '; } /** * The live preview: the pass as Apple Wallet and Google Wallet draw it, front and * back, filled in with a booking. admin.js redraws it as the form changes; this is the * first paint, so the page is right before any script runs. */ private static function preview($s, $t, $values, $logo, $booking) { $fill = function ($text) use ($values) { return ATW_Bookly_Template::fill($text, $values); }; $name = $fill($t['business_name']); $name = $name !== '' ? $name : $values['business_name']; $ink = ATW_Bookly_Pass_Builder::font_color($s['background_color']); $style = 'background:' . $s['background_color'] . ';color:' . $ink; $hero = ATW_Bookly_Pass_Builder::hero($s, $booking); $fields = []; foreach ($t['fields'] as $field) { $value = $fill($field['value']); if ($value !== '') { $fields[] = ['label' => $fill($field['label']), 'value' => $value]; } } $fields_html = function ($class) use ($fields) { echo '
    '; foreach ($fields as $field) { echo '
    ' . esc_html($field['label']) . '
    ' . esc_html($field['value']) . '
    '; } echo '
    '; }; $logo_html = function ($class) use ($logo, $name) { $initial = function_exists('mb_substr') ? mb_substr($name, 0, 1) : substr($name, 0, 1); echo ''; echo '' . esc_html($initial) . ''; }; $code_html = function () use ($s) { echo '
    '; }; $strip_html = function ($class) use ($hero) { echo '
    '; }; echo '
    '; echo '
    '; echo '
    '; echo ''; echo '
    '; echo '
    '; echo ''; echo '
    '; echo '
    '; echo '
    '; // Apple Wallet, front. echo '
    '; echo '
    '; $logo_html('atw-bookly-apple-logo'); echo '' . esc_html($name) . '
    '; $strip_html('atw-bookly-apple-strip'); echo '
    ' . esc_html($fill($t['header'])) . '
    '; echo '
    ' . esc_html($fill($t['title'])) . '
    '; $fields_html('atw-bookly-apple-fields'); $code_html(); echo '
    '; // Apple Wallet, back: the pass details screen. echo '
    '; echo '
    '; $logo_html('atw-bookly-apple-logo'); echo '' . esc_html($name) . '
    '; echo '
    ' . esc_html($fill($t['header'])) . '
    '; echo '
    ' . esc_html($fill($t['title'])) . '
    '; echo '
    ' . esc_html($name) . '
    '; echo '
    ' . esc_html__('Automatic Updates', 'addtowallet-for-bookly') . '
    '; echo '
    ' . esc_html__('Allow Notifications', 'addtowallet-for-bookly') . '
    '; echo '
    '; echo '
    ' . esc_html__('Remove Pass', 'addtowallet-for-bookly') . '
    '; echo '
    '; // Google Wallet, front. echo '
    '; echo '
    '; $logo_html('atw-bookly-google-logo'); echo '' . esc_html($name) . '
    '; echo '
    '; echo '
    ' . esc_html($fill($t['header'])) . '
    '; echo '
    ' . esc_html($fill($t['title'])) . '
    '; $fields_html('atw-bookly-google-fields'); $code_html(); $strip_html('atw-bookly-google-hero'); echo '
    '; // Google Wallet, back: the Details sheet. echo '
    '; echo '
    ' . esc_html__('Details', 'addtowallet-for-bookly') . '
    '; $logo_html('atw-bookly-gd-logo'); echo '
    ' . esc_html($fill($t['title'])) . '
    '; echo '
    '; echo '

    ' . esc_html__('The pass provider or merchant is responsible for the info on this pass and may send you notifications.', 'addtowallet-for-bookly') . '

    '; echo '
    '; echo '
    '; // .atw-bookly-stage $note = !empty($booking['real']) /* translators: %s: booking number. */ ? sprintf(__('A close preview, filled in with your latest booking (#%s).', 'addtowallet-for-bookly'), $booking['booking_id']) : __('A close preview, filled in with a sample booking.', 'addtowallet-for-bookly'); echo '

    ' . esc_html($note) . '

    '; } /* ---------------------------------------------------------------- passes */ private static function tab_passes() { ATW_Bookly_Passes_List::render(); } /* -------------------------------------------------------------- settings */ /** The stored key as bullets and its last four characters. */ private static function masked_key($key) { $tail = strlen($key) > 8 ? substr($key, -4) : ''; return str_repeat('•', 12) . $tail; } private static function tab_settings() { $s = ATW_Bookly_Settings::get(); // Account. echo '

    ' . esc_html__('Account', 'addtowallet-for-bookly') . '

    '; echo '' . esc_html__('View plans and top up credits', 'addtowallet-for-bookly') . ' ↗
    '; if ($s['api_key'] === '') { echo '

    ' . esc_html__('Not connected. Paste your AddToWallet API key to start issuing passes.', 'addtowallet-for-bookly') . '

    '; self::key_form('settings', __('Connect', 'addtowallet-for-bookly')); echo '
    '; } else { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- only bypasses a read cache. $force = isset($_GET['atw_refresh']); $credits = ATW_Bookly_Api_Client::get_credits($s, $force); $refresh = add_query_arg('atw_refresh', '1', self::url('settings')); echo '
    '; echo '
    ' . esc_html__('Status', 'addtowallet-for-bookly') . '
    ' . esc_html__('Connected', 'addtowallet-for-bookly') . '
    '; echo '
    ' . esc_html__('Pass credits left', 'addtowallet-for-bookly') . '
    '; if (is_array($credits)) { /** * Same threshold as the app's LowCreditsBanner: 10% of everything the * account has ever had, paid and free. */ $empty = $credits['remaining'] === 0; $low = !$empty && $credits['total'] > 0 && $credits['remaining'] <= max(1, (int) ceil($credits['total'] * 0.1)); echo '' . esc_html(number_format_i18n($credits['remaining'])) . ''; echo ''; printf( /* translators: 1: paid credits left, 2: free passes left, 3: free pass allowance */ esc_html__('%1$s paid · %2$s of %3$s free', 'addtowallet-for-bookly'), esc_html(number_format_i18n($credits['paid'])), esc_html(number_format_i18n($credits['free'])), esc_html(number_format_i18n($credits['free_total'])) ); echo ''; echo '' . esc_html__('Refresh', 'addtowallet-for-bookly') . ''; if ($empty) { echo '' . esc_html__('Free pass limit reached and no credits available. No passes will be created until you top up.', 'addtowallet-for-bookly') . ''; } elseif ($low) { echo '' . esc_html__('You\'re running low on credits.', 'addtowallet-for-bookly') . ''; } } elseif (is_wp_error($credits)) { echo '' . esc_html($credits->get_error_message()) . ' ' . esc_html__('Retry', 'addtowallet-for-bookly') . ''; } echo '
    '; echo '
    ' . esc_html__('API key', 'addtowallet-for-bookly') . '
    ' . esc_html(self::masked_key($s['api_key'])) . '
    '; echo '
    '; echo '

    ' . esc_html__('Every pass issued draws one credit. When the balance runs out, bookings still go through but no pass is created, so this is the first thing to check if passes stop appearing. The key stays on this server and is never sent to visitors\' browsers.', 'addtowallet-for-bookly') . '

    '; echo '
    ' . esc_html__('Replace API key', 'addtowallet-for-bookly') . ''; self::key_form('settings', __('Replace key', 'addtowallet-for-bookly')); echo '
    '; echo '
    '; wp_nonce_field('atw_bookly_disconnect'); echo ''; echo ''; echo '
    '; } // Rules and options. echo '
    '; wp_nonce_field('atw_bookly_save_settings'); echo ''; echo '
    '; echo '

    ' . esc_html__('Which bookings get a pass', 'addtowallet-for-bookly') . '

    '; echo '

    ' . esc_html__('A booking can be accepted before it is confirmed. Only the statuses ticked here get a pass.', 'addtowallet-for-bookly') . '

    '; echo '
    '; foreach (ATW_Bookly_Settings::ISSUABLE_STATUSES as $status) { self::status_option('atw_bookly_allowed[]', $status, in_array($status, $s['allowed_statuses'], true)); } echo '
    '; echo '

    ' . esc_html__('Which bookings expire their pass', 'addtowallet-for-bookly') . '

    '; echo '

    ' . esc_html__('The pass already in the customer\'s wallet is marked expired straight away, so it stops looking like an appointment to turn up for. Untick to leave issued passes alone.', 'addtowallet-for-bookly') . '

    '; echo '
    '; foreach (ATW_Bookly_Settings::EXPIRABLE_STATUSES as $status) { self::status_option('atw_bookly_expire[]', $status, in_array($status, $s['expire_statuses'], true)); } echo '

    ' . esc_html__('Expiring a pass does not refund the credit it was created with.', 'addtowallet-for-bookly') . '

    '; echo '
    '; echo '

    ' . esc_html__('Confirmation screen', 'addtowallet-for-bookly') . '

    '; echo '
    '; echo ''; echo '' . esc_html__('Shown on the single button used when the official Apple and Google badges cannot be.', 'addtowallet-for-bookly') . '
    '; echo ''; echo '' . esc_html__('Logs what the button does to the browser console, and pass expiry to the PHP error log.', 'addtowallet-for-bookly') . ''; echo '
    '; echo '

    '; echo '
    '; } private static function status_option($name, $status, $checked) { echo ''; } /* ------------------------------------------------------------------ help */ private static function tab_help() { $s = ATW_Bookly_Settings::get(); $issued = ATW_Bookly_Pass_Store::count('bookly'); $apple = ATW_BOOKLY_URL . 'assets/img/add_to_apple_wallet.png'; $google = ATW_BOOKLY_URL . 'assets/img/add_to_google_wallet_add-wallet.png'; $on = $s['api_key'] !== '' && ATW_Bookly_Providers::available(); echo '
    '; // Where customers get their pass. echo '
    '; echo '

    ' . esc_html__('Bookly', 'addtowallet-for-bookly') . '

    ' . esc_html__('A wallet pass for every appointment', 'addtowallet-for-bookly') . '

    '; echo '' . esc_html($on ? __('On', 'addtowallet-for-bookly') : __('Off', 'addtowallet-for-bookly')) . '
    '; /* translators: %s: number of passes. */ echo '

    ' . esc_html(sprintf(_n('%s pass issued', '%s passes issued', $issued, 'addtowallet-for-bookly'), number_format_i18n($issued))) . ' ' . esc_html__('See bookings', 'addtowallet-for-bookly') . '

    '; echo '

    ' . esc_html__('Where customers get their pass', 'addtowallet-for-bookly') . '

      '; echo '
    • ' . esc_html__('Booking confirmation', 'addtowallet-for-bookly') . ' ' . esc_html__('automatic', 'addtowallet-for-bookly') . ''; echo '' . esc_html__('On the last step of Bookly\'s booking form, above its Start over button, wherever the form is placed: shortcode, block or Elementor widget.', 'addtowallet-for-bookly') . '
    '; echo '
    ' . esc_attr__('Add to Apple Wallet', 'addtowallet-for-bookly') . '' . esc_attr__('Add to Google Wallet', 'addtowallet-for-bookly') . '
    '; echo '

    ' . esc_html__('Both wallets are always offered, because someone may book on a laptop and carry a phone that uses the other one. The wallet matching their device comes first. While the pass is being created they see a "Preparing your pass" button in its place.', 'addtowallet-for-bookly') . '

    '; echo ''; echo '
    '; // Getting set up. echo '

    ' . esc_html__('Getting set up', 'addtowallet-for-bookly') . '

      '; echo '
    1. ' . wp_kses( sprintf( /* translators: %s: link to the Pass design tab */ __('Connect your AddToWallet account on the %s tab.', 'addtowallet-for-bookly'), '' . esc_html__('Pass design', 'addtowallet-for-bookly') . '' ), ['a' => ['href' => []]] ) . '
    2. '; echo '
    3. ' . esc_html__('Design the pass: your logo and colour, then what the front and back say. "+ Data Field" fills in each booking\'s details.', 'addtowallet-for-bookly') . '
    4. '; echo '
    5. ' . esc_html__('On Settings, choose which booking statuses issue a pass, and which expire one.', 'addtowallet-for-bookly') . '
    6. '; echo '
    7. ' . esc_html__('Make a test booking and check the buttons appear on the confirmation screen.', 'addtowallet-for-bookly') . '
    8. '; echo '
    '; echo '
    '; echo '
    '; echo '

    ' . esc_html__('Quick answers', 'addtowallet-for-bookly') . '

    '; $answers = [ __('No buttons appear after booking', 'addtowallet-for-bookly') => __('Usually one of three things: you are out of credits; the booking has a status you do not issue passes for (a service that needs approval books as Pending); or the customer is sent to another page after booking (a WooCommerce checkout, or a service\'s "Final step URL"), so Bookly never shows its last step. Bookings & passes lists every booking and whether it got a pass.', 'addtowallet-for-bookly'), __('Which bookings get a pass?', 'addtowallet-for-bookly') => __('Approved bookings only, unless you say otherwise on Settings. A pending booking or a waiting-list place is not confirmed yet, so issuing a pass for it can put an appointment in someone\'s wallet that never happens. A booking is only ever charged for one pass, however many times the confirmation screen is reloaded.', 'addtowallet-for-bookly'), __('What happens when a booking is cancelled or moved?', 'addtowallet-for-bookly') => __('Cancelled, rejected and deleted bookings have their pass marked expired straight away, whether you change it in Bookly or the customer uses their own cancel link. When an appointment is rescheduled, or you change its staff member or service, the pass already in the wallet is updated, without using another credit. Changes made outside Bookly\'s own screens are picked up within ten minutes.', 'addtowallet-for-bookly'), __('What uses credits?', 'addtowallet-for-bookly') => __('Each pass costs one credit. If your balance runs out, bookings carry on as normal but no pass is created. Expiring a pass does not return its credit.', 'addtowallet-for-bookly'), __('Does changing the design update passes already issued?', 'addtowallet-for-bookly') => __('No. A saved design applies to passes created from then on. Passes already in customers\' wallets keep the design they were issued with.', 'addtowallet-for-bookly'), __('When does the reminder appear?', 'addtowallet-for-bookly') => __('With the reminder on, iPhone brings the pass up on the lock screen at the appointment time and Google Wallet sends a reminder before it.', 'addtowallet-for-bookly'), ]; foreach ($answers as $question => $answer) { echo '
    ' . esc_html($question) . '

    ' . esc_html($answer) . '

    '; } echo '

    ' . esc_html__('View plans and top up credits', 'addtowallet-for-bookly') . ' ↗

    '; echo '
    '; ATW_Bookly_Support::render(); echo '
    '; } }