programing

WooCommerce Order API는 항상 빈 주문을 만듭니다.

madecode 2023. 3. 14. 22:04
반응형

WooCommerce Order API는 항상 빈 주문을 만듭니다.

Woo Commerce API(v3.4.4)를 가지고 놀고 있습니다.다음과 같은 제품을 얻을 수 있습니다.

curl -X GET \
  'http://localhost/wp-json/wc/v2/products/7?oauth_consumer_key=ck_8cbe42fb09c04954a63994c22145270f27871dec&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1535381325&oauth_nonce=iApWJblA1A5&oauth_version=1.0&oauth_signature=9T1T43FvOpBzVBU+RQS90zMB/XM=' \
  -H 'Cache-Control: no-cache' \
  -H 'Postman-Token: bdb7f5c9-5719-4bcf-b4fc-38aed3bd5d08'

다음과 같은 답변을 받았습니다.

{
    "id": 7,
    "name": "Test product",
    "slug": "test-product",
    "permalink": "http://localhost/product/test-product/",
    "date_created": "2018-08-22T15:25:26",
    "date_created_gmt": "2018-08-22T15:25:26",
    "date_modified": "2018-08-22T15:25:26",
    "date_modified_gmt": "2018-08-22T15:25:26",
    "type": "simple",
    "status": "publish",
    "featured": false,
    "catalog_visibility": "visible",
    "description": "<p>this is a test product</p>\n",
    "short_description": "<p>the short desc</p>\n",
    "sku": "",
    "price": "9",
    "regular_price": "10",
    "sale_price": "9",
    "date_on_sale_from": null,
    "date_on_sale_from_gmt": null,
    "date_on_sale_to": null,
    "date_on_sale_to_gmt": null,
    "price_html": "<del><span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">&euro;</span>10.00</span></del> <ins><span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">&euro;</span>9.00</span></ins>",
    "on_sale": true,
    "purchasable": true,
    "total_sales": 3,
    "virtual": false,
    "downloadable": false,
    "downloads": [],
    "download_limit": -1,
    "download_expiry": -1,
    "external_url": "",
    "button_text": "",
    "tax_status": "taxable",
    "tax_class": "",
    "manage_stock": false,
    "stock_quantity": null,
    "in_stock": true,
    "backorders": "no",
    "backorders_allowed": false,
    "backordered": false,
    "sold_individually": false,
    "weight": "",
    "dimensions": {
        "length": "",
        "width": "",
        "height": ""
    },
    "shipping_required": true,
    "shipping_taxable": true,
    "shipping_class": "",
    "shipping_class_id": 0,
    "reviews_allowed": true,
    "average_rating": "0.00",
    "rating_count": 0,
    "related_ids": [
        36,
        41
    ],
    "upsell_ids": [],
    "cross_sell_ids": [],
    "parent_id": 0,
    "purchase_note": "",
    "categories": [
        {
            "id": 15,
            "name": "Uncategorized",
            "slug": "uncategorized"
        }
    ],
    "tags": [],
    "images": [
        {
            "id": 8,
            "date_created": "2018-08-22T15:24:00",
            "date_created_gmt": "2018-08-22T15:24:00",
            "date_modified": "2018-08-22T15:24:00",
            "date_modified_gmt": "2018-08-22T15:24:00",
            "src": "http://localhost/wp-content/uploads/2018/08/sock.jpeg",
            "name": "sock",
            "alt": "",
            "position": 0
        }
    ],
    "attributes": [
        {
            "id": 0,
            "name": "size",
            "position": 0,
            "visible": true,
            "variation": false,
            "options": [
                "small",
                "medium",
                "large"
            ]
        }
    ],
    "default_attributes": [],
    "variations": [],
    "grouped_products": [],
    "menu_order": 0,
    "meta_data": [],
    "_links": {
        "self": [
            {
                "href": "http://localhost/wp-json/wc/v2/products/7"
            }
        ],
        "collection": [
            {
                "href": "http://localhost/wp-json/wc/v2/products"
            }
        ]
    }
}

그러면 명령줄에서 CURL을 사용하여 요청을 실행하고 Postman에서 요청을 실행할 수 있습니다.

이제 주문을 작성하려고 합니다.

curl -X POST \
  'http://localhost/wp-json/wc/v2/orders?oauth_consumer_key=ck_8cbe42fb09c04954a63994c22145270f27871dec&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1535382336&oauth_nonce=P8RWaD9DnZ9&oauth_version=1.0&oauth_signature=GFxtI7+gqbah5fu68gSdqL4V3fs=' \
  -H 'Cache-Control: no-cache' \
  -H 'Postman-Token: f17bec6a-c76b-4a6c-8797-1df9dac73f36' \
  -d '{
  "payment_method": "bacs",
  "payment_method_title": "Direct Bank Transfer",
  "set_paid": true,
  "billing": {
    "first_name": "John",
    "last_name": "Doe",
    "address_1": "969 Market",
    "address_2": "",
    "city": "San Francisco",
    "state": "CA",
    "postcode": "94103",
    "country": "US",
    "email": "john.doe@example.com",
    "phone": "(555) 555-5555"
  },
  "shipping": {
    "first_name": "John",
    "last_name": "Doe",
    "address_1": "969 Market",
    "address_2": "",
    "city": "San Francisco",
    "state": "CA",
    "postcode": "94103",
    "country": "US"
  },
  "line_items": [
    {
      "product_id": 7,
      "quantity": 1
    }
  ],
  "shipping_lines": [
    {
      "method_id": "flat_rate",
      "method_title": "Flat Rate",
      "total": 7
    }
  ]
}'

위의 요청을 Postman에서 실행하면 빈 주문이 생성되고 다음과 같은 응답이 나타납니다.

{
    "id": 59,
    "parent_id": 0,
    "number": "59",
    "order_key": "wc_order_5b8413f8ed585",
    "created_via": "rest-api",
    "version": "3.4.4",
    "status": "pending",
    "currency": "EUR",
    "date_created": "2018-08-27T15:08:40",
    "date_created_gmt": "2018-08-27T15:08:40",
    "date_modified": "2018-08-27T15:08:41",
    "date_modified_gmt": "2018-08-27T15:08:41",
    "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",
    "prices_include_tax": false,
    "customer_id": 0,
    "customer_ip_address": "",
    "customer_user_agent": "",
    "customer_note": "",
    "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": ""
    },
    "payment_method": "",
    "payment_method_title": "",
    "transaction_id": "",
    "date_paid": null,
    "date_paid_gmt": null,
    "date_completed": null,
    "date_completed_gmt": null,
    "cart_hash": "",
    "meta_data": [],
    "line_items": [],
    "tax_lines": [],
    "shipping_lines": [],
    "fee_lines": [],
    "coupon_lines": [],
    "refunds": [],
    "_links": {
        "self": [
            {
                "href": "http://localhost/wp-json/wc/v2/orders/59"
            }
        ],
        "collection": [
            {
                "href": "http://localhost/wp-json/wc/v2/orders"
            }
        ]
    }
}

이상하게도 명령줄에서 CURL을 사용하여 동일한 요청을 실행하면 다음과 같은 응답이 나타납니다.

{"code":"woocommerce_rest_authentication_error","message":"Invalid signature - provided signature does not match.","data":{"status":401}}

우체국에서 요청을 실행하면"product_id"사용하고 있다"this is a completely fake id"빈 주문을 만들고 다음과 같이 응답합니다.

{
    "id": 60,
    "parent_id": 0,
    "number": "60",
    "order_key": "wc_order_5b84148e002da",
    "created_via": "rest-api",
    "version": "3.4.4",
    "status": "pending",
    "currency": "EUR",
    "date_created": "2018-08-27T15:11:10",
    "date_created_gmt": "2018-08-27T15:11:10",
    "date_modified": "2018-08-27T15:11:10",
    "date_modified_gmt": "2018-08-27T15:11:10",
    "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",
    "prices_include_tax": false,
    "customer_id": 0,
    "customer_ip_address": "",
    "customer_user_agent": "",
    "customer_note": "",
    "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": ""
    },
    "payment_method": "",
    "payment_method_title": "",
    "transaction_id": "",
    "date_paid": null,
    "date_paid_gmt": null,
    "date_completed": null,
    "date_completed_gmt": null,
    "cart_hash": "",
    "meta_data": [],
    "line_items": [],
    "tax_lines": [],
    "shipping_lines": [],
    "fee_lines": [],
    "coupon_lines": [],
    "refunds": [],
    "_links": {
        "self": [
            {
                "href": "http://localhost/wp-json/wc/v2/orders/60"
            }
        ],
        "collection": [
            {
                "href": "http://localhost/wp-json/wc/v2/orders"
            }
        ]
    }
}

몇 가지 문제가 있습니다.

1/ 어떤 product_id를 사용하든 작성된 주문은 항상 비어 있습니다.

2/ 가짜 product_id를 제공해도 Woo Commerce에서 주문이 작성됩니다.확실히 이건 잘못된 건가요?

3/ 명령줄에서 Create Order 요청을 실행하면 Postman에게 다른 응답이 나타납니다.

나는 놓쳤다:

-H 'Content-Type: application/json' \

요청에서.Postman에 입력했지만 체크박스를 켜지 않았습니다.

여기에 이미지 설명 입력

언급URL : https://stackoverflow.com/questions/52042325/woocommerce-order-api-always-creates-empty-orders

반응형