programing

PayPal IPN 응답에서 Woocommerce 기능은 무엇입니까?

jooyons 2023. 10. 17. 20:14
반응형

PayPal IPN 응답에서 Woocommerce 기능은 무엇입니까?

우커머스로 결제가 완료되고 페이팔이 IPN을 보내면 어떤 기능이 호출되는지 파악하는 데 문제가 있습니다.

PayPal 로그 파일을 클릭하면 바로 업데이트되기 때문에 IPN이 수신되고 있습니다.Pay, 하지만 그 파일에 어떤 기능을 쓰고 있는지 알 수가 없습니다.

주문이 생성되면 관리자에게 이메일을 보낼 수 있는 기능이 이미 내장되어 있는지, 어디에서 이런 일이 발생하는지 파악해야 합니다.

존재하는 경우 다른 사람에게 이메일을 보내도록 수정해야 하고, 존재하지 않는 경우 직접 작성해야 하지만 코드를 어디에 두어야 하는지 알아야 합니다.

파일 확인하기/wp-content/plugins/woocommerce/classes/gateways/paypal/class-wc-paypal.php, 우리는 그 함수 안에 행동 고리가 있는 것을 봅니다.check_ipn_response:

if ($this->check_ipn_request_is_valid()) :

    header('HTTP/1.1 200 OK');

    do_action("valid-paypal-standard-ipn-request", $_POST);

다음과 같이 연결할 수 있습니다.

add_action( 'valid-paypal-standard-ipn-request', 'so_12967331_ipn_response', 10, 1 );

function so_12967331_ipn_response( $formdata )
{
    // do your stuff
}

@brasofilo의 답변을 토대로 현재 주문 건에 대해 제품별로 추가 작업을 해야 했습니다.

참고: 저는 데이터 직렬화를 처음 해보는데, 데이터를 얻기 위해 왜 이중 따옴표를 제거해야 했는지 모르겠습니다.unserialize()일하기 위해.그것은 오류를 던졌습니다. 그렇지 않으면요.더 나은 방법이 있을지도 모르겠네요

function so_12967331_ipn_response( $formdata ) {

    if ( !empty( $formdata['invoice'] ) && !empty( $formdata['custom'] ) ) {

        if( $formdata['payment_status'] == 'Completed' ) {

            if( is_serialized( $posted['custom'] ) ) {

                // backwards compatible
                // unserialize data
                $order_data = unserialize( str_replace('\"', '"', $posted['custom'] ) );
                $order_id = $order_data[0];

            } else {

                // custom data was changed to JSON at some point
                $order_data = (array)json_decode( $posted['custom'] );
                $order_id = $order_data['order_id'];

            }

            // get order
            $order = new WC_Order( $order_id );

            // got something to work with?
            if ( $order ) {

                // get user id
                $user_id = get_post_meta( $order_id, '_customer_user', true );

                // get user data
                $user = get_userdata( $user_id );

                // get order items
                $items = $order->get_items();

                // loop thru each item
                foreach( $items as $order_item_id => $item ) {

                    $product = new WC_Product( $item['product_id'] );

                    // do extra work...

                }   
            }   
        }
    }
}

언급URL : https://stackoverflow.com/questions/12967331/what-woocommerce-function-is-called-on-paypal-ipn-response

반응형