Fix TypeError in WooCommerce Store API: process_payment() returning bool instead of array#108
Open
bratajczakqf wants to merge 1 commit into
Open
Conversation
…ool instead of array Several payment gateways (TpayBlik, TpayCC, TpaySF) return a bare `false` from process_payment() on certain failure paths (missing/ invalid BLIK code, tpay_has_errors(), missing card data). This is fine for the classic (shortcode) checkout, but WooCommerce Store API (used by the Blocks Checkout, Automattic\WooCommerce\StoreApi\Legacy ::process_legacy_payment()) unconditionally does array_merge($result->payment_details, $gateway_result) on the return value, which throws an uncaught TypeError when $gateway_result is `false` instead of an array: TypeError: array_merge(): Argument tpay-com#2 must be of type array, bool given Reproduced with: WooCommerce 10.9.4, WordPress 7.0.1, PHP 8.2.29, Blocks Checkout, Tpay BLIK level 0, empty BLIK code submitted. The gateways already call wc_add_notice() with the correct user-facing message before returning false, so this fix only changes the return type to the ['result' => 'failure'] shape already used elsewhere in the same files - no behavioral change for the classic checkout, and no change to any success path.
Contributor
|
Dziękujemy za kontrybucję. Zrobiłem drugi merge request Twoich zmian z konta, które ma uprawnienia do naszej przestrzeni nazw żeby CI się poprawnie zbudowało i zweryfikowało - #109 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
process_payment()inTpayBlik,TpayCCandTpaySFreturns a barefalseon several failure paths instead of the['result' => 'failure']array shape used everywhere else. This works fine on the classic (shortcode) checkout, but breaks WooCommerce Blocks Checkout:Automattic\WooCommerce\StoreApi\Legacy::process_legacy_payment()unconditionally doesarray_merge($result->payment_details, $gateway_result), which throws an uncaughtTypeErrorwhen$gateway_resultisfalse:The customer sees a WordPress "critical error" page instead of a normal validation message.
Reproduced with
WooCommerce 10.9.4, WordPress 7.0.1, PHP 8.2.29, Blocks Checkout, Tpay BLIK level 0, empty BLIK code submitted. Confirmed on plugin versions 1.12.5 and 1.15.2 (current) — identical code, bug not fixed by the version bump.
What this fixes
TpayBlik.php: 2 occurrences (missing BLIK code;tpay_has_errors()branch)TpayCC.php: 2 occurrences (tpay_has_errors()branch; final fallback)TpaySF.php: 1 occurrence (missing card data)The BLIK case was reproduced and tested end-to-end (before/after, with debug log evidence). The
TpayCC/TpaySFoccurrences are the identical pattern found via code audit — not dynamically tested by us, please verify on your end.Why this is safe
No behavior change for the classic checkout or for any success path. The gateways already call
wc_add_notice()with the correct user-facing message before returningfalse— this PR only fixes the return type to match the convention already used elsewhere in the same files.