From 7fdbf69cdfeeaecadbefc822fef564ae0137fb92 Mon Sep 17 00:00:00 2001 From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com> Date: Wed, 4 Oct 2023 16:12:11 +0200 Subject: [PATCH] More DRY auto submit feature, and fix boolean flag argument. Single Responsibility Principle (SRP). --- src/Core/Gateway.php | 13 +++++++++---- views/redirect-via-html.php | 16 ++-------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/Core/Gateway.php b/src/Core/Gateway.php index 28365b0a..f7d800e4 100644 --- a/src/Core/Gateway.php +++ b/src/Core/Gateway.php @@ -306,7 +306,7 @@ public function redirect_via_http( Payment $payment ) { */ public function redirect_via_html( Payment $payment ) { if ( headers_sent() ) { - echo $this->get_form_html( $payment, true ); + echo $this->get_form_html( $payment ); } else { Core_Util::no_cache(); @@ -319,12 +319,11 @@ public function redirect_via_html( Payment $payment ) { /** * Get form HTML. * - * @param Payment $payment Payment to get form HTML for. - * @param bool $auto_submit Flag to auto submit. + * @param Payment $payment Payment to get form HTML for. * @return string * @throws \Exception When payment action URL is empty. */ - public function get_form_html( Payment $payment, $auto_submit = false ) { + public function get_form_html( Payment $payment ) { $form_inner = $this->get_output_html( $payment ); $form_inner .= sprintf( @@ -344,6 +343,12 @@ public function get_form_html( Payment $payment, $auto_submit = false ) { $form_inner ); + $auto_submit = true; + + if ( defined( '\PRONAMIC_PAY_DEBUG' ) && \PRONAMIC_PAY_DEBUG ) { + $auto_submit = true; + } + if ( $auto_submit ) { $element = new Element( 'script', diff --git a/views/redirect-via-html.php b/views/redirect-via-html.php index c487ef0f..4b2830c7 100644 --- a/views/redirect-via-html.php +++ b/views/redirect-via-html.php @@ -31,19 +31,7 @@ - - -
+