|
| 1 | +(ns wc-api-clj.v3.order-refunds |
| 2 | + "Helper functions to communicate with the WooCommerce REST API's order refund endpoints. |
| 3 | + These functions need authentication by `consumer_key` and `consumer_secret`.</br> |
| 4 | + https://woocommerce.github.io/woocommerce-rest-api-docs/#order-refunds" |
| 5 | + (:require [wc-api-clj.core :as woo] |
| 6 | + [wc-api-clj.util :as util])) |
| 7 | + |
| 8 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 9 | +;; Order Refunds REST API v3 wrapper functions ;; |
| 10 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 11 | + |
| 12 | +(defn create-order-refund |
| 13 | + "Create an order refund." |
| 14 | + [{:keys [url consumer_key consumer_secret order api_refund body exception insecure]}] |
| 15 | + (try (woo/post-req {:siteurl url |
| 16 | + :uri (str "/wp-json/wc/v3/orders/" order "/refunds" (util/edn-to-query-str {:api_refund api_refund})) |
| 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-refund-by-id |
| 25 | + "Retrieve an order refund by the order and refund ID." |
| 26 | + [{:keys [url consumer_key consumer_secret order refund exception insecure]}] |
| 27 | + (try (woo/get-req {:siteurl url |
| 28 | + :uri (str "/wp-json/wc/v3/orders/" order "/refunds/" refund) |
| 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-refunds |
| 36 | + "Retrieve all order refunds." |
| 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 "/refunds") |
| 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-refund-by-id |
| 47 | + "Delete an order by the order and refund ID." |
| 48 | + [{:keys [url consumer_key consumer_secret order refund exception insecure]}] |
| 49 | + (try (woo/delete-req {:siteurl url |
| 50 | + :uri (str "/wp-json/wc/v3/orders/" order "/refunds/" refund (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