• Resolved careyrob

    (@careyrob)


    You helped me on Version 2.4.0 with a code snippet that saved the Stripe receipt URL to the order meta data. It has worked flawlessly until the 2.7.0 release. I’m currently running Woocommerce 7.5.1 and WP 6.2.

    Here’s the snippet from the original support task:

    
    add_filter( 'http_response', function ( $response, $r, $url ) {
        if (
            doing_action( 'wp_ajax_woo_mp_process_transaction' ) &&
            isset( $_REQUEST['order_id'] ) &&
            $url === 'https://api.stripe.com/v1/payment_intents'
        ) {
            $decoded_body = json_decode( wp_remote_retrieve_body( $response ) );
    
            if ( isset( $decoded_body->charges->data[0] ) ) {
                $order = wc_get_order( $_REQUEST['order_id'] );
    
                if ( $order ) {
                    $charge = $decoded_body->charges->data[0];
    
                    $order->add_meta_data( 'manual_payment_stripe_receipt_url', json_encode( [
                        'charge_id'   => $charge->id,
                        'receipt_url' => $charge->receipt_url,
                    ] ) );
    
                    $order->save();
                }
            }
        }
    
        return $response;
    }, 10, 3 );

    Here’s the original support topic: https://www.ads-software.com/support/topic/add-stripe-receipt_url-to-order_meta/#post-11954097

    It looks like the hooks and functions still exist. Did the stripe API update in woo-mp-2.7.0 cause this snippet to stop working or is it something else?

    • This topic was modified 1 year, 7 months ago by careyrob.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author bfl

    (@bfl)

    Yes, the Stripe API update in 2.7.0 breaks that snippet.

    The 2 references to charges->data[0] need to be changed to latest_charge.

    Here is the updated snippet:

    add_filter( 'http_response', function ( $response, $r, $url ) {
        if (
            doing_action( 'wp_ajax_woo_mp_process_transaction' ) &&
            isset( $_REQUEST['order_id'] ) &&
            $url === 'https://api.stripe.com/v1/payment_intents'
        ) {
            $decoded_body = json_decode( wp_remote_retrieve_body( $response ) );
    
            if ( isset( $decoded_body->latest_charge ) ) {
                $order = wc_get_order( $_REQUEST['order_id'] );
    
                if ( $order ) {
                    $charge = $decoded_body->latest_charge;
    
                    $order->add_meta_data( 'manual_payment_stripe_receipt_url', json_encode( [
                        'charge_id'   => $charge->id,
                        'receipt_url' => $charge->receipt_url,
                    ] ) );
    
                    $order->save();
                }
            }
        }
    
        return $response;
    }, 10, 3 );

    This is due to the second change listed here:
    https://stripe.com/docs/upgrades#2022-11-15

Viewing 1 replies (of 1 total)
  • The topic ‘Hook to add Stripe [receipt_url] to order_meta’ is closed to new replies.