variable type casting causes error
-
Good morning! My client (who runs a airBnB style photographic locations company) contacted me today with an problem that was causing payments to not be accepted. We have a fairly complex system involving woocommerce and jet engine (don’t ask, it was an inherited project and has been a nightmare) so I’ve created several bridging functions that are called via woo hooks.
The problem this morning was with the action hook woocommerce_thankyou, the function I’ve written updates the jet booking with the woo order ID, so that once the host of the property accepts the booking stripe are notified to capture the charge.
After some digging around in the logs I found the error in (Woocommerce Payments) class-wc-payments-order-success-page.php with the following 2 functions:
/** * Add the notice to the thank you page in case a recent order with the same content has already paid. * * @param string $text the default thank you text. * * @return string */ public function add_notice_previous_paid_order( string $text ) { if ( isset( $_GET[ WC_Payment_Gateway_WCPay::FLAG_PREVIOUS_ORDER_PAID ] ) ) { // phpcs:disable WordPress.Security.NonceVerification.Recommended $text .= sprintf( '<div class="woocommerce-info">%s</div>', esc_attr__( 'We detected and prevented an attempt to pay for a duplicate order. If this was a mistake and you wish to try again, please create a new order.', 'woocommerce-payments' ) ); } return $text; } /** * Add the notice to the thank you page in case an existing intention was successful for the order. * * @param string $text the default thank you text. * * @return string */ public function add_notice_previous_successful_intent( string $text ) { if ( isset( $_GET[ WC_Payment_Gateway_WCPay::FLAG_PREVIOUS_SUCCESSFUL_INTENT ] ) ) { // phpcs:disable WordPress.Security.NonceVerification.Recommended $text .= sprintf( '<div class="woocommerce-info">%s</div>', esc_attr__( 'We prevented multiple payments for the same order. If this was a mistake and you wish to try again, please create a new order.', 'woocommerce-payments' ) ); } return $text; }My system doesn’t appear to have any direction contact with these functions, but the logs showed the system was failing because the variable $text was coming through as null rather than as a string.
I’ve removed the casting “string” from the functions inputs and the system works again, so I will be taking off auto-updates for now but I wanted to let you know in case this was in error, or if there’s some string I need to send somewhere?
Cheers,
Paul
The topic ‘variable type casting causes error’ is closed to new replies.