Fix TypeError in WooCommerce Store API: process_payment() returning b…#109
Open
KamilBalwierz wants to merge 1 commit into
Open
Fix TypeError in WooCommerce Store API: process_payment() returning b…#109KamilBalwierz wants to merge 1 commit into
KamilBalwierz wants to merge 1 commit into
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 #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.
|
Tpay Woocommerce plugin - https://github.com/tpay-com/tpay-woocommerce/actions/runs/29904827315/artifacts/8523381443 |
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.
…ool instead of array
Several payment gateways (TpayBlik, TpayCC, TpaySF) return a bare
falsefrom 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 doesarray_merge($result->payment_details, $gateway_result) on the return value, which throws an uncaught TypeError when $gateway_result is
falseinstead of an array:TypeError: array_merge(): Argument #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.