diff --git a/aluxpay-payment-gateway/includes/class-aluxpay-payment-gateway.php b/aluxpay-payment-gateway/includes/class-aluxpay-payment-gateway.php index b9f4124..cc607b7 100644 --- a/aluxpay-payment-gateway/includes/class-aluxpay-payment-gateway.php +++ b/aluxpay-payment-gateway/includes/class-aluxpay-payment-gateway.php @@ -9,6 +9,103 @@ if (!defined('ABSPATH')) { class WC_Aluxpay_Payment_Gateway extends WC_Payment_Gateway { + /** + * Reusable: HTML notice for Thank You page + HTML emails + */ + protected function get_generic_notice_html(): string { + // Keep inline styles for email clients; translate strings + $html .= '

' . esc_html__( 'Thank you for your payment!', 'aluxpay-payment-gateway' ) . ' '; + $html .= esc_html__( 'Your order has been successfully processed, and a confirmation email has been sent from our webstore.', 'aluxpay-payment-gateway' ) . '

'; + + $html .= '
' . esc_html__( 'Important Note:', 'aluxpay-payment-gateway' ) . '
'; + $html .= '

' . esc_html__( "Because of the nature of our business and how our website integrates with PayPal, you’ll also receive a PayPal payment confirmation email. That email will display a generic product name instead of the specific item(s) you purchased.", 'aluxpay-payment-gateway' ) . '

'; + + $html .= '

' . esc_html__( 'Rest assured — your order is fully confirmed, and the webstore confirmation email contains the correct details of your purchase.', 'aluxpay-payment-gateway' ) . '

'; + + $html .= '

' . esc_html__( "If you have any questions or need assistance, please don’t hesitate to contact our support team.", 'aluxpay-payment-gateway' ) . '

'; + + // For frontend we can allow basic tags; for email we echo directly. + $allowed = array( + 'p' => array('style'=>true), + 'h5' => array('style'=>true), + 'strong' => array(), + ); + return wp_kses( $html, $allowed ); + } + + /** + * Reusable: Plain-text version for plain emails + */ + protected function get_generic_notice_plain(): string { + $lines = array( + __( 'Thank you for your payment! Your order has been successfully processed, and a confirmation email has been sent from our webstore.', 'aluxpay-payment-gateway' ), + '', + __( 'Important Note:', 'aluxpay-payment-gateway' ), + __( "Because of the nature of our business and how our website integrates with PayPal, you’ll also receive a PayPal payment confirmation email. That email will display a generic product name instead of the specific item(s) you purchased.", 'aluxpay-payment-gateway' ), + __( 'Rest assured — your order is fully confirmed, and the webstore confirmation email contains the correct details of your purchase.', 'aluxpay-payment-gateway' ), + '', + __( "If you have any questions or need assistance, please don’t hesitate to contact our support team.", 'aluxpay-payment-gateway' ), + ); + return implode( PHP_EOL, $lines ) . PHP_EOL; + } + + /** + * Reusable: HTML notice for Failed Order emails + */ + protected function get_failed_notice_html(): string { + $html = ''; + $html .= '

' . esc_html__( 'Payment Failed', 'aluxpay-payment-gateway' ) . '

'; + $html .= '

' . esc_html__( 'Unfortunately, your payment could not be processed. This may have occurred for one of the following reasons:', 'aluxpay-payment-gateway' ) . '

'; + + $html .= ''; + + $html .= '

' . esc_html__( 'Your order has not been completed and no charges have been made to your account.', 'aluxpay-payment-gateway' ) . '

'; + + $html .= '
' . esc_html__( 'What to do next:', 'aluxpay-payment-gateway' ) . '
'; + $html .= '

' . esc_html__( 'You can try placing your order again by visiting our website. If you continue to experience issues, please contact us for assistance.', 'aluxpay-payment-gateway' ) . '

'; + + $html .= '

' . esc_html__( 'We apologize for any inconvenience this may have caused.', 'aluxpay-payment-gateway' ) . '

'; + + $allowed = array( + 'p' => array('style'=>true), + 'h5' => array('style'=>true), + 'ul' => array('style'=>true), + 'li' => array(), + 'strong' => array(), + ); + return wp_kses( $html, $allowed ); + } + + /** + * Reusable: Plain-text version for Failed Order emails + */ + protected function get_failed_notice_plain(): string { + $lines = array( + __( 'Payment Failed', 'aluxpay-payment-gateway' ), + '', + __( 'Unfortunately, your payment could not be processed. This may have occurred for one of the following reasons:', 'aluxpay-payment-gateway' ), + '', + '- ' . __( 'Insufficient funds in your account', 'aluxpay-payment-gateway' ), + '- ' . __( 'Payment was cancelled during the process', 'aluxpay-payment-gateway' ), + '- ' . __( 'Payment method declined the transaction', 'aluxpay-payment-gateway' ), + '- ' . __( 'Technical issue during payment processing', 'aluxpay-payment-gateway' ), + '', + __( 'Your order has not been completed and no charges have been made to your account.', 'aluxpay-payment-gateway' ), + '', + __( 'What to do next:', 'aluxpay-payment-gateway' ), + __( 'You can try placing your order again by visiting our website. If you continue to experience issues, please contact us for assistance.', 'aluxpay-payment-gateway' ), + '', + __( 'We apologize for any inconvenience this may have caused.', 'aluxpay-payment-gateway' ), + ); + return implode( PHP_EOL, $lines ) . PHP_EOL; + } + + /** * Constructor */ @@ -42,8 +139,12 @@ class WC_Aluxpay_Payment_Gateway extends WC_Payment_Gateway { add_action('woocommerce_api_' . $this->id, array($this, 'webhook_handler')); add_action('woocommerce_thankyou_' . $this->id, array($this, 'thankyou_page')); - // Customer Emails + // Customer Emails - Success add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3); + + // Customer Emails - Failed Orders + add_action('woocommerce_email_before_order_table', array($this, 'failed_email_instructions'), 10, 3); + } /** @@ -233,24 +334,58 @@ class WC_Aluxpay_Payment_Gateway extends WC_Payment_Gateway { */ public function thankyou_page($order_id) { - if ($this->description) { + /**if ($this->description) { echo wpautop(wptexturize($this->description)); - } + }*/ $order = wc_get_order($order_id); if ($order && $order->get_status() === 'processing') { - echo '

' . __('Your payment has been received and your order is being processed.', 'aluxpay-payment-gateway') . '

'; + echo $this->get_generic_notice_html(); } } /** - * Add content to the WC emails + * Add content to the WC emails for successful orders */ public function email_instructions($order, $sent_to_admin, $plain_text = false) { - if ($this->description && !$sent_to_admin && $this->id === $order->get_payment_method()) { - echo wpautop(wptexturize($this->description)) . PHP_EOL; + /** if ($this->description && !$sent_to_admin && $this->id === $order->get_payment_method()) { + * echo wpautop(wptexturize($this->description)) . PHP_EOL; + *} */ + + if ( $sent_to_admin ) return; // customers only + if ( ! $order instanceof WC_Order ) return; + if ( $order->get_payment_method() !== $this->id ) return; + + // Only show for completed/processing orders + if ( ! in_array( $order->get_status(), array( 'processing', 'completed' ) ) ) return; + + // Pick the right format for the email renderer + if ( $plain_text ) { + echo $this->get_generic_notice_plain(); + } else { + echo $this->get_generic_notice_html(); + } + } + + /** + * Add content to the WC emails for failed orders + */ + public function failed_email_instructions($order, $sent_to_admin, $plain_text = false) { + + if ( $sent_to_admin ) return; // customers only + if ( ! $order instanceof WC_Order ) return; + if ( $order->get_payment_method() !== $this->id ) return; + + // Only show for failed orders + if ( $order->get_status() !== 'failed' ) return; + + // Pick the right format for the email renderer + if ( $plain_text ) { + echo $this->get_failed_notice_plain(); + } else { + echo $this->get_failed_notice_html(); } } } \ No newline at end of file