Error 400 Invalid “products[1].productId” Kinguin

I’m receiving this message “Error 400 Invalid “products[1].productId” property. This collection should contain only elements with unique value in “productId” property.”

From this plugin: https://wordpress.org/plugins/kinguin/ on: https://github.com/kinguinltdhk/Kinguin-eCommerce-API/issues/46

Someone else is having a similar issue. How should I go about fixing it?

I was looking at this code, but I don’t know if I’m looking in the right place:

<?php
/**
 * Product WebHook class.
 *
 * @package WPDeskILKinguin
 */

namespace WPDeskILKinguinCommon;

use WPDeskILKinguinAdminConfiguration;
use WPDeskILKinguinAdminExceptionsKinguinWebHookIncorrectSecret;
use WPDeskILKinguinAdminKinguinAPI;
use WPDeskILKinguinAdminProductInsertUpdate;

defined( 'ABSPATH' ) || exit;

class ProductWebHook {
    use Configuration;



    /**
     * Register product update route.
     */
    public function register_route() {
        register_rest_route(
            'kinguin/v1',
            '/products/update',
            array(
                'methods'             => WP_REST_Server::CREATABLE,
                'callback'            => array( $this, 'update_product' ),
                'args'                => array(),
                'permission_callback' => function() {
                    return true;
                }
            )
        );
    }



    /**
     * Validate response and send Rest API response
     *
     * @param WP_REST_Request $request Incoming request with order status update.
     *
     * @see https://github.com/kinguinltdhk/Kinguin-eCommerce-API/blob/master/features/Webhooks.md#product-updated-webhook
     */
    public function update_product( WP_REST_Request $request ) {

        if ( $request->is_json_content_type() ) {
            try {
                if ( $this->check_secret( $request->get_header( 'X-Event-Secret' ) ) ) {
                    $body     = json_decode( $request->get_body(), true );
                    $response = $this->event_handler( $body );
                }
            } catch ( Exception $e ) {
                $response = array(
                    'status'        => $e->getCode(),
                    'response'      => $e->getMessage(),
                );
                //wc_get_logger()->debug( 'Error for webhook: ', array( 'source' => 'kinguin-debug-log' ) );
                //wc_get_logger()->debug( print_r( $e->getCode(), true), array( 'source' => 'kinguin-debug-log' ) );
                //wc_get_logger()->debug( print_r( $e->getMessage(), true), array( 'source' => 'kinguin-debug-log' ) );
            }

        } else {
            $response = array(
                'status'        => 406,
                'response'      => 'Not Acceptable',
            );
        }

        return new WP_REST_Response( $response ? $response : null, 204 );
    }



    /**
     * Check and validate X-Event-Secret value from request header.
     *
     * @param string|null $secret X-Event-Secret value.
     *
     * @return bool
     *
     * @throws WPDeskILKinguinAdminExceptionsKinguinWebHookIncorrectSecret Incorrect X-Event-Secret value.
     */
    private function check_secret( $secret ) : bool {
        if ( $secret === $this->get_products_webhook_secret() ) {
            return true;
        } else {
            throw new KinguinWebHookIncorrectSecret( 401, 'Incorrect X-Event-Secret' );
        }
    }



    /**
     * Event switcher
     *
     * @param string $event Available int this method: order.complete, order.status.
     * @param array $body Response body.
     *
     * @return array
     *
     * @throws WPDeskILKinguinAdminExceptionsKinguinMissingApiKeyException No Api Key provided.
     * @throws WPDeskILKinguinAdminExceptionsKinguinNoConnectionException  No connection.
     * @throws WPDeskILKinguinAdminExceptionsKinguinStatusCodeException    Exception for any other status code than 200.
     */
    private function event_handler( array $body ) {
        $product = $this->request_product( $body['productId'] );
        $post = new InsertUpdate();
        $post->set_currency_rate();
        if ( $post->manage_webhook( $product ) ) {
            return array(
                'status'   => 200,
                'response' => 'Product updated'
            );
        } else {
            return array(
                'status'   => 404,
                'response' => 'Product not found'
            );
        }
    }



    /**
     * Request product object from Kinguin API
     *
     * @param string $product_id Kinguin productId.
     *
     * @return array Kinguin product.
     *
     * @throws WPDeskILKinguinAdminExceptionsKinguinMissingApiKeyException
     * @throws WPDeskILKinguinAdminExceptionsKinguinNoConnectionException
     * @throws WPDeskILKinguinAdminExceptionsKinguinStatusCodeException
     *
     * @see https://github.com/kinguinltdhk/Kinguin-eCommerce-API/tree/master/api/products/v2#get-product
     */
    private function request_product( $product_id ) {
        try {
            $product = ( new KinguinAPI() )->get( $this->get_api_url() . '/v2/products/' . $product_id );
            $product = json_decode( json_encode( $product ), true, 512, JSON_OBJECT_AS_ARRAY );
            return $product;
        } catch ( Exception $error ) {
            wc_get_logger()->debug( 'Kinguin request_product error: ', array( 'source' => 'kinguin-debug-log' ) );
            wc_get_logger()->debug( print_r( $error->getMessage(), true), array( 'source' => 'kinguin-debug-log' ) );
            throw $error;
        }
    }

}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật