Skip to content

Fix TypeError in WooCommerce Store API: process_payment() returning bool instead of array#108

Open
bratajczakqf wants to merge 1 commit into
tpay-com:masterfrom
bratajczakqf:fix/blik-process-payment-return-type
Open

Fix TypeError in WooCommerce Store API: process_payment() returning bool instead of array#108
bratajczakqf wants to merge 1 commit into
tpay-com:masterfrom
bratajczakqf:fix/blik-process-payment-return-type

Conversation

@bratajczakqf

Copy link
Copy Markdown

Summary

process_payment() in TpayBlik, TpayCC and TpaySF returns a bare false on 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 does array_merge($result->payment_details, $gateway_result), which throws an uncaught TypeError when $gateway_result is false:

TypeError: array_merge(): Argument #2 must be of type array, bool given

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/TpaySF occurrences 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 returning false — this PR only fixes the return type to match the convention already used elsewhere in the same files.

…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.
@KamilBalwierz

Copy link
Copy Markdown
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
Zrobimy sobie jeszcze testy manualne i dołączymy zmiany do najbliższego wydania.

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.

2 participants