Skip to content

Commit

Permalink
Merge pull request #30 from AdGoji/fix/29-too-many-requests-error
Browse files Browse the repository at this point in the history
Handle 429 error properly
  • Loading branch information
roman-rudakov authored Mar 18, 2024
2 parents 38072e3 + 4e00c0d commit 39bcb97
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ pom.xml.asc
.cpcache/

# End of https://www.toptal.com/developers/gitignore/api/clojure
/.clj-kondo/.cache/
9 changes: 8 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased] ##

## [0.4.1] - 2024-03-18 ##

### Fixed ###

- HTTP error code 429 is not handled properly ([#29](https://github.com/AdGoji/mollie/issues/29)).

## [0.4.0] - 2024-02-28 ##

### Added ###
Expand Down Expand Up @@ -94,7 +100,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Mandates management ([#1](https://github.com/AdGoji/mollie/issues/1)).
- Subscriptions management ([#1](https://github.com/AdGoji/mollie/issues/1)).

[unreleased]: https://github.com/AdGoji/mollie/compare/0.4.0..HEAD
[unreleased]: https://github.com/AdGoji/mollie/compare/0.4.1..HEAD
[0.4.1]: https://github.com/AdGoji/mollie/compare/0.4.0..0.4.1
[0.4.0]: https://github.com/AdGoji/mollie/compare/0.3.6..0.4.0
[0.3.6]: https://github.com/AdGoji/mollie/compare/0.3.5..0.3.6
[0.3.5]: https://github.com/AdGoji/mollie/compare/0.3.4..0.3.5
Expand Down
2 changes: 1 addition & 1 deletion build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[deps-deploy.deps-deploy :as dd]))

(def lib 'com.adgoji/mollie)
(def version "0.4.0")
(def version "0.4.1")
(def class-dir "target/classes")
(def basis (b/create-basis {:project "deps.edn"}))
(def jar-file (format "target/%s-%s.jar" (name lib) version))
Expand Down
4 changes: 2 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{:paths ["src" "spec"]

:deps {org.clojure/clojure {:mvn/version "1.11.1"}
:deps {org.clojure/clojure {:mvn/version "1.11.2"}
org.clojure/data.json {:mvn/version "2.5.0"}
org.clojure/spec.alpha {:mvn/version "0.4.233"}
camel-snake-kebab/camel-snake-kebab {:mvn/version "0.4.3"}
Expand All @@ -23,6 +23,6 @@
"--codecov"]}

:build
{:deps {io.github.clojure/tools.build {:mvn/version "0.9.6"}
{:deps {io.github.clojure/tools.build {:mvn/version "0.10.0"}
slipset/deps-deploy {:mvn/version "0.2.2"}}
:ns-default build}}}
5 changes: 3 additions & 2 deletions src/com/adgoji/mollie/api/payments.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
[com.adgoji.utils.spec :as spec]
[com.adgoji.mollie.refund :as refund]
[clojure.string :as str]
[com.adgoji.mollie.chargeback :as chargeback])
[com.adgoji.mollie.chargeback :as chargeback]
[camel-snake-kebab.core :as csk])
(:import
(java.time Instant LocalDate)))

Expand Down Expand Up @@ -72,7 +73,7 @@
card-country-code (assoc ::creditcard/card-country-code card-country-code)
card-security (assoc ::creditcard/card-security (keyword card-security))
fee-region (assoc ::creditcard/fee-region fee-region)
failure-reason (assoc ::creditcard/failure-reason (keyword failure-reason))
failure-reason (assoc ::creditcard/failure-reason (csk/->kebab-case-keyword failure-reason))
failure-message (assoc ::creditcard/failure-message failure-message)
wallet (assoc ::creditcard/wallet (keyword wallet))))

Expand Down
2 changes: 1 addition & 1 deletion src/com/adgoji/mollie/client.clj
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
(404 410) ::anomalies/not-found
405 ::anomalies/unsupported
500 ::anomalies/fault
503 ::anomalies/busy)
(429 503) ::anomalies/busy)
error {::anomalies/category anomaly
:error body}]
(if throw-exceptions?
Expand Down
10 changes: 7 additions & 3 deletions test/com/adgoji/mollie/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@
(if-let [customers (->> (sut/get-customers-list utils/*mollie-client*
{:limit 50})
::mollie/customers
(sequence utils/test-customer-xf)
seq)]
(rand-nth customers)
(sut/create-customer utils/*mollie-client* {:metadata utils/default-metadata})))
(sut/create-customer utils/*mollie-client*
{:metadata utils/default-metadata})))

(defn- ensure-customer-without-mandate []
(if-let [customers (->> (sut/get-customers-list utils/*mollie-client*
{:limit 50})
::mollie/customers
(sequence (remove ::link/mandates))
(sequence (comp (remove ::link/mandates)
utils/test-customer-xf))
seq)]
(let [customer (rand-nth customers)]
(if-not (->> (sut/get-mandates-list utils/*mollie-client*
Expand All @@ -42,7 +45,8 @@
seq)
customer
(recur)))
(sut/create-customer utils/*mollie-client* {:metadata utils/default-metadata})))
(sut/create-customer utils/*mollie-client*
{:metadata utils/default-metadata})))

(defn- ensure-mandate [customer-id]
(if-let [mandates (->> (sut/get-mandates-list utils/*mollie-client*
Expand Down
13 changes: 9 additions & 4 deletions test/com/adgoji/mollie/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@
(or (System/getenv "MOLLIE_PROFILE_ID")
(:profile-id secrets)))

(def test-purpose "api-client-test")
(defonce test-execution-id (str (random-uuid)))

(def default-metadata {:purpose test-purpose})
(def default-metadata {:execution-id test-execution-id})

(def test-customer-xf
(filter (fn [cus]
(= test-execution-id
(get-in cus [::customer/metadata :execution-id])))))

(def ^:dynamic *mollie-client* nil)

Expand Down Expand Up @@ -60,8 +65,8 @@
(defn- customers-to-cleaunup []
(->> (mollie.api/get-customers-list *mollie-client* {})
(::mollie/customers)
(sequence (filter (fn [customer]
(= test-purpose (get-in customer [::customer/metadata :purpose])))))))
(sequence test-customer-xf)))

(defn mollie-cleanup []
(doseq [{customer-id ::customer/id} (customers-to-cleaunup)]
(cleanup-payments customer-id)
Expand Down

0 comments on commit 39bcb97

Please sign in to comment.