-
Notifications
You must be signed in to change notification settings - Fork 0
/
coupons.clj
75 lines (68 loc) · 3.37 KB
/
coupons.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
(ns wc-api-clj.v3.coupons
"Helper functions to communicate with the WooCommerce REST API's coupons endpoints.
These functions need authentication by `consumer_key` and `consumer_secret`.</br>
https://woocommerce.github.io/woocommerce-rest-api-docs/#coupons"
(:require [wc-api-clj.core :as woo]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Coupons REST API v3 helper functions ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn create-coupon
"Create coupon(s)."
[{:keys [url consumer_key consumer_secret body exception insecure]}]
(try (woo/post-req {:url (str url "/wp-json/wc/v3/coupons")
:username consumer_key
:password consumer_secret
:body body
:exception (not (not exception))
:insecure (not (not insecure))})
(catch clojure.lang.ExceptionInfo e (str (.getMessage e)))))
(defn get-coupon-by-id
"Retrieve a coupon by the coupon's ID."
[{:keys [url consumer_key consumer_secret coupon exception insecure]}]
(try (woo/get-req {:siteurl url
:uri (str "/wp-json/wc/v3/coupons/" coupon)
:username consumer_key
:password consumer_secret
:exception (not (not exception))
:insecure (not (not insecure))})
(catch clojure.lang.ExceptionInfo e (str (.getMessage e)))))
(defn get-coupons
"Retrieve all coupons."
[{:keys [url consumer_key consumer_secret exception insecure]}]
(try (woo/get-req {:siteurl url
:uri "/wp-json/wc/v3/coupons/"
:username consumer_key
:password consumer_secret
:exception (not (not exception))
:insecure (not (not insecure))})
(catch clojure.lang.ExceptionInfo e (str (.getMessage e)))))
(defn update-coupon-by-id
"Update a coupon by the coupon's ID."
[{:keys [url consumer_key consumer_secret coupon body exception insecure]}]
(try (woo/post-req {:url (str url "/wp-json/wc/v3/coupons/" coupon)
:username consumer_key
:password consumer_secret
:body body
:exception (not (not exception))
:insecure (not (not insecure))})
(catch clojure.lang.ExceptionInfo e (str (.getMessage e)))))
(defn delete-coupon-by-id
"Delete a coupon by the coupon's ID."
[{:keys [url consumer_key consumer_secret coupon exception insecure]}]
(try (woo/delete-req {:siteurl url
:uri (str "/wp-json/wc/v3/coupons/" coupon "?force=true")
:username consumer_key
:password consumer_secret
:exception (not (not exception))
:insecure (not (not insecure))})
(catch clojure.lang.ExceptionInfo e (str (.getMessage e)))))
(defn coupons-batch-operations
"CRUD multiple coupons in a batch."
[{:keys [url consumer_key consumer_secret body exception insecure]}]
(try (woo/post-req {:url (str url "/wp-json/wc/v3/coupons/batch")
:username consumer_key
:password consumer_secret
:body body
:exception (not (not exception))
:insecure (not (not insecure))})
(catch clojure.lang.ExceptionInfo e (str (.getMessage e)))))