Skip to content

Fix/632 show generic error to customers when invalid keys #4536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

diegocurbelo
Copy link
Member

@diegocurbelo diegocurbelo commented Jul 28, 2025

Fixes STRIPE-632

Changes proposed in this Pull Request:

This PR replaces the error message displayed during checkout when the Stripe API Key is invalid; we specifically mention that the payment was not processed, and then use a message similar to what we use when no payment methods are available (as this is the same case, with an invalid API key all payment methods will fail).

Screenshot 2025-07-28 at 18 52 31

The logs entry and the order note still show the full error message for debugging purposes.


For context, when there are no payment methods available during checkout, the message look like this:
Screenshot 2025-07-28 at 19 07 22

Testing instructions

  1. Checkout the develop branch
  2. Replace the secret_key with an invalid value:
    wp option patch update woocommerce_stripe_settings test_secret_key 'sk_test_INVALID'
  3. Go to the Store, add a product to the cart
  4. Go to the Blocks Checkout, place the order, and check the error message mentions the API key:
    Screenshot 2025-07-28 at 19 25 10
  5. Checkout this branch
  6. Go to the Blocks Checkout, place the order again and check that the error message is now generic:
    Screenshot 2025-07-28 at 19 23 06
  7. Go to the Shortcode Checkout, attempt to place the order again, and check the message:
    Screenshot 2025-07-28 at 19 25 22

  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Changelog entry

  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Comment

Comment

Post merge

@diegocurbelo diegocurbelo requested a review from Copilot July 28, 2025 22:17
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the user experience during checkout by replacing technical error messages with a more customer-friendly message when Stripe API keys are invalid. While the detailed error information is preserved in logs and order notes for debugging purposes, customers now see a generic message that doesn't expose technical implementation details.

  • Replace technical "Invalid API Key" error message with user-friendly checkout error
  • Preserve detailed error information in logs and order notes for debugging
  • Update changelog and readme to document the improvement

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
includes/payment-methods/class-wc-stripe-upe-payment-gateway.php Adds error message handling to show generic message for invalid API key errors
readme.txt Documents the change in the changelog
changelog.txt Adds changelog entry for the error message improvement

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@diegocurbelo diegocurbelo marked this pull request as ready for review July 28, 2025 22:30
@diegocurbelo diegocurbelo requested review from a team, malithsen and wjrosa and removed request for a team July 29, 2025 12:52
Copy link
Contributor

@malithsen malithsen left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

Image

Copy link
Contributor

@wjrosa wjrosa left a comment

Choose a reason for hiding this comment

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

Nice fix! Looks good to me 👍

@diegocurbelo diegocurbelo enabled auto-merge (squash) July 29, 2025 19:13
@diegocurbelo diegocurbelo merged commit c778297 into develop Jul 29, 2025
45 checks passed
@diegocurbelo diegocurbelo deleted the fix/632-show-generic-error-to-customers-when-invalid-keys branch July 29, 2025 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants