1
resposta

Conexão com a API WooCommerce

Estou tentando enviar os dados do JSON através do Java, só que não consigo enviar qnd tem mais de um objeto nos campos, como o de orders, por exemplo. Mas qnd eu envio para uma categoria de campo simples ele funciona normal, alguem sabe dizer como eu consigo fazer com que os dados cheguem nessas categorias onde o JSON tem vários objetos?

o meu código está assim:

 public static void main(String[] args) throws JSONException {
        // Setup client

        OAuthConfig config = new OAuthConfig("https://olinkoriginalestaaqui.com.br",
                "chave ck",
                "chave cs");    // No código original elas já estão colocadas corretamente

        WooCommerce wooCommerce;
        wooCommerce = new WooCommerceAPI(config, ApiVersionType.V3);



        //Dizendo os campos e dando os valores

       Map <String, Object> orderInfo = new HashMap<>();
      orderInfo.put("payment_method", "bacs");
      orderInfo.put("payment_method_title", "Direct Bank Transfer");
      orderInfo.put("first_name", "Joe");
      orderInfo.put("last_name", "Doe");
      orderInfo.put("address_1", "969 Market");
      orderInfo.put("address_2", "");
      orderInfo.put("city", "San Francisco");
      orderInfo.put("state", "CA");
      orderInfo.put("postcode", "94103");
      orderInfo.put("country", "US");
      orderInfo.put("email", "john.doe@example.com");
      orderInfo.put("phone", "(555) 555-5555");
      orderInfo.put("first_name", "Joe");
      orderInfo.put("last_name", "Doe");
      orderInfo.put("address_1", "969 Market");
      orderInfo.put(  "address_2", "");
      orderInfo.put("city", "San Francisco");
      orderInfo.put("state", "CA");
      orderInfo.put("postcode", "94103");
      orderInfo.put("country", "US");


        //mapeando os pedidos
        Map order = wooCommerce.create(EndpointBaseType.ORDERS.getValue(),orderInfo);


        System.out.println(order.get("id"));


        Map <String,String> params = new HashMap<>();
        params.put("per_page", "100");
        params.put("offset", "0");
        List products = wooCommerce.getAll(EndpointBaseType.ORDERS.getValue(), params);

        System.out.println(products.size());

    }

e o que retorna é o seguinte JSON:

{
        "id": 3104,
        "parent_id": 0,
        "status": "pending",
        "currency": "BRL",
        "version": "5.9.0",
        "prices_include_tax": false,
        "date_created": "2021-12-27T14:12:53",
        "date_modified": "2021-12-27T14:12:53",
        "discount_total": "0.00",
        "discount_tax": "0.00",
        "shipping_total": "0.00",
        "shipping_tax": "0.00",
        "cart_tax": "0.00",
        "total": "0.00",
        "total_tax": "0.00",
        "customer_id": 0,
        "order_key": "wc_order_ufiuvHMWQacPl",
        "billing": {
            "first_name": "",
            "last_name": "",
            "company": "",
            "address_1": "",
            "address_2": "",
            "city": "",
            "state": "",
            "postcode": "",
            "country": "",
            "email": "",
            "phone": ""
        },
        "shipping": {
            "first_name": "",
            "last_name": "",
            "company": "",
            "address_1": "",
            "address_2": "",
            "city": "",
            "state": "",
            "postcode": "",
            "country": "",
            "phone": ""
        },
        "payment_method": "bacs",
        "payment_method_title": "Direct Bank Transfer",
        "transaction_id": "",
        "customer_ip_address": "",
        "customer_user_agent": "",
        "created_via": "rest-api",
        "customer_note": "",
        "date_completed": null,
        "date_paid": null,
        "cart_hash": "",
        "number": "3104",
        "meta_data": [],
        "line_items": [],
        "tax_lines": [],
        "shipping_lines": [],
        "fee_lines": [],
        "coupon_lines": [],
        "refunds": [],
        "date_created_gmt": "2021-12-27T14:12:53",
        "date_modified_gmt": "2021-12-27T14:12:53",
        "date_completed_gmt": null,
        "date_paid_gmt": null,
        "currency_symbol": "R$",
        "_links": {
            "self": [
                {
                    "href": "https://catalogo.rfldesigner.com.br/wp-json/wc/v3/orders/3104"
                }
            ],
            "collection": [
                {
                    "href": "https://catalogo.rfldesigner.com.br/wp-json/wc/v3/orders"
                }
            ]
        }
    }
1 resposta
O post foi fechado por inatividade. Para continuar o assunto, recomendamos criar um novo tópico. Bons Estudos!