Highlights plaid errors more clearly
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
[cemerick.url :as url]
|
||||
[clj-http.client :as client]
|
||||
[clojure.data.json :as json]
|
||||
[config.core :as cfg :refer [env]]))
|
||||
[config.core :as cfg :refer [env]]
|
||||
[slingshot.slingshot :refer [try+]]))
|
||||
|
||||
(def base-url (-> env :plaid :base-url))
|
||||
|
||||
@@ -50,23 +51,43 @@
|
||||
"public_token" public-token})})
|
||||
:body))
|
||||
|
||||
(defn get-item [access-token ]
|
||||
(-> (client/post (str base-url "/item/get")
|
||||
{:as :json
|
||||
:headers {"Content-Type" "application/json"}
|
||||
:body (json/write-str {"client_id" client-id
|
||||
"secret" secret-key
|
||||
"access_token" access-token})})
|
||||
:body))
|
||||
(defn get-item [access-token]
|
||||
(try+
|
||||
(-> (client/post (str base-url "/item/get")
|
||||
{:as :json
|
||||
:headers {"Content-Type" "application/json"}
|
||||
:body (json/write-str {"client_id" client-id
|
||||
"secret" secret-key
|
||||
"access_token" access-token})})
|
||||
:body)
|
||||
(catch [:status 400] x
|
||||
(let [json (try (json/read-str (:body x)) (catch Exception _
|
||||
{}))]
|
||||
(throw (ex-info
|
||||
(or (get json "error_message")
|
||||
(get json "display_message")
|
||||
(.getMessage (:throwable &throw-context)))
|
||||
json))))))
|
||||
|
||||
(defn get-accounts [access-token]
|
||||
(try+
|
||||
(-> (client/post (str base-url "/accounts/get")
|
||||
{:as :json
|
||||
:headers {"Content-Type" "application/json"}
|
||||
:body (json/write-str {"client_id" client-id
|
||||
"secret" secret-key
|
||||
"access_token" access-token})})
|
||||
:body)
|
||||
(catch [:status 400] x
|
||||
(let [json (try (json/read-str (:body x)) (catch Exception _
|
||||
{}))]
|
||||
(throw (ex-info
|
||||
(or (get json "error_message")
|
||||
(get json "display_message")
|
||||
(.getMessage (:throwable &throw-context)))
|
||||
json))))))
|
||||
|
||||
|
||||
(defn get-accounts [access-token ]
|
||||
(-> (client/post (str base-url "/accounts/get")
|
||||
{:as :json
|
||||
:headers {"Content-Type" "application/json"}
|
||||
:body (json/write-str {"client_id" client-id
|
||||
"secret" secret-key
|
||||
"access_token" access-token})})
|
||||
:body))
|
||||
|
||||
(defn get-balance [access-token ]
|
||||
(-> (client/post (str base-url "/accounts/balance/get")
|
||||
@@ -82,17 +103,28 @@
|
||||
:start (str start)
|
||||
:end (str end)
|
||||
:acct (str account-id))
|
||||
(-> (client/post (str base-url "/transactions/get")
|
||||
{:as :json
|
||||
:headers {"Content-Type" "application/json"}
|
||||
:body (json/write-str {"client_id" client-id
|
||||
"secret" secret-key
|
||||
"access_token" access-token
|
||||
"start_date" (atime/unparse start atime/iso-date)
|
||||
"end_date" (atime/unparse end atime/iso-date)
|
||||
"options" {"account_ids" [account-id]
|
||||
"count" 500}})})
|
||||
:body))
|
||||
|
||||
|
||||
(try+
|
||||
(-> (client/post (str base-url "/transactions/get")
|
||||
{:as :json
|
||||
:headers {"Content-Type" "application/json"}
|
||||
:body (json/write-str {"client_id" client-id
|
||||
"secret" secret-key
|
||||
"access_token" access-token
|
||||
"start_date" (atime/unparse start atime/iso-date)
|
||||
"end_date" (atime/unparse end atime/iso-date)
|
||||
"options" {"account_ids" [account-id]
|
||||
"count" 500}})})
|
||||
:body)
|
||||
(catch [:status 400] x
|
||||
(let [json (try (json/read-str (:body x)) (catch Exception _
|
||||
{}))]
|
||||
(throw (ex-info
|
||||
(or (get json "error_message")
|
||||
(get json "display_message")
|
||||
(.getMessage (:throwable &throw-context)))
|
||||
json))))))
|
||||
|
||||
(comment
|
||||
(require '[datomic.api :as dc])
|
||||
|
||||
@@ -1,35 +1,36 @@
|
||||
(ns auto-ap.ssr.company.plaid
|
||||
(:require
|
||||
[auto-ap.datomic
|
||||
:refer [add-sorter-fields
|
||||
apply-pagination
|
||||
apply-sort-3
|
||||
conn
|
||||
merge-query
|
||||
pull-attr
|
||||
pull-many-by-id
|
||||
query2]]
|
||||
[auto-ap.graphql.utils :refer [assert-can-see-client]]
|
||||
[auto-ap.logging :as alog]
|
||||
[auto-ap.plaid.core :as p]
|
||||
[auto-ap.ssr-routes :as ssr-routes]
|
||||
[auto-ap.ssr.components :as com]
|
||||
[auto-ap.ssr.grid-page-helper :as helper]
|
||||
[auto-ap.ssr.svg :as svg]
|
||||
[auto-ap.ssr.utils :refer [html-response]]
|
||||
[auto-ap.time :as atime]
|
||||
[bidi.bidi :as bidi]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as time]
|
||||
[datomic.api :as dc]
|
||||
[hiccup2.core :as hiccup]))
|
||||
(:require [auto-ap.datomic
|
||||
:refer [add-sorter-fields apply-pagination apply-sort-3 conn merge-query
|
||||
pull-attr pull-many-by-id query2]]
|
||||
[auto-ap.graphql.utils :refer [assert-can-see-client]]
|
||||
[auto-ap.logging :as alog]
|
||||
[auto-ap.plaid.core :as p]
|
||||
[auto-ap.ssr-routes :as ssr-routes]
|
||||
[auto-ap.ssr.components :as com]
|
||||
[auto-ap.ssr.grid-page-helper :as helper]
|
||||
[auto-ap.ssr.hx :as hx]
|
||||
[auto-ap.ssr.svg :as svg]
|
||||
[auto-ap.ssr.utils :refer [html-response]]
|
||||
[auto-ap.time :as atime]
|
||||
[bidi.bidi :as bidi]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as time]
|
||||
[clojure.string :as str]
|
||||
[datomic.api :as dc]
|
||||
[hiccup2.core :as hiccup]))
|
||||
|
||||
(def default-read '[:db/id
|
||||
:plaid-item/external-id
|
||||
:plaid-item/access-token
|
||||
:plaid-item/last-updated
|
||||
:plaid-item/status
|
||||
|
||||
{:plaid-item/accounts [:db/id
|
||||
{:bank-account/_plaid-account [{:bank-account/integration-status
|
||||
[{ [ :integration-status/state :xform iol-ion.query/ident] [:db/ident]}
|
||||
:integration-status/message
|
||||
:integration-status/last-attempt
|
||||
:integration-status/last-updated]}]}
|
||||
:plaid-account/external-id
|
||||
:plaid-account/number
|
||||
:plaid-account/balance
|
||||
@@ -169,14 +170,57 @@
|
||||
:name "Plaid Item"
|
||||
:sort-key "external-id"
|
||||
:render :plaid-item/external-id}
|
||||
{:key "status"
|
||||
:name "Status"
|
||||
:sort-key "status"
|
||||
:render #(when-let [status (:plaid-item/status %)]
|
||||
[:div [:div (com/pill {:color :primary}
|
||||
status)]
|
||||
[:div (atime/unparse-local (coerce/to-date-time (:plaid-item/last-updated %)) atime/normal-date)]])}
|
||||
{:key "integreat-plaid-status"
|
||||
:name "Integreat ↔ Plaid status"
|
||||
:sort-key "integreat-plaid-status"
|
||||
:render (fn [e]
|
||||
|
||||
(let [bad-integration (->> (:plaid-item/accounts e)
|
||||
(map (comp
|
||||
first
|
||||
:bank-account/_plaid-account))
|
||||
(filter (comp #{:integration-state/failed :integration-state/unauthorized}
|
||||
:integration-status/state
|
||||
:bank-account/integration-status))
|
||||
first
|
||||
:bank-account/integration-status)]
|
||||
[:div
|
||||
(when bad-integration
|
||||
{:x-popper (hx/json {:source "$refs.button"
|
||||
:tooltip "$refs.tooltip"})
|
||||
:x-data (hx/json {})
|
||||
})
|
||||
[:div.cursor-pointer (com/pill {:color (if bad-integration
|
||||
:red
|
||||
:primary) :x-ref "button"}
|
||||
|
||||
[:div.inline-flex.gap-2
|
||||
(or
|
||||
(some-> bad-integration
|
||||
:integration-status/state
|
||||
name
|
||||
str/capitalize)
|
||||
"Success")
|
||||
(when bad-integration
|
||||
" (detail)")
|
||||
|
||||
|
||||
(when bad-integration
|
||||
(com/tooltip {:x-ref "tooltip"}
|
||||
[:div.text-red-700
|
||||
(:integration-status/message bad-integration)]))])]
|
||||
[:div.grid.grid-cols-2.gap-1.auto-cols-min.grid-flow-row.shrink
|
||||
[:div "Attempted: "] [:div (atime/unparse-local (coerce/to-date-time (:integration-status/last-attempt e)) atime/normal-date)]
|
||||
[:div "Last Updated: "] [:div (atime/unparse-local (coerce/to-date-time (:integration-status/last-updated e)) atime/normal-date)]]]))}
|
||||
{:key "plaid-bank-status"
|
||||
:name "Plaid ↔ Bank Status"
|
||||
:sort-key "plaid-bank-status"
|
||||
:render (fn [e]
|
||||
(when-let [status (:plaid-item/status e)]
|
||||
[:div [:div (com/pill {:color :primary}
|
||||
status)]
|
||||
[:div (atime/unparse-local (coerce/to-date-time (:plaid-item/last-updated e)) atime/normal-date)]]))}
|
||||
|
||||
{:key "accounts"
|
||||
:name "Accounts"
|
||||
:show-starting "md"
|
||||
|
||||
Reference in New Issue
Block a user