Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion stripe/controllers/FrmTransLiteActionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public static function actions_js() {
'frmtrans_admin',
'frm_trans_vars',
array(
'nonce' => wp_create_nonce( 'frm_trans_ajax' ),
'nonce' => wp_create_nonce( 'frm_trans_ajax' ),
'refunded' => FrmTransLiteAppHelper::show_status( 'refunded' ),
)
);
}
Expand Down
21 changes: 21 additions & 0 deletions stripe/js/frmtrans_admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
slideOpts( this, show, '.frm_trans_sub_opts' );
toggleOpts( this, ! show, '.frm_gateway_no_recur' );

if ( ! show ) {
hideOtherGatewayRows( jQuery( this ).closest( '.frm_form_action_settings' ) );
}

// Hiding the selected gateway would leave the tablist without a Tab stop.
const tablist = this.closest( '.frm_form_action_settings' ).querySelector( '.frm-long-icon-buttons[role="tablist"]' );
if ( tablist ) {
Expand Down Expand Up @@ -32,6 +36,18 @@
}
}

function hideOtherGatewayRows( settings ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: this duplicates the hide-other-gateway-rows loop in toggleGateway() (the toggleOff.forEach block). Consider one shared helper, or scoping the toggleOpts( this, ! show, '.frm_gateway_no_recur' ) call in toggleSub() so it never reveals rows that belong to an unselected gateway.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping this as is. The two loops don't select the same set: toggleGateway() hides every .show_<other gateway> element in the action unless it carries the selected gateway's class, while hideOtherGatewayRows() only touches .frm_gateway_no_recur rows, the ones toggleOpts() just revealed. Sharing one helper means changing what toggleGateway() hides, and that handler has no JS test. Scoping the toggleOpts() call instead means a third selector form in a function that is also used for the frm_trans_sub_opts slide. I would rather do either as its own change with a way to test it. Happy to open a follow-up.

const selected = settings.find( 'input[name$="[gateway]"]:checked' ).val();

settings.find( '.frm_gateway_no_recur' ).each(
( i, row ) => {
if ( /\bshow_(stripe|square|paypal)\b/.test( row.className ) && ! row.classList.contains( `show_${ selected }` ) ) {
row.style.display = 'none';
}
}
);
}

function toggleGateway() {
const gateway = this.value;
const { checked } = this;
Expand Down Expand Up @@ -133,6 +149,11 @@
},
success( html ) {
jQuery( loadingImage ).replaceWith( html );

const status = document.querySelector( '.frm-payment-status' );
if ( status && href.includes( 'action=frm_trans_refund' ) && html.includes( 'frm_updated_message' ) ) {
status.textContent = frm_trans_vars.refunded;
}
}
} );
};
Expand Down
2 changes: 1 addition & 1 deletion stripe/views/action-settings/capture-payments-upsell.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
$upgrade_params
);

if ( isset( $selected_gateway ) && 'stripe' !== $selected_gateway ) {
if ( isset( $selected_gateway ) && ! in_array( 'stripe', (array) $selected_gateway, true ) ) {
$wrapper_atts['style'] = 'display: none;';
}
?>
Expand Down
2 changes: 1 addition & 1 deletion stripe/views/payments/show.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<tbody>
<tr>
<th scope="row"><?php esc_html_e( 'Status', 'formidable' ); ?>:</th>
<td><?php echo esc_html( FrmTransLiteAppHelper::show_status( FrmTransLiteAppHelper::get_payment_status( $payment ) ) ); ?></td>
<td class="frm-payment-status"><?php echo esc_html( FrmTransLiteAppHelper::show_status( FrmTransLiteAppHelper::get_payment_status( $payment ) ) ); ?></td>
</tr>

<tr>
Expand Down
27 changes: 27 additions & 0 deletions tests/phpunit/stripe/test_FrmTransLiteActionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,33 @@ public function test_maybe_use_decimal() {
$this->assertSame( '111.500', $amount );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmTransLiteActionsController::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

}

public function test_echo_capture_payment_upsell_is_hidden_unless_stripe_is_selected() {
$action = new FrmTransLiteAction();

$this->assertStringContainsString( 'display: none', $this->get_capture_payment_upsell( $action, array( 'paypal' ) ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmTransLiteActionsController::assertStringContainsString()


The method you are trying to call is not defined, which can result in a fatal error.

$this->assertStringContainsString( 'display: none', $this->get_capture_payment_upsell( $action, array( 'square' ) ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmTransLiteActionsController::assertStringContainsString()


The method you are trying to call is not defined, which can result in a fatal error.

$this->assertStringNotContainsString( 'display: none', $this->get_capture_payment_upsell( $action, array( 'stripe' ) ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmTransLiteActionsController::assertStringNotContainsString()


The method you are trying to call is not defined, which can result in a fatal error.

}

public function test_actions_js_localizes_the_refunded_label() {
FrmTransLiteActionsController::actions_js();

$data = wp_scripts()->get_data( 'frmtrans_admin', 'data' );
$this->assertStringContainsString( '"refunded":"' . FrmTransLiteAppHelper::show_status( 'refunded' ) . '"', $data );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmTransLiteActionsController::assertStringContainsString()


The method you are trying to call is not defined, which can result in a fatal error.

}

/**
* @param FrmTransLiteAction $action
* @param array $gateway
*
* @return string
*/
private function get_capture_payment_upsell( $action, $gateway ) {
ob_start();
$action->echo_capture_payment_upsell( $gateway );
return ob_get_clean();
}

/**
* @param string $amount
* @param array $currency
Expand Down
Loading