Skip to content

Fix TypeError in WooCommerce Store API: process_payment() returning b…#109

Open
KamilBalwierz wants to merge 1 commit into
masterfrom
proper_failure_return
Open

Fix TypeError in WooCommerce Store API: process_payment() returning b…#109
KamilBalwierz wants to merge 1 commit into
masterfrom
proper_failure_return

Conversation

@KamilBalwierz

Copy link
Copy Markdown
Contributor

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

…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.
@github-actions

Copy link
Copy Markdown

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.

1 participant