Hopefully makes yodlee less busy.
This commit is contained in:
@@ -218,7 +218,7 @@
|
||||
|
||||
(defn maybe-autopay-invoices [{:transaction/keys [amount client bank-account] :as transaction}]
|
||||
(when-let [autopay-invoices-matches (seq (match-transaction-to-unfulfilled-autopayments amount client))]
|
||||
(add-new-payment autopay-invoices-matches bank-account client)))
|
||||
(add-new-payment transaction autopay-invoices-matches bank-account client)))
|
||||
|
||||
(defn maybe-clear-expected-deposit [{:transaction/keys [amount client date] :as transaction}]
|
||||
(when (>= amount 0.0)
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
(d/db conn))]
|
||||
(doseq [[yodlee-account bank-account client-id] account-lookup
|
||||
transaction (try
|
||||
(client/get-specific-transactions yodlee-account)
|
||||
(client/get-specific-transactions yodlee-account (client/get-auth-header))
|
||||
(catch Exception e
|
||||
(log/warn e)
|
||||
[]))]
|
||||
|
||||
@@ -174,14 +174,13 @@
|
||||
(lc/with-context {:area "upload-invoice"}
|
||||
(log/info "Number of invoices to import is" (count imports) "sample: " (first imports))
|
||||
(let [clients (d-clients/get-all)
|
||||
transactions (reduce (fn [result {:keys [invoice-number customer-identifier account-number total date vendor-code text full-text] :as info}]
|
||||
|
||||
transactions (reduce (fn [result {:keys [invoice-number customer-identifier account-number total date vendor-code text full-text]}]
|
||||
(let [
|
||||
matching-client (or (and account-number
|
||||
(parse/best-match clients account-number 0.0))
|
||||
(and customer-identifier
|
||||
(parse/best-match clients customer-identifier))
|
||||
(if client
|
||||
(when client
|
||||
(first (filter (fn [c]
|
||||
(= (:db/id c) (Long/parseLong client)))
|
||||
clients))))
|
||||
|
||||
@@ -1,99 +1,83 @@
|
||||
(ns auto-ap.routes.yodlee
|
||||
(:require
|
||||
[auto-ap.graphql :as graphql]
|
||||
[clj-http.client :as http]
|
||||
|
||||
[auto-ap.yodlee.core :as yodlee]
|
||||
[auto-ap.graphql.utils :refer [->graphql assert-admin]]
|
||||
(:require
|
||||
[auto-ap.graphql.utils :refer [assert-admin]]
|
||||
[auto-ap.routes.utils :refer [wrap-secure]]
|
||||
[clj-time.coerce :refer [to-date]]
|
||||
[ring.middleware.json :refer [wrap-json-response]]
|
||||
[compojure.core :refer [GET POST context defroutes wrap-routes]]
|
||||
[clojure.string :as str]
|
||||
[config.core :refer [env]]
|
||||
|
||||
[clojure.tools.logging :as log]))
|
||||
[auto-ap.yodlee.core :as yodlee]
|
||||
[clojure.tools.logging :as log]
|
||||
[compojure.core :refer [context defroutes GET POST wrap-routes]]
|
||||
[config.core :refer [env]]))
|
||||
|
||||
(defroutes routes
|
||||
(wrap-routes
|
||||
(context "/yodlee" []
|
||||
(GET "/fastlink" {:keys [query-params identity] :as request}
|
||||
(assert-admin identity)
|
||||
(let [[session token] (yodlee/get-access-token)]
|
||||
|
||||
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str {:session session
|
||||
:token token
|
||||
:app (:yodlee-app env)
|
||||
|
||||
:url (:yodlee-fastlink env)
|
||||
(GET "/fastlink" {:keys [identity]}
|
||||
(assert-admin identity)
|
||||
(let [[session token] (yodlee/get-access-token)]
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str {:session session
|
||||
:token token
|
||||
:app (:yodlee-app env)
|
||||
|
||||
}) }))
|
||||
(GET "/accounts" {:keys [query-params identity] :as request}
|
||||
(assert-admin identity)
|
||||
(let [[session token] (yodlee/get-access-token)]
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str (yodlee/get-accounts)) }))
|
||||
:url (:yodlee-fastlink env)})}))
|
||||
|
||||
(GET "/provider-accounts" {:keys [query-params identity] :as request}
|
||||
(assert-admin identity)
|
||||
(log/info "working on provider accounts...")
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str @yodlee/in-memory-cache) })
|
||||
(POST "/reauthenticate/:id" {:keys [query-params identity] {:keys [id]} :route-params
|
||||
data :edn-params
|
||||
:as request}
|
||||
(assert-admin identity)
|
||||
(try
|
||||
(let [[session token] (yodlee/get-access-token)]
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str (yodlee/reauthenticate (Long/parseLong id) data)) })
|
||||
(catch Exception e
|
||||
(log/error e)
|
||||
{:status 500
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)})})))
|
||||
(POST "/provider-accounts/refresh/:id" {:keys [query-params identity] {:keys [id]} :route-params :as request}
|
||||
(assert-admin identity)
|
||||
(try
|
||||
(let [[session token] (yodlee/get-access-token)]
|
||||
(yodlee/refresh-provider-account (Long/parseLong id))
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str @yodlee/in-memory-cache) })
|
||||
(catch Exception e
|
||||
{:status 400
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)})})))
|
||||
(POST "/provider-accounts/delete/:id" {:keys [query-params identity] {:keys [id]} :route-params :as request}
|
||||
(assert-admin identity)
|
||||
(try
|
||||
(let [[session token] (yodlee/get-access-token)]
|
||||
(yodlee/delete-provider-account (Long/parseLong id))
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str @yodlee/in-memory-cache) })
|
||||
(catch Exception e
|
||||
{:status 400
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)})})))
|
||||
(POST "/provider-accounts/:id" {:keys [query-params identity] {:keys [id]} :route-params :as request}
|
||||
(assert-admin identity)
|
||||
(try
|
||||
(let [[session token] (yodlee/get-access-token)]
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str (yodlee/update-yodlee (Long/parseLong id))) })
|
||||
(catch Exception e
|
||||
{:status 400
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str e)}))))
|
||||
(GET "/accounts" {:keys [identity]}
|
||||
(assert-admin identity)
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str (yodlee/get-accounts (yodlee/get-auth-header)))})
|
||||
|
||||
(GET "/provider-accounts" {:keys [identity]}
|
||||
(assert-admin identity)
|
||||
(log/info "working on provider accounts...")
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str @yodlee/in-memory-cache)})
|
||||
(POST "/reauthenticate/:id" {:keys [identity] {:keys [id]} :route-params
|
||||
data :edn-params}
|
||||
(assert-admin identity)
|
||||
(try
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str (yodlee/reauthenticate-and-recache (Long/parseLong id) data (yodlee/get-auth-header)))}
|
||||
(catch Exception e
|
||||
(log/error e)
|
||||
{:status 500
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)})})))
|
||||
(POST "/provider-accounts/refresh/:id" {:keys [identity] {:keys [id]} :route-params}
|
||||
(assert-admin identity)
|
||||
(try
|
||||
(yodlee/refresh-provider-account (Long/parseLong id) (yodlee/get-auth-header))
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str @yodlee/in-memory-cache)}
|
||||
(catch Exception e
|
||||
{:status 400
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)})})))
|
||||
(POST "/provider-accounts/delete/:id" {:keys [identity] {:keys [id]} :route-params}
|
||||
(assert-admin identity)
|
||||
(try
|
||||
(yodlee/delete-and-uncache-provider-account (Long/parseLong id) (yodlee/get-auth-header))
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str @yodlee/in-memory-cache)}
|
||||
(catch Exception e
|
||||
{:status 400
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)})})))
|
||||
(POST "/provider-accounts/:id" {:keys [identity] {:keys [id]} :route-params}
|
||||
(assert-admin identity)
|
||||
(try
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str (yodlee/update-yodlee (Long/parseLong id) (yodlee/get-auth-header)))}
|
||||
(catch Exception e
|
||||
{:status 400
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str e)}))))
|
||||
wrap-secure))
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#_{:clj-kondo/ignore [:unused-namespace]}
|
||||
(ns auto-ap.yodlee.core
|
||||
(:require [clj-http.client :as client]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[cemerick.url :as u]
|
||||
[unilog.context :as lc]
|
||||
[clojure.tools.logging :as log]
|
||||
[clojure.data.json :as json]
|
||||
[clojure.core.async :as async]
|
||||
[config.core :refer [env]]
|
||||
[mount.core :as mount]
|
||||
[yang.scheduler :as scheduler]))
|
||||
(:require
|
||||
[auto-ap.utils :refer [by]]
|
||||
[clj-http.client :as client]
|
||||
[clojure.core.async :as async]
|
||||
[clojure.data.json :as json]
|
||||
[clojure.tools.logging :as log]
|
||||
[config.core :refer [env]]
|
||||
[mount.core :as mount]
|
||||
[unilog.context :as lc]
|
||||
[yang.scheduler :as scheduler]))
|
||||
|
||||
(defn auth-header
|
||||
([cob-session] (str "{cobSession=" cob-session "}"))
|
||||
@@ -18,12 +19,12 @@
|
||||
(if (:yodlee-proxy-host env)
|
||||
{:proxy-host (:yodlee-proxy-host env)
|
||||
:proxy-port (:yodlee-proxy-port env)
|
||||
:retry-handler (fn [ex try-count http-context]
|
||||
:retry-handler (fn [ex _ _]
|
||||
(log/error "yodlee Error." ex)
|
||||
false)
|
||||
:socket-timeout 60000
|
||||
:connection-timeout 60000}
|
||||
{:retry-handler (fn [ex try-count http-context]
|
||||
{:retry-handler (fn [ex _ _]
|
||||
(log/error "yodlee Error." ex)
|
||||
false)
|
||||
:socket-timeout 60000
|
||||
@@ -37,32 +38,33 @@
|
||||
(catch Exception e
|
||||
(if (>= i 3)
|
||||
(throw e)
|
||||
(do
|
||||
(do
|
||||
(Thread/sleep 5000)
|
||||
(retry-thrice x (inc i))))))))
|
||||
|
||||
|
||||
(def base-headers {"Api-Version" "1.1"
|
||||
"Cobrand-Name" (:yodlee-cobrand-name env)
|
||||
"Cobrand-Name" (:yodlee-cobrand-name env)
|
||||
"Content-Type" "application/json"})
|
||||
|
||||
|
||||
(defn login-cobrand []
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/cobrand/login")
|
||||
(-> (str (:yodlee-base-url env) "/cobrand/login")
|
||||
(client/post (merge {:headers base-headers
|
||||
:body
|
||||
(json/write-str {:cobrand {:cobrandLogin (:yodlee-cobrand-login env)
|
||||
:cobrandPassword (:yodlee-cobrand-password env)
|
||||
:locale "en_US"}})
|
||||
:locale "en_US"}})
|
||||
:as :json}
|
||||
other-config)
|
||||
)
|
||||
other-config))
|
||||
:body
|
||||
:session
|
||||
:cobSession))))
|
||||
|
||||
|
||||
(defn login-user
|
||||
(defn login-user
|
||||
([cob-session] (login-user cob-session (:yodlee-user-login env) (:yodlee-user-password env)))
|
||||
([cob-session user password]
|
||||
(retry-thrice
|
||||
@@ -71,214 +73,159 @@
|
||||
(client/post (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
:body
|
||||
(json/write-str {:user {:loginName user
|
||||
:password password
|
||||
:locale "en_US"}})
|
||||
:password password
|
||||
:locale "en_US"}})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:user
|
||||
:session
|
||||
:userSession))))
|
||||
)
|
||||
:userSession)))))
|
||||
|
||||
(defn get-accounts []
|
||||
|
||||
(defn get-auth-header []
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)]
|
||||
(-> (str (:yodlee-base-url env) "/accounts")
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:account)))
|
||||
{"Authorization" (auth-header cob-session user-session)}))
|
||||
|
||||
(defn get-accounts-for-provider-account [provider-account-id]
|
||||
(try
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/accounts?providerAccountId=" provider-account-id)
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:account))))
|
||||
|
||||
(defn get-accounts [auth-header]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/accounts")
|
||||
(client/get (merge {:headers (merge base-headers auth-header)
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:account))))
|
||||
|
||||
|
||||
(defn get-accounts-for-provider-account [provider-account-id auth-header]
|
||||
(try
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/accounts?providerAccountId=" provider-account-id)
|
||||
(client/get (merge {:headers (merge base-headers auth-header)
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:account)))
|
||||
(catch Exception e
|
||||
(log/error (str "Couldn't get accounts for provider account '" provider-account-id "'")
|
||||
e)
|
||||
[])))
|
||||
|
||||
(defn get-account [i]
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)]
|
||||
(-> (str (:yodlee-base-url env) (str "/accounts/" i))
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:account)))
|
||||
|
||||
(defn get-provider-accounts []
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)]
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts")
|
||||
(-> (client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:query-params {"include" "credentials,questions,preferences"}
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:providerAccount))))
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn get-account [i auth-header]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) (str "/accounts/" i))
|
||||
(client/get (merge {:headers (merge base-headers auth-header)
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:account))))
|
||||
|
||||
|
||||
|
||||
(defn get-transactions []
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)
|
||||
batch-size 100
|
||||
get-transaction-batch (fn [skip]
|
||||
(-> (str (:yodlee-base-url env) "/transactions?top=" batch-size "&skip=" skip)
|
||||
|
||||
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:transaction
|
||||
))]
|
||||
|
||||
(loop [transactions []
|
||||
skip 0]
|
||||
(let [transaction-batch (get-transaction-batch skip)]
|
||||
(if (seq transaction-batch)
|
||||
(recur (concat transactions transaction-batch) (+ batch-size skip))
|
||||
transactions)))))
|
||||
|
||||
(defn get-provider-accounts []
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)
|
||||
batch-size 100]
|
||||
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts")
|
||||
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:providerAccount
|
||||
)))
|
||||
(defn get-provider-accounts [auth-header]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts")
|
||||
(client/get (merge {:headers (merge base-headers auth-header)
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:providerAccount))))
|
||||
|
||||
|
||||
|
||||
(defn get-provider-account [id]
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)
|
||||
batch-size 100]
|
||||
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts/" id)
|
||||
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:providerAccount)))
|
||||
|
||||
(defn get-provider-account-detail [id]
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)
|
||||
batch-size 100]
|
||||
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts/" id )
|
||||
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:query-params {"include" "credentials,preferences"}
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:providerAccount
|
||||
first)))
|
||||
|
||||
(defn update-provider-account [pa]
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)
|
||||
batch-size 100]
|
||||
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts?providerAccountIds=" pa)
|
||||
|
||||
(client/put (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:body "{\"dataSetName\": [\"BASIC_AGG_DATA\"]}"
|
||||
:as :json}
|
||||
other-config)))))
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn get-provider-account [id auth-header]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts/" id)
|
||||
(client/get (merge {:headers (merge base-headers auth-header)
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:providerAccount))))
|
||||
|
||||
|
||||
(defn get-provider-account-detail [id auth-header]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts/" id)
|
||||
(client/get (merge {:headers (merge base-headers auth-header)
|
||||
:query-params {"include" "credentials,preferences"}
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:providerAccount
|
||||
first))))
|
||||
|
||||
|
||||
(defn update-provider-account [pa auth-header]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts?providerAccountIds=" pa)
|
||||
(client/put (merge {:headers (merge base-headers auth-header)
|
||||
:body "{\"dataSetName\": [\"BASIC_AGG_DATA\"]}"
|
||||
:as :json}
|
||||
other-config))))))
|
||||
|
||||
|
||||
(defn get-specific-transactions [account]
|
||||
(log/infof "Getting yodlee transactions for account %s" account)
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)
|
||||
batch-size 100
|
||||
get-transaction-batch (fn [skip]
|
||||
(-> (str (:yodlee-base-url env) "/transactions?top=" batch-size "&skip=" skip "&accountId=" account)
|
||||
(defn delete-provider-account [id auth-header]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts/" id)
|
||||
(client/delete (merge {:headers (merge base-headers auth-header)
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:providerAccount
|
||||
first))))
|
||||
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:transaction
|
||||
))]
|
||||
|
||||
(loop [transactions []
|
||||
skip 0]
|
||||
(let [transaction-batch (get-transaction-batch skip)]
|
||||
(if (seq transaction-batch)
|
||||
(recur (concat transactions transaction-batch) (+ batch-size skip))
|
||||
transactions)))))
|
||||
(defn get-transaction-page
|
||||
([account batch-size skip auth-header]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/transactions?top=" batch-size "&skip=" skip "&accountId=" account)
|
||||
(client/get (merge {:headers (merge base-headers auth-header)
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:transaction))))
|
||||
([account start end batch-size skip auth-header]
|
||||
(-> (str (:yodlee-base-url env) "/transactions?top=" batch-size "&fromDate=" start "&toDate=" end "&skip=" skip "&accountId=" account)
|
||||
(client/get (merge {:headers (merge base-headers auth-header)
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:transaction)))
|
||||
|
||||
(defn get-specific-transactions-with-date [account start end]
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)
|
||||
batch-size 100
|
||||
get-transaction-batch (fn [skip]
|
||||
(-> (str (:yodlee-base-url env) "/transactions?top=" batch-size "&fromDate=" start "&toDate=" end "&skip=" skip "&accountId=" account)
|
||||
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:transaction
|
||||
))]
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn count-specific-transactions [account auth-header]
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/transactions/count?accountId=" account)
|
||||
(client/get (merge {:headers (merge base-headers auth-header)
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:transaction))))
|
||||
|
||||
(loop [transactions []
|
||||
skip 0]
|
||||
(let [transaction-batch (get-transaction-batch skip)]
|
||||
(if (seq transaction-batch)
|
||||
(recur (concat transactions transaction-batch) (+ batch-size skip))
|
||||
transactions)))))
|
||||
|
||||
(defn count-specific-transactions [account]
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)]
|
||||
|
||||
(-> (str (:yodlee-base-url env) "/transactions/count?accountId=" account)
|
||||
|
||||
(client/get (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:transaction
|
||||
)))
|
||||
|
||||
(defn get-access-token []
|
||||
(try
|
||||
(try
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)
|
||||
token (->
|
||||
token (->
|
||||
(str (:yodlee-base-url env) "/user/accessTokens?appIds=" 10003600)
|
||||
|
||||
(client/get
|
||||
(merge {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
(client/get
|
||||
(merge {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:as :json}
|
||||
other-config))
|
||||
(doto log/info)
|
||||
@@ -286,17 +233,18 @@
|
||||
:user
|
||||
:accessTokens
|
||||
first
|
||||
:value
|
||||
)]
|
||||
:value)]
|
||||
[user-session token])
|
||||
(catch Exception e
|
||||
(log/error e)
|
||||
(throw e))))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn create-user []
|
||||
(let [cob-session (login-cobrand)]
|
||||
(-> (str (:yodlee-base-url env) "/user/register")
|
||||
(client/post (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
(-> (str (:yodlee-base-url env) "/user/register")
|
||||
(client/post (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
:body (json/write-str {:user {:loginName "brycesPersoonal2"
|
||||
:password "kV@mdv3TU11"
|
||||
:email "yodleepersonal2@brycecovertoperations.com"}})
|
||||
@@ -305,24 +253,62 @@
|
||||
:body)))
|
||||
|
||||
|
||||
(defn reauthenticate [pa data auth-header]
|
||||
(try
|
||||
(retry-thrice
|
||||
(fn []
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts?providerAccountIds=" pa)
|
||||
(client/put (merge {:headers (merge base-headers auth-header)
|
||||
:body (json/write-str data)
|
||||
:as :json}
|
||||
other-config)))))
|
||||
(catch Exception e
|
||||
(log/error e))))
|
||||
|
||||
(defn get-provider-accounts-with-details []
|
||||
(let [provider-accounts (get-provider-accounts)]
|
||||
(let [concurrent 10
|
||||
output-chan (async/chan)]
|
||||
(async/pipeline-blocking concurrent
|
||||
output-chan
|
||||
(map (fn [provider-account]
|
||||
(lc/with-context {:provider-account-id (:id provider-account)}
|
||||
(get-provider-account-detail (:id provider-account)))))
|
||||
(async/to-chan provider-accounts)
|
||||
true
|
||||
(fn [e]
|
||||
(lc/with-context {:source "Yodlee"}
|
||||
(log/error "Yodlee pipeline error" e))))
|
||||
(async/<!! (async/into [] output-chan)))))
|
||||
|
||||
(defn concurrent-get-accounts-for-providers [provider-account-ids]
|
||||
;; helpers
|
||||
|
||||
|
||||
(defn get-specific-transactions [account auth-header]
|
||||
(log/infof "Getting yodlee transactions for account %s" account)
|
||||
(let [batch-size 100]
|
||||
(loop [transactions []
|
||||
skip 0]
|
||||
(let [transaction-batch (get-transaction-page account batch-size skip auth-header)]
|
||||
(if (seq transaction-batch)
|
||||
(recur (concat transactions transaction-batch) (+ batch-size skip))
|
||||
transactions)))))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn get-specific-transactions-with-date [account start end auth-header]
|
||||
(let [batch-size 100]
|
||||
(loop [transactions []
|
||||
skip 0]
|
||||
(let [transaction-batch (get-transaction-page account start end batch-size skip auth-header)]
|
||||
(if (seq transaction-batch)
|
||||
(recur (concat transactions transaction-batch) (+ batch-size skip))
|
||||
transactions)))))
|
||||
|
||||
|
||||
(defn get-provider-accounts-with-details [auth-header]
|
||||
(let [provider-accounts (get-provider-accounts auth-header)
|
||||
concurrent 10
|
||||
output-chan (async/chan)]
|
||||
(async/pipeline-blocking concurrent
|
||||
output-chan
|
||||
(map (fn [provider-account]
|
||||
(lc/with-context {:provider-account-id (:id provider-account)}
|
||||
(get-provider-account-detail (:id provider-account) auth-header))))
|
||||
(async/to-chan! provider-accounts)
|
||||
true
|
||||
(fn [e]
|
||||
(lc/with-context {:source "Yodlee"}
|
||||
(log/error "Yodlee pipeline error" e))))
|
||||
(async/<!! (async/into [] output-chan))))
|
||||
|
||||
|
||||
(defn concurrent-get-accounts-for-providers [provider-account-ids auth-header]
|
||||
(let [concurrent 20
|
||||
output-chan (async/chan)]
|
||||
(async/pipeline-blocking concurrent
|
||||
@@ -330,93 +316,70 @@
|
||||
(map (fn [provider-account-id]
|
||||
(lc/with-context {:provider-account-id provider-account-id}
|
||||
[provider-account-id
|
||||
(get-accounts-for-provider-account provider-account-id)])))
|
||||
(async/to-chan provider-account-ids)
|
||||
(get-accounts-for-provider-account provider-account-id auth-header)])))
|
||||
(async/to-chan! provider-account-ids)
|
||||
true
|
||||
(fn [e]
|
||||
(lc/with-context {:source "Yodlee"}
|
||||
(log/error "Yodlee pipeline error" e))))
|
||||
(async/<!! (async/into {} output-chan))))
|
||||
|
||||
(defn get-provider-accounts-with-accounts []
|
||||
(let [provider-accounts (by :id (get-provider-accounts-with-details))
|
||||
accounts (concurrent-get-accounts-for-providers (keys provider-accounts))]
|
||||
(->> accounts
|
||||
|
||||
(defn get-provider-accounts-with-accounts [auth-header]
|
||||
(let [provider-accounts (by :id (get-provider-accounts-with-details auth-header))
|
||||
accounts (concurrent-get-accounts-for-providers (keys provider-accounts) auth-header)]
|
||||
(->> accounts
|
||||
(reduce
|
||||
(fn [provider-accounts [which accounts]]
|
||||
(assoc-in provider-accounts [which :accounts] accounts))
|
||||
provider-accounts)
|
||||
vals)))
|
||||
|
||||
|
||||
(mount/defstate in-memory-cache
|
||||
:start (atom []))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn refresh-in-memory-cache []
|
||||
(lc/with-context {:source "refreshing-in-memory-cache"}
|
||||
(try
|
||||
(try
|
||||
(log/info "Refreshing Yodlee in memory cache")
|
||||
(reset! in-memory-cache (get-provider-accounts-with-accounts))
|
||||
|
||||
(reset! in-memory-cache (get-provider-accounts-with-accounts (get-auth-header)))
|
||||
(catch Exception e
|
||||
(log/error e)))))
|
||||
|
||||
|
||||
(mount/defstate in-memory-cache-worker
|
||||
:start (scheduler/every (* 5 60 1000) refresh-in-memory-cache)
|
||||
:stop (scheduler/stop in-memory-cache-worker))
|
||||
|
||||
|
||||
(defn refresh-provider-account [id]
|
||||
(swap! in-memory-cache
|
||||
(defn refresh-provider-account [id auth-header]
|
||||
(swap! in-memory-cache
|
||||
(fn [i]
|
||||
(-> (by :id i)
|
||||
(assoc id (assoc (get-provider-account-detail id)
|
||||
:accounts (get-accounts-for-provider-account id)))
|
||||
(assoc id (assoc (get-provider-account-detail id auth-header)
|
||||
:accounts (get-accounts-for-provider-account id auth-header)))
|
||||
vals))))
|
||||
|
||||
(defn delete-provider-account [id]
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)
|
||||
batch-size 100]
|
||||
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts/" id )
|
||||
|
||||
(client/delete (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:as :json}
|
||||
other-config))
|
||||
:body
|
||||
:providerAccount
|
||||
first))
|
||||
(swap! in-memory-cache
|
||||
(defn delete-and-uncache-provider-account [id auth-header]
|
||||
(delete-provider-account id auth-header)
|
||||
(swap! in-memory-cache
|
||||
(fn [i]
|
||||
(-> (by :id i)
|
||||
(dissoc id)
|
||||
vals))))
|
||||
|
||||
(defn update-yodlee [id]
|
||||
(update-provider-account id)
|
||||
(refresh-provider-account id)
|
||||
)
|
||||
|
||||
(defn reauthenticate [pa data]
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)
|
||||
batch-size 100]
|
||||
(defn update-yodlee [id auth-header]
|
||||
(update-provider-account id auth-header)
|
||||
(refresh-provider-account id auth-header))
|
||||
|
||||
(try
|
||||
(doto (-> (str (:yodlee-base-url env) "/providerAccounts?providerAccountIds=" pa)
|
||||
|
||||
(client/put (merge {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:body (json/write-str data)
|
||||
:as :json}
|
||||
other-config)))
|
||||
log/info)
|
||||
(refresh-provider-account pa)
|
||||
(catch Exception e
|
||||
(log/error e)))))
|
||||
(defn reauthenticate-and-recache [pa data auth-header]
|
||||
(reauthenticate pa data auth-header)
|
||||
(refresh-provider-account pa auth-header))
|
||||
|
||||
|
||||
#_(defn get-users []
|
||||
(let [cob-session (login-cobrand)]
|
||||
(-> "https://developer.api.yodlee.com/ysl/user"
|
||||
(client/get {:headers (merge base-headers {"Authorization" (auth-header cob-session)})
|
||||
:as :json})
|
||||
:body)))
|
||||
|
||||
Reference in New Issue
Block a user