cap())) { wp_die(esc_html__('You do not have permission to access this page.', 'adverships-affiliate')); } echo '

' . esc_html__('Adverships — Dashboard', 'adverships-affiliate') . '

'; if (!Adverships_Affiliate_Client::is_connected()) { $this->render_not_connected(); echo '
'; return; } $res = Adverships_Affiliate_Client::post_signed('/api/wordpress/stats.php', array('recent_limit' => 20), true); if (is_wp_error($res) || empty($res['data']['ok'])) { $this->render_error($res); echo ''; return; } $d = $res['data']; $totals = isset($d['totals']) ? $d['totals'] : array(); $owed = isset($d['owed']) ? $d['owed'] : array(); $wallet = isset($d['wallet']) ? $d['wallet'] : array(); $recent = isset($d['recent_sales']) ? $d['recent_sales'] : array(); // --- Trial-ending countdown banner (most urgent; very top of page) --- Adverships_Affiliate_Trial::render_banner(isset($d['trial']) ? $d['trial'] : array()); // --- Pending partner requests banner (like Shopify) --- Adverships_Affiliate_Pending::render_banner(isset($d['pending']) ? $d['pending'] : array()); // --- Account quick links: sign in to Adverships + partner invite link --- $base = Adverships_Affiliate_Client::api_base(); $acct = Adverships_Affiliate_Client::settings(); echo ''; // --- KPI cards --- echo '
'; $this->kpi(__('Partners', 'adverships-affiliate'), number_format_i18n((int) ($totals['partners'] ?? 0))); $this->kpi(__('Clicks', 'adverships-affiliate'), number_format_i18n((int) ($totals['clicks'] ?? 0))); $this->kpi(__('Sales', 'adverships-affiliate'), number_format_i18n((int) ($totals['sales'] ?? 0))); $this->kpi(__('Revenue', 'adverships-affiliate'), $this->money($totals['revenue'] ?? 0)); $this->kpi(__('Earned by creators', 'adverships-affiliate'), $this->money($totals['earned'] ?? 0)); $this->kpi(__('You owe', 'adverships-affiliate'), $this->money($owed['total'] ?? 0)); echo '
'; // --- Wallet --- echo '

' . esc_html__('Wallet', 'adverships-affiliate') . '

'; printf( /* translators: 1: balance, 2: lifetime funded */ esc_html__('Balance: %1$s · Lifetime funded: %2$s', 'adverships-affiliate'), esc_html($this->money($wallet['balance'] ?? 0)), esc_html($this->money($wallet['lifetime'] ?? 0)) ); echo '

'; // --- Recent sales --- echo '

' . esc_html__('Recent sales', 'adverships-affiliate') . '

'; if (empty($recent)) { echo '

' . esc_html__('No sales recorded yet.', 'adverships-affiliate') . '

'; } else { echo ''; foreach (array( __('Date', 'adverships-affiliate'), __('Order', 'adverships-affiliate'), __('Creator', 'adverships-affiliate'), __('Type', 'adverships-affiliate'), __('Platform', 'adverships-affiliate'), __('Amount', 'adverships-affiliate'), __('Refunded', 'adverships-affiliate'), __('Status', 'adverships-affiliate'), ) as $h) { echo ''; } echo ''; foreach ($recent as $s) { $status = !empty($s['voided']) ? __('Voided', 'adverships-affiliate') : __('Confirmed', 'adverships-affiliate'); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
' . esc_html($h) . '
' . esc_html(isset($s['created_at']) ? $s['created_at'] : '') . '' . esc_html(isset($s['order_id']) ? $s['order_id'] : '') . '' . esc_html(isset($s['creator']) ? $s['creator'] : '') . '' . esc_html(isset($s['type']) ? ucfirst($s['type']) : '') . '' . esc_html(isset($s['platform']) ? $s['platform'] : '') . '' . esc_html($this->money($s['amount'] ?? 0, $s['currency'] ?? '')) . '' . esc_html($this->money($s['refunded'] ?? 0, $s['currency'] ?? '')) . '' . esc_html($status) . '
'; } echo '
'; echo '

' . esc_html__('Figures are lifetime totals, computed by Adverships.', 'adverships-affiliate') . '

'; echo ''; } // ---- helpers ---------------------------------------------------------- private function kpi($label, $value) { echo '
' . esc_html($value) . '
' . esc_html($label) . '
'; } private function money($amount, $currency = '') { $amount = (float) $amount; if (function_exists('wc_price') && $currency !== '') { return wp_strip_all_tags(wc_price($amount, array('currency' => $currency))); } if (function_exists('wc_price')) { return wp_strip_all_tags(wc_price($amount)); } return number_format_i18n($amount, 2); } private function render_not_connected() { $url = admin_url('admin.php?page=adverships-settings'); echo '

' . esc_html__('Connect your store to see your Adverships analytics here.', 'adverships-affiliate') . '

'; echo '

' . esc_html__('Go to Settings', 'adverships-affiliate') . '

'; } private function render_error($res) { $msg = is_wp_error($res) ? $res->get_error_message() : (isset($res['data']['error']) ? $res['data']['error'] : __('Could not load data from Adverships.', 'adverships-affiliate')); echo '

' . esc_html($msg) . '

'; } private function cap() { return current_user_can('manage_woocommerce') ? 'manage_woocommerce' : 'manage_options'; } }