woocommerce / woocommerce-gateway-stripe

The official Stripe Payment Gateway for WooCommerce
https://wordpress.org/plugins/woocommerce-gateway-stripe/
232 stars 203 forks source link

Can't save settings when toggling Test mode and Legacy experience #3026

Closed a-danae closed 6 months ago

a-danae commented 6 months ago

Describe the bug

When toggling the Test mode and the Legacy experience, an error is triggered when saving the settings and they can't be updated anymore.

This isn't happening in 8.0.0.

To Reproduce Steps to reproduce the behavior:

  1. Go to WC Stripe > Settings tab > General, at /wp-admin/admin.php?page=wc-settings&tab=checkout&section=stripe&panel=settings
  2. Ensure the checkbox under Enable test mode is checked off
  3. Uncheck the checkbox for Enable test mode
  4. Save the settings
  5. Scroll down to Advanced settings > Legacy checkout experience
  6. If the checkbox under Legacy checkout experience is unchecked, check it off to enable the Legacy checkout experience. Otherwise, disable the Legacy experience and enable it again
  7. Save the settings
  8. Notice there's a notice saying "Error saving settings"

Expected behavior

The settings must continue to be saved after toggling any of our settings.

Additional context

It looks like the settings validation isn't expecting Link to be within the enabled payment method types. This is being added to the payload with the described setting toggling.

I'm unsure if this is happening with a less edgy scenario, but we want to avoid having merchants stuck not being able to save their settings.

This request has the following payload:

``` { "is_stripe_enabled": true, "is_test_mode_enabled": false, "enabled_payment_method_ids": [ "card", "link", "alipay", "giropay", "eps", "bancontact", "ideal", "sepa_debit", "p24", "multibanco" ], "available_payment_method_ids": [ "card", "alipay", "giropay", "eps", "bancontact", "boleto", "ideal", "oxxo", "sepa_debit", "p24", "multibanco" ], "ordered_payment_method_ids": [ "card", "alipay", "giropay", "eps", "bancontact", "boleto", "ideal", "oxxo", "sepa_debit", "p24", "multibanco" ], "individual_payment_method_settings": [], "is_payment_request_enabled": true, "payment_request_button_type": "buy", "payment_request_button_theme": "dark", "payment_request_button_size": "small", "payment_request_button_locations": [ "product", "cart", "checkout" ], "is_manual_capture_enabled": false, "is_saved_cards_enabled": true, "is_separate_card_form_enabled": true, "statement_descriptor": "longStatementDescripto", "is_short_statement_descriptor_enabled": false, "short_statement_descriptor": "shortState", "is_debug_log_enabled": true, "is_upe_enabled": false } ```

And it has the following response:

``` { "code": "rest_invalid_param", "message": "Invalid parameter(s): enabled_payment_method_ids", "data": { "status": 400, "params": { "enabled_payment_method_ids": "enabled_payment_method_ids[1] is not one of card, alipay, giropay, eps, bancontact, boleto, ideal, oxxo, sepa_debit, p24, multibanco, card, sepa, alipay, bancontact, eps, giropay, multibanco, sofort, ideal, p24, oxxo, and boleto." }, "details": { "enabled_payment_method_ids": { "code": "rest_not_in_enum", "message": "enabled_payment_method_ids[1] is not one of card, alipay, giropay, eps, bancontact, boleto, ideal, oxxo, sepa_debit, p24, multibanco, card, sepa, alipay, bancontact, eps, giropay, multibanco, sofort, ideal, p24, oxxo, and boleto.", "data": null } } } } ```
a-danae commented 6 months ago

Fixed by #3027