formipay_settings = get_option('formipay_settings'); } private function get_email_template() { if ($this->email_template === null) { $this->email_template = file_get_contents(FORMIPAY_PATH . 'notification/email_templates/email-page-template.html'); } return $this->email_template; } public function notification($order_data) { $formipay_settings = $this->formipay_settings; $this->order_data = $order_data; $recipient_type = apply_filters('formipay/notification/recipients', ['admin', 'buyer'] ); $order_status = str_replace('-', '_', $this->order_data['status']); foreach($recipient_type as $recipient){ if( false !== boolval($formipay_settings['notification_email_'.$recipient.'_'.$order_status.'_toggle']) && !empty($formipay_settings['notification_email_'.$recipient.'_'.$order_status.'_title']) && !empty($formipay_settings['notification_email_'.$recipient.'_'.$order_status.'_content']) ) { $recipient_email = ''; $buyer_email_field = formipay_get_post_meta($this->order_data['form_id'], 'buyer_email'); if($recipient == 'admin' && false !== boolval($formipay_settings['notification_email_admin_recipient'])){ $recipient_email = $formipay_settings['notification_email_admin_recipient']; }elseif( $recipient == 'buyer' && !empty($buyer_email_field)) { $recipient_email = $this->order_data['form_data'][$buyer_email_field]; } if( '' !== $recipient_email ){ $args = [ 'order_id' => $this->order_data['id'], 'recipient_type' => $recipient, 'media' => 'email', 'notification_data' => [ 'to' => $recipient_email, 'subject' => $formipay_settings['notification_email_'.$recipient.'_'.$order_status.'_title'], 'content' => $this->process_content($recipient) ], 'meta_data' => [ 'request_date' => formipay_date('Y-m-d H:i:s') ] ]; $notification_id = parent::insert_notification_data($args); if(false !== $notification_id){ wp_schedule_single_event( time() + 15, 'formipay/notification/order/email/trigger-event', [$notification_id] ); } } } do_action( 'formipay/notification/order/email/trigger', $recipient, $order_data); } } public function send_email($notification_id) { $get = parent::get_notification_data_by_id($notification_id); if(false !== $get){ $metadata = maybe_unserialize( $get->meta_data ); $get_data = maybe_unserialize( $get->notification_data ); $status = $get->status; if(!empty($get_data)){ $send_mail = wp_mail( sanitize_email( $get_data['to'] ), $get_data['subject'], $get_data['content'], array('Content-Type: text/html; charset=UTF-8') ); if(!is_wp_error($send_mail)){ $status = 'sent'; }else{ $status = 'error'; $metadata['error_message'] = $send_mail->get_error_messages(); } $metadata['update_date'] = formipay_date('Y-m-d H:i:s'); $args = [ 'status' => $status, 'meta_data' => $metadata ]; \Formipay_Notification::update_notification_data($notification_id, $args); } } } public function access_link($order_data) { $formipay_settings = $this->formipay_settings; $this->order_data = $order_data; $buyer_email_field = formipay_get_post_meta($order_data['form_id'], 'notification_email_buyer_recipient'); if( !empty($formipay_settings['notification_email_access_link_title']) && !empty($formipay_settings['notification_email_access_link_content']) && !empty($buyer_email_field) ) { $recipient = 'buyer'; $recipient_email = ''; foreach($order_data['form_data'] as $form_data){ if($form_data['name'] == $buyer_email_field){ $recipient_email = $form_data['value']; break; } } if( '' !== $recipient_email ){ $send_mail = wp_mail( sanitize_email( $recipient_email ), $formipay_settings['notification_email_access_link_title'], $this->process_content('buyer', 'access_link'), array('Content-Type: text/html; charset=UTF-8') ); } } do_action( 'formipay/notification/access/email/trigger', $recipient, $order_data); } public function process_content($recipient, $context='order') { $formipay_settings = $this->formipay_settings; $order_status = str_replace('-', '_', $this->order_data['status']); $order_body_template = $formipay_settings['notification_email_' . $recipient . '_' . $order_status . '_content']; $accesslink_body_template = $formipay_settings['notification_email_access_link_content']; $body_template = $context == 'order' ? $order_body_template : $accesslink_body_template; $buyer_name = formipay_get_post_meta($this->order_data['form_id'], 'buyer_name'); if(!empty($buyer_name)){ $buyer_name_field = $buyer_name; $buyer_name = $this->order_data['form_data'][$buyer_name_field]['value']; } // Prepare the replacements for shortcodes $replacements = [ '{{image_logo}}' => $this->get_image_logo(), '{{email_content}}' => $this->get_content($body_template, $context), '{{action_button}}' => $context == 'order' ? $this->get_action_button($recipient) : '', '{{footer_message}}' => $this->get_footer_message(), '{{social_links}}' => $this->get_social_links() ]; // Load the email template $email_template = $this->get_email_template(); // Replace the shortcodes in the email template $email_template = strtr($email_template, $replacements); return $email_template; } private function get_content_depracated($body_template, $context) { $form_id = $this->order_data['form_id']; $order_data = $this->order_data; $formipay_settings = $this->formipay_settings; // Cache frequently used settings and meta values $buyer_name_field = formipay_get_post_meta($form_id, 'buyer_name'); $payment_gateway = $order_data['form_data']['payment_gateway']; $payment_timeout = !empty($formipay_settings[$payment_gateway . '_timeout']) ? formipay_date($order_data['created_date'] . ' + ' . $formipay_settings[$payment_gateway . '_timeout'] . ' minutes') : ''; $lines = explode('


', $body_template); $content = ''; foreach ($lines as $line) { $line = trim($line); if (strpos($line, '{{order_details}}') !== false) { $content .= ' '; $content .= $this->convert_order_details(); $content .= ''; } else { $content .= ' '; // Replace placeholders with actual data $replacements = [ '{{buyer_name}}' => !empty($buyer_name_field) ? $order_data['form_data'][$buyer_name_field] : '', '{{order_id}}' => $order_data['id'], '{{order_status}}' => $order_data['status'], '{{payment_timeout}}' => $payment_timeout ]; $line = strtr( $line, $replacements ); if ($context === 'access_link') { $meta_data = $order_data['meta_data']; $meta_session_id = ''; foreach($meta_data as $meta){ if($meta['name'] == 'session_id'){ $meta_session_id = $meta['value']; break; } } $thankyou_link = 'thankyou'; if(isset($formipay_settings['thankyou_link']) && !empty($formipay_settings['thankyou_link'])){ $thankyou_link = $formipay_settings['thankyou_link']; } $access_link = site_url('/'.$thankyou_link.'/' . base64_encode("$form_id:::{$order_data['id']}:::{$meta_session_id}")); $line = str_replace( [ '{{access_link}}', '{{access_button}}' ], [ $access_link, $this->get_action_button('buyer', 'access_link', ['url' => $access_link, 'label' => 'Access Link']) ], $line ); } $content .= $line; $content .= ''; } } return $content; } private function get_content($body_template, $context) { $form_id = $this->order_data['form_id']; $order_data = $this->order_data; $formipay_settings = $this->formipay_settings; // Cache frequently used settings and meta values $buyer_name_field = formipay_get_post_meta($form_id, 'buyer_name'); $payment_gateway = $order_data['form_data']['payment_gateway']['label']; $this->payment_timeout = $payment_timeout = !empty($formipay_settings[$payment_gateway . '_timeout']) ? formipay_date($order_data['created_date'] . ' + ' . $formipay_settings[$payment_gateway . '_timeout'] . ' minutes') : ''; $lines = explode('

', $body_template); $content = ''; foreach ($lines as $line) { $line = trim(str_replace('

', '', $line)); if(in_array($line, ['', '
'])) { continue; } if (strpos($line, '{{order_details}}') !== false) { $content .= ''; $content .= $this->convert_order_details(); } elseif (strpos($line, '{{order_items}}') !== false) { $content .= ''; $content .= $this->convert_order_items(); } elseif (strpos($line, '{{buyer_details}}') !== false) { $content .= ''; $content .= $this->convert_buyer_details(); } else { $content .= ''; } } return $content; } // Function to get the logo image private function get_image_logo() { $formipay_settings = $this->formipay_settings; if(empty($formipay_settings['notification_email_logo'])){ return; } $logo_url = wp_get_attachment_image_url($formipay_settings['notification_email_logo'], 'full'); if(false == $logo_url){ return; } /** * Template Baru */ return ''; } // Function to convert order details private function convert_order_details_depracated() { if(empty($this->order_data['items'])){ return; } $button_background_color = json_decode(formipay_get_post_meta($this->order_data['form_id'], 'button_bg_color'), true ); ob_start(); ?> order_data['items'] as $item){ ?> order_data['items'])){ return; } $button_background_color = json_decode(formipay_get_post_meta($this->order_data['form_id'], 'button_bg_color'), true ); ob_start(); ?> order_data['items'])){ return; } $button_background_color = json_decode(formipay_get_post_meta($this->order_data['form_id'], 'button_bg_color'), true ); ob_start(); ?> order_data['items'])){ return; } $button_background_color = json_decode(formipay_get_post_meta($this->order_data['form_id'], 'button_bg_color'), true ); // $buyer_email_field = formipay_get_post_meta($this->order_data['form_id'], 'notification_email_buyer_recipient'); $field_buyer_name = formipay_get_post_meta($this->order_data['form_id'], 'buyer_name'); $buyer_name = !empty($this->order_data['form_data'][$field_buyer_name]) ? $this->order_data['form_data'][$field_buyer_name] : ''; ob_start(); ?> order_data ); } $content = ''; if(!empty($button)){ $button_background_color = json_decode(formipay_get_post_meta($this->order_data['form_id'], 'button_bg_color'), true ); $button_text_color = json_decode(formipay_get_post_meta($this->order_data['form_id'], 'button_text_color'), true ); ob_start(); if($context == 'order'){ ?> order_data ); } $content = ''; if(!empty($button)){ $button_background_color = json_decode(formipay_get_post_meta($this->order_data['form_id'], 'button_bg_color'), true ); $button_text_color = json_decode(formipay_get_post_meta($this->order_data['form_id'], 'button_text_color'), true ); ob_start(); if($context == 'order'){ ?>

formipay_settings; if(empty($formipay_settings['notification_email_footer'])){ return; } $footer = sprintf('

%s

', wp_kses_post($formipay_settings['notification_email_footer']) ); return $footer; } private function get_footer_message() { $formipay_settings = $this->formipay_settings; if(empty($formipay_settings['notification_email_footer'])){ return; } $footer = ''; return $footer; } private function get_social_links() { $formipay_settings = $this->formipay_settings; $content = ''; if(!empty($formipay_settings['notification_email_footer_links'])){ $links = []; foreach($formipay_settings['notification_email_footer_links'] as $link){ // phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage -- This image is a plugin asset and not a WordPress attachment. $links[] = ''; } $content .= ''; } return $content; } }