• Resolved whatspauldoing

    (@whatspauldoing)


    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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @whatspauldoing

    Thanks for reaching out!

    This is a fairly complex development topic. These forums are meant for general support with the core functionality of WooCommerce itself. What you want to achieve is a bit complex and would require customization to do it. Since custom coding is outside our scope of support, I am leaving this thread open for a bit to see if anyone can chime in to help you out.

    For questions related to development and custom coding, your best bet is to ask on any of these channels for support. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, too.

    Hope this helps!

    Thread Starter whatspauldoing

    (@whatspauldoing)

    Thanks for your reply. I’m actually just pointing out a problem with the code. And I’m not sure how to get it to a developer over at woo.

    Is this something you could flag with a developer?

    Cheers,

    Paul

    Roxy

    (@roxannestoltz)

    Hi @whatspauldoing ,

    Thanks for clarifying!

    I’d suggest submitting a GitHub issue about this, as it would be viewed by the developers of the plugin.

    Feel free to submit one, here.

    I will go ahead and mark this thread as resolved then, however, feel free to create a new ticket should you need any further help!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘variable type casting causes error’ is closed to new replies.