Skip to content

Commit ecc71f0

Browse files
committed
Wrapper functions added for WC order notes endpoint
1 parent 92cccef commit ecc71f0

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/wc_api_clj/v3/order_notes.clj

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
(ns wc-api-clj.v3.order-notes
2+
"Helper functions to communicate with the WooCommerce REST API's order note endpoints.
3+
These functions need authentication by `consumer_key` and `consumer_secret`.</br>
4+
https://woocommerce.github.io/woocommerce-rest-api-docs/#order-notes"
5+
(:require [wc-api-clj.core :as woo]
6+
[wc-api-clj.util :as util]))
7+
8+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9+
;; Order Notes REST API v3 wrapper functions ;;
10+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11+
12+
(defn create-order-note
13+
"Create an order note."
14+
[{:keys [url consumer_key consumer_secret order body exception insecure]}]
15+
(try (woo/post-req {:siteurl url
16+
:uri (str "/wp-json/wc/v3/orders/" order "/notes")
17+
:username consumer_key
18+
:password consumer_secret
19+
:body body
20+
:exception (not (not exception))
21+
:insecure (not (not insecure))})
22+
(catch clojure.lang.ExceptionInfo e (str (.getMessage e)))))
23+
24+
(defn get-order-note-by-id
25+
"Retrieve an order note by the order and note ID."
26+
[{:keys [url consumer_key consumer_secret order note exception insecure]}]
27+
(try (woo/get-req {:siteurl url
28+
:uri (str "/wp-json/wc/v3/orders/" order "/notes/" note)
29+
:username consumer_key
30+
:password consumer_secret
31+
:exception (not (not exception))
32+
:insecure (not (not insecure))})
33+
(catch clojure.lang.ExceptionInfo e (str (.getMessage e)))))
34+
35+
(defn get-order-notes
36+
"Retrieve all order notes."
37+
[{:keys [url consumer_key consumer_secret order exception insecure]}]
38+
(try (woo/get-req {:siteurl url
39+
:uri (str "/wp-json/wc/v3/orders/" order "/notes")
40+
:username consumer_key
41+
:password consumer_secret
42+
:exception (not (not exception))
43+
:insecure (not (not insecure))})
44+
(catch clojure.lang.ExceptionInfo e (str (.getMessage e)))))
45+
46+
(defn delete-order-note-by-id
47+
"Delete an order by the order and note ID."
48+
[{:keys [url consumer_key consumer_secret order note exception insecure]}]
49+
(try (woo/delete-req {:siteurl url
50+
:uri (str "/wp-json/wc/v3/orders/" order "/notes/" note (util/edn-to-query-str {:force true}))
51+
:username consumer_key
52+
:password consumer_secret
53+
:exception (not (not exception))
54+
:insecure (not (not insecure))})
55+
(catch clojure.lang.ExceptionInfo e (str (.getMessage e)))))

0 commit comments

Comments
 (0)