-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from codemascot/f/13/refunds
FIX #13
- Loading branch information
Showing
3 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
(ns wc-api-clj.v3.order-refunds | ||
"Helper functions to communicate with the WooCommerce REST API's order refund endpoints. | ||
These functions need authentication by `consumer_key` and `consumer_secret`.</br> | ||
https://woocommerce.github.io/woocommerce-rest-api-docs/#order-refunds" | ||
(:require [wc-api-clj.core :as woo] | ||
[wc-api-clj.util :as util])) | ||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; Order Refunds REST API v3 wrapper functions ;; | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
|
||
(defn create-order-refund | ||
"Create an order refund." | ||
[{:keys [url consumer_key consumer_secret order api_refund body exception insecure]}] | ||
(try (woo/post-req {:siteurl url | ||
:uri (str "/wp-json/wc/v3/orders/" order "/refunds" (util/edn-to-query-str {:api_refund api_refund})) | ||
: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-order-refund-by-id | ||
"Retrieve an order refund by the order and refund ID." | ||
[{:keys [url consumer_key consumer_secret order refund exception insecure]}] | ||
(try (woo/get-req {:siteurl url | ||
:uri (str "/wp-json/wc/v3/orders/" order "/refunds/" refund) | ||
:username consumer_key | ||
:password consumer_secret | ||
:exception (not (not exception)) | ||
:insecure (not (not insecure))}) | ||
(catch clojure.lang.ExceptionInfo e (str (.getMessage e))))) | ||
|
||
(defn get-order-refunds | ||
"Retrieve all order refunds." | ||
[{:keys [url consumer_key consumer_secret order exception insecure]}] | ||
(try (woo/get-req {:siteurl url | ||
:uri (str "/wp-json/wc/v3/orders/" order "/refunds") | ||
:username consumer_key | ||
:password consumer_secret | ||
:exception (not (not exception)) | ||
:insecure (not (not insecure))}) | ||
(catch clojure.lang.ExceptionInfo e (str (.getMessage e))))) | ||
|
||
(defn delete-order-refund-by-id | ||
"Delete an order by the order and refund ID." | ||
[{:keys [url consumer_key consumer_secret order refund exception insecure]}] | ||
(try (woo/delete-req {:siteurl url | ||
:uri (str "/wp-json/wc/v3/orders/" order "/refunds/" refund (util/edn-to-query-str {:force true})) | ||
:username consumer_key | ||
:password consumer_secret | ||
:exception (not (not exception)) | ||
:insecure (not (not insecure))}) | ||
(catch clojure.lang.ExceptionInfo e (str (.getMessage e))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
(ns wc-api-clj.v3.order-refunds-test | ||
(:require [clojure.test :refer :all] | ||
[wc-api-clj.v3.orders :refer :all] | ||
[wc-api-clj.v3.order-refunds :refer :all] | ||
[wc-api-clj.core-test :refer [credentials]] | ||
[clojure.data.json :as json])) | ||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; Test for v3/order-refunds API ;; | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
|
||
(deftest order-refund-v3-api-create-read-delete-success-test | ||
(testing "Testing order-refund v3 API for create, read and delete." | ||
(let [order (-> {:url (:siteurl credentials) | ||
:consumer_key (:ckw credentials) | ||
:consumer_secret (:csw credentials) | ||
:exception false | ||
:insecure true | ||
:body (json/write-str (:order_to_create credentials))} | ||
(create-order))] | ||
(is (< 0 (:id order))) | ||
(let [refund (-> {:url (:siteurl credentials) | ||
:consumer_key (:ckw credentials) | ||
:consumer_secret (:csw credentials) | ||
:exception false | ||
:order (:id order) | ||
:api_refund false | ||
:insecure true | ||
:body (json/write-str {:refund_to_create credentials})} | ||
create-order-refund)] | ||
(is (< 0 (:id refund))) | ||
(is (< 0 (-> {:url (:siteurl credentials) | ||
:consumer_key (:ckr credentials) | ||
:consumer_secret (:csr credentials) | ||
:order (:id order) | ||
:exception false | ||
:insecure true} | ||
get-order-refunds | ||
first | ||
:id))) | ||
(is (= (:id refund) (-> {:url (:siteurl credentials) | ||
:consumer_key (:ckr credentials) | ||
:consumer_secret (:csr credentials) | ||
:order (:id order) | ||
:refund (:id refund) | ||
:exception false | ||
:insecure true} | ||
get-order-refund-by-id | ||
:id))) | ||
(is (= (:id refund) (-> {:url (:siteurl credentials) | ||
:consumer_key (:ckw credentials) | ||
:consumer_secret (:csw credentials) | ||
:order (:id order) | ||
:refund (:id refund) | ||
:exception false | ||
:insecure true} | ||
delete-order-refund-by-id | ||
:id)))) | ||
(is (= (:id order) (-> {:url (:siteurl credentials) | ||
:consumer_key (:ckw credentials) | ||
:consumer_secret (:csw credentials) | ||
:order (:id order) | ||
:exception false | ||
:insecure true} | ||
delete-order-by-id | ||
:id)))))) |