Skip to content

Commit

Permalink
More DRY auto submit feature, and fix boolean flag argument.
Browse files Browse the repository at this point in the history
Single Responsibility Principle (SRP).
  • Loading branch information
remcotolsma committed Oct 4, 2023
1 parent fb9946b commit 7fdbf69
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
13 changes: 9 additions & 4 deletions src/Core/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Check failure on line 309 in src/Core/Gateway.php

View workflow job for this annotation

GitHub Actions / phpcs / phpcs

All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$this'.
} else {
Core_Util::no_cache();

Expand All @@ -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(
Expand All @@ -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 ) {

Check failure on line 352 in src/Core/Gateway.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

If condition is always true.
$element = new Element(
'script',
Expand Down
16 changes: 2 additions & 14 deletions views/redirect-via-html.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,7 @@
</script>
</head>

<?php

$auto_submit = true;

if ( defined( '\PRONAMIC_PAY_DEBUG' ) && \PRONAMIC_PAY_DEBUG ) {
$auto_submit = false;
}

$onload = $auto_submit ? 'document.forms[0].submit();' : '';

?>

<body onload="<?php esc_attr( $onload ); ?>">
<body>
<div class="pronamic-pay-redirect-page">
<div class="pronamic-pay-redirect-container">
<h1><?php esc_html_e( 'Redirecting…', 'pronamic-ideal' ); ?></h1>
Expand All @@ -58,7 +46,7 @@
<?php esc_html_e( 'Please click the button below if you are not automatically redirected.', 'pronamic-ideal' ); ?>
</p>

<?php echo $this->get_form_html( $payment, $auto_submit ); ?>
<?php echo $this->get_form_html( $payment ); ?>

Check failure on line 49 in views/redirect-via-html.php

View workflow job for this annotation

GitHub Actions / phpcs / phpcs

All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$this'.

Check failure on line 49 in views/redirect-via-html.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Variable $this might not be defined.
</div>
</div>

Expand Down

0 comments on commit 7fdbf69

Please sign in to comment.