fetch_option( \Airalo\Admin\Settings\Option::LANGUAGE ); $translations = file_get_contents( __DIR__ . '../../../languages/translations.json' ); $this->translations = json_decode( $translations, true ); $this->language_texts = $this->translations[$language]; $this->enqueue_assets(); } public function enqueue_assets() { wp_enqueue_style( 'my-esim-page-style', plugin_dir_url( __FILE__ ) . '../../assets/css/myEsimPageStyle.css', [], AIRALO_PLUGIN_VERSION ); wp_enqueue_script( 'my-esim-page-script', plugin_dir_url( __FILE__ ) . '../airalo-js/my_esim_page.js', [], AIRALO_PLUGIN_VERSION, true ); } /** * @param string $text * @return string */ private function t( string $text ) { return $this->language_texts[$text] ?? $text; } /** * @return string */ public function build_html() { $all_orders_details = ( new \Airalo\User\MySimsDetails() )->get_all_user_order_details(); if ( empty( $all_orders_details ) ) { return '

' . $this->t( 'my.esims.no.esims' ) . '

'; } $iccid = isset( $_GET['iccid'] ) ? sanitize_text_field( $_GET['iccid'] ) : $all_orders_details[0]['iccid']; $esim_list = []; $current_url_path = esc_url_raw( strtok( $_SERVER["REQUEST_URI"], '&' ) ); foreach ( $all_orders_details as $esim ) { $sim_name_class = "esim-list-title"; if ( $iccid == $esim['iccid'] ) { $sim_name_class .= " active"; } $sim_name_element = '

' . $esim['sim_name'] . '

'; if ( strpos( $current_url_path, '?' ) === false ) { $current_url_path = rtrim( $current_url_path, '/' ); $iccid_slug = '?iccid=' . $esim['iccid']; } else { $iccid_slug = '&iccid=' . $esim['iccid']; } $esim_list[] = '' . $sim_name_element . ''; } return '

' . $this->t('my.esims.available.esims') . '

' . implode( '', $esim_list ) . '
'; } /** * @param string $default_iccid * @return string */ private function get_usage_data( string $default_iccid ) { $details_client = new \Airalo\User\MySimsDetails(); $all_orders_details = $details_client->get_all_user_order_details(); $current_iccid = isset( $_GET['iccid'] ) ? sanitize_text_field( $_GET['iccid'] ) : $default_iccid; $data_usage_item = []; foreach ( $all_orders_details as $esim ) { if ( $esim['iccid'] == $current_iccid ) { $data_usage_item = $esim; $details_client->append_usage_details_to_iccid( $current_iccid, $data_usage_item ); } } if ( empty( $data_usage_item ) ) { wp_die( 'You are not authorized to view this page.', 'Forbidden', 403 ); } if ( $data_usage_item['remaining'] > 0 && $data_usage_item['total'] > 0 ) { $remaining_data = round( ( $data_usage_item['remaining'] / 1024 ), 2 ); $remaining_percentage = ( $remaining_data / ( $data_usage_item['total'] / 1024 ) ) * 100; } else { $remaining_data = 0; $remaining_percentage = 0; } $parts = explode( ' - ', $data_usage_item['sim_name'] ); $validity_and_data = explode( ' ', $parts[1] ); return '

' . $this->t('my.esims.coverage') . '

' . ( $data_usage_item['sim_name'] ?? null ) . '

' . $this->t('my.esims.iccid') . '

' . ( $data_usage_item['iccid'] ?? null ) . '

' . $this->t('my.esims.package') . '

' . ( $data_usage_item['coverage'] ?? null ) . '

' . $this->t('my.esims.package') . '

' . $data_usage_item['status'] . '

' . $this->t('my.esims.date') . '

' . $data_usage_item['expired_at'] . '

' . $this->t('my.esims.package.valid') . '

' . implode( ' ', [$validity_and_data[1], $validity_and_data[2]] ) . '

' . $this->t('my.esims.package.data') . '

' . implode( ' ', [$validity_and_data[3], $validity_and_data[4]] ) . '

' . $this->t('my.esims.remaining-data') . '

' . $remaining_data . ' GB

'; } /** * @param string $type * @return string */ private function get_installation_form_content( string $type ) { return '

' . $this->t( 'my.esims.select-platform' ) . '

' . $this->t( 'my.esims.select-device' ) . '

' . $this->t( 'my.esims.installation-instructions' ) . '

airalo-instruction-check

' . $this->t( 'my.esims.installation.instructions.description' ) . '

    '; } /** * @param string $default_iccid * @return string */ private function get_qr_and_manual_tabs( string $default_iccid ) { $iccid = isset( $_GET['iccid'] ) ? sanitize_text_field( $_GET['iccid'] ) : $default_iccid; if ( ! $iccid ) { return; } $language = ( new \Airalo\Admin\Settings\Option() )->fetch_option( \Airalo\Admin\Settings\Option::LANGUAGE ); try { $instructions = new \Airalo\Admin\InstallationInstruction(); $response = $instructions->handle( $iccid, $language ); } catch ( \Exception $e ) { echo 'Error loading installation instructions. Please try again later.'; return; } $ios_data = $response->data->instructions->ios[0]; $android_data = $response->data->instructions->android[0]; $localize_data = [ 'iosData' => $ios_data, 'androidData' => $android_data, 'iosInstallationQrSteps' => $ios_data->installation_via_qr_code->steps, 'androidInstallationQrSteps' => $android_data->installation_via_qr_code->steps, 'iosInstallationManualSteps' => $ios_data->installation_manual->steps, 'androidInstallationManualSteps' => $android_data->installation_manual->steps, 'iosQrCodeUrl' => $ios_data->installation_via_qr_code->qr_code_url, 'androidQrCodeUrl' => $android_data->installation_via_qr_code->qr_code_url, 'iosManualSMDPAddressAndActivationCode' => $ios_data->installation_manual->smdp_address_and_activation_code, 'androidManualSMDPAddressAndActivationCode' => $android_data->installation_manual->smdp_address_and_activation_code, ]; wp_localize_script( 'my-esim-page-script', 'myEsimData', $localize_data ); return '
    qr-code
    ' . $this->get_installation_form_content( "qr" ) . '

    ' . $this->t( 'my.esims.installation.manual.sm.dp.activation' ) . '

    ' . $this->get_installation_form_content( "manual" ) . '
    '; } }