fixes
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1019,6 +1019,10 @@
|
|||||||
:db/cardinality #:db{:ident :db.cardinality/one},
|
:db/cardinality #:db{:ident :db.cardinality/one},
|
||||||
:db/doc "Available Balance",
|
:db/doc "Available Balance",
|
||||||
:db/ident :plaid-account/balance}
|
:db/ident :plaid-account/balance}
|
||||||
|
{:db/valueType #:db{:ident :db.type/instant},
|
||||||
|
:db/cardinality #:db{:ident :db.cardinality/one},
|
||||||
|
:db/doc "Last synced",
|
||||||
|
:db/ident :plaid-account/last-synced}
|
||||||
|
|
||||||
{:db/unique #:db{:ident :db.unique/identity},
|
{:db/unique #:db{:ident :db.unique/identity},
|
||||||
:db/valueType #:db{:ident :db.type/string},
|
:db/valueType #:db{:ident :db.type/string},
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
(ns auto-ap.import.plaid
|
(ns auto-ap.import.plaid
|
||||||
(:require
|
(:require [auto-ap.datomic :refer [conn random-tempid]]
|
||||||
[auto-ap.datomic :refer [conn random-tempid]]
|
[auto-ap.import.common :refer [wrap-integration]]
|
||||||
[auto-ap.import.common :refer [wrap-integration]]
|
[auto-ap.import.transactions :as t]
|
||||||
[auto-ap.import.transactions :as t]
|
[auto-ap.logging :as alog]
|
||||||
[auto-ap.logging :as alog]
|
[auto-ap.plaid.core :as p]
|
||||||
[auto-ap.plaid.core :as p]
|
[auto-ap.solr]
|
||||||
[auto-ap.solr]
|
[auto-ap.time :as atime]
|
||||||
[auto-ap.time :as atime]
|
[auto-ap.utils :refer [allow-once by]]
|
||||||
[auto-ap.utils :refer [allow-once by]]
|
[clj-time.coerce :as coerce]
|
||||||
[clj-time.coerce :as coerce]
|
[clj-time.core :as time]
|
||||||
[clj-time.core :as time]
|
[clojure.string :as str]
|
||||||
[datomic.api :as dc]
|
[datomic.api :as dc]
|
||||||
[digest :as di]
|
[digest :as di]
|
||||||
[manifold.deferred :as de]
|
[iol-ion.utils :refer [remove-nils]]
|
||||||
[manifold.executor :as ex]
|
[manifold.deferred :as de]
|
||||||
[clojure.string :as str]
|
[manifold.executor :as ex]))
|
||||||
[auto-ap.ezcater.core :as e]))
|
|
||||||
|
|
||||||
(defn get-plaid-accounts
|
(defn get-plaid-accounts
|
||||||
([db]
|
([db]
|
||||||
@@ -86,31 +85,33 @@
|
|||||||
"name" (:plaid-merchant/name result)}))))
|
"name" (:plaid-merchant/name result)}))))
|
||||||
|
|
||||||
(defn upsert-accounts []
|
(defn upsert-accounts []
|
||||||
(try
|
(try
|
||||||
(doseq [[bank-account-id client-id external-id access-token] (get-plaid-accounts (dc/db conn))
|
(doseq [[bank-account-id client-id external-id access-token] (get-plaid-accounts (dc/db conn))]
|
||||||
]
|
(try
|
||||||
|
(let [accounts (p/get-accounts access-token)
|
||||||
(try
|
item (p/get-item access-token)]
|
||||||
(let [accounts (p/get-accounts access-token)]
|
@(dc/transact
|
||||||
@(dc/transact
|
conn
|
||||||
conn
|
(for [a (:accounts accounts)]
|
||||||
(for [a (:accounts accounts)]
|
(remove-nils
|
||||||
{:plaid-account/external-id (:account_id a)
|
{:plaid-account/external-id (:account_id a)
|
||||||
|
:plaid-account/last-synced (coerce/to-date (coerce/to-date-time (-> item :status :transactions :last_successful_update)))
|
||||||
:plaid-account/balance (or (some-> a
|
:plaid-account/balance (or (some-> a
|
||||||
:balances
|
:balances
|
||||||
:current
|
:current
|
||||||
double)
|
double)
|
||||||
0.0) }))
|
0.0)}))))
|
||||||
)
|
(catch Exception e
|
||||||
(catch Exception e
|
(alog/warn ::couldnt-upsert-account :error e))))
|
||||||
(alog/warn ::couldnt-upsert-account :error e))))
|
|
||||||
|
|
||||||
|
(catch Exception e
|
||||||
(catch Exception e
|
(alog/warn ::couldnt-upsert-accounts :error e))))
|
||||||
(alog/warn ::couldnt-upsert-accounts :error e))))
|
|
||||||
|
|
||||||
(defn import-plaid-int []
|
(defn import-plaid-int []
|
||||||
(let [import-batch (t/start-import-batch :import-source/plaid "Automated plaid user")
|
(let [_ (upsert-accounts)
|
||||||
|
import-batch (t/start-import-batch :import-source/plaid "Automated plaid user")
|
||||||
end (atime/local-now)
|
end (atime/local-now)
|
||||||
start (time/plus end (time/days -30))
|
start (time/plus end (time/days -30))
|
||||||
plaid-merchant->vendor-id (build-plaid-merchant->vendor-id)]
|
plaid-merchant->vendor-id (build-plaid-merchant->vendor-id)]
|
||||||
|
|||||||
@@ -11,6 +11,11 @@
|
|||||||
(def client-id (-> env :plaid :client-id))
|
(def client-id (-> env :plaid :client-id))
|
||||||
(def secret-key (-> env :plaid :secret-key))
|
(def secret-key (-> env :plaid :secret-key))
|
||||||
|
|
||||||
|
(def base-url "https://production.plaid.com")
|
||||||
|
|
||||||
|
(def client-id "61bfab05f7e762001b323f79")
|
||||||
|
|
||||||
|
(def secret-key "2be026ca5e7f7e9f23f2fb4d7c914d")
|
||||||
|
|
||||||
(defn get-link-token [client-code]
|
(defn get-link-token [client-code]
|
||||||
(-> (client/post (str base-url "/link/token/create")
|
(-> (client/post (str base-url "/link/token/create")
|
||||||
@@ -49,8 +54,16 @@
|
|||||||
:body (json/write-str {"client_id" client-id
|
:body (json/write-str {"client_id" client-id
|
||||||
"secret" secret-key
|
"secret" secret-key
|
||||||
"public_token" public-token})})
|
"public_token" public-token})})
|
||||||
:body
|
:body))
|
||||||
(doto println)))
|
|
||||||
|
(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-accounts [access-token ]
|
(defn get-accounts [access-token ]
|
||||||
(-> (client/post (str base-url "/accounts/get")
|
(-> (client/post (str base-url "/accounts/get")
|
||||||
|
|||||||
@@ -13,40 +13,73 @@
|
|||||||
|
|
||||||
(defn- page-contents [request]
|
(defn- page-contents [request]
|
||||||
[:div
|
[:div
|
||||||
|
[:div {:class "grid grid-cols-1 lg:grid-cols-2 2xl:grid-cols-3 gap-4 overflow-scroll"}
|
||||||
|
[:div.bg-blue-300.p-4.flex.flex-grow-0 "report-1"]
|
||||||
|
[:div.bg-red-300.p-4.flex.flex-grow-0 "hi"]
|
||||||
|
[:div.row-span-2
|
||||||
|
(com/card {:class "inline-block"}
|
||||||
|
[:div.p-4
|
||||||
|
|
||||||
[:h1.text-2xl.font-bold "Bank Accounts"]
|
[:h1.text-2xl.font-bold "Bank Accounts"]
|
||||||
(com/card {:class "inline-block"}
|
[:div {:class "max-h-[800px] overflow-scroll"}
|
||||||
[:div.inline-flex.flex-wrap
|
(for [c (:clients request)
|
||||||
(for [c (:clients request)
|
b (:client/bank-accounts (dc/pull (dc/db conn) '[{ :client/bank-accounts
|
||||||
b (:client/bank-accounts (dc/pull (dc/db conn) '[{ :client/bank-accounts
|
|
||||||
[:bank-account/current-balance
|
[:bank-account/current-balance
|
||||||
[ :bank-account/current-balance-synced :xform clj-time.coerce/from-date]
|
{[:bank-account/type :xform iol-ion.query/ident] [:db/ident]}
|
||||||
:bank-account/name
|
|
||||||
{:bank-account/intuit-bank-account [:intuit-bank-account/current-balance
|
[:bank-account/current-balance-synced :xform clj-time.coerce/from-date]
|
||||||
[ :intuit-bank-account/last-synced :xform clj-time.coerce/from-date]]}
|
:bank-account/name
|
||||||
{:bank-account/yodlee-account [:yodlee-account/available-balance
|
{:bank-account/intuit-bank-account [:intuit-bank-account/current-balance
|
||||||
[:yodlee-account/last-synced :xform clj-time.coerce/from-date]]}
|
[:intuit-bank-account/last-synced :xform clj-time.coerce/from-date]]}
|
||||||
{:bank-account/plaid-account [:plaid-account/balance
|
{:bank-account/yodlee-account [:yodlee-account/available-balance
|
||||||
#_[:yodlee-account/last-synced :xform clj-time.coerce/from-date]]}]}]
|
[:yodlee-account/last-synced :xform clj-time.coerce/from-date]]}
|
||||||
(:db/id c)))]
|
{:bank-account/plaid-account [:plaid-account/balance
|
||||||
[:div.flex.flex-col.p-4.border-l-2
|
[:plaid-account/last-synced :xform clj-time.coerce/from-date]]}]}]
|
||||||
[:div (:client/name c)]
|
(:db/id c)))
|
||||||
[:div (:bank-account/name b)]
|
:when (not= :bank-account-type/cash (:bank-account/type b))]
|
||||||
[:div.inline-flex.justify-between [:div "Ledger Balance"] (format "$%,.2f" (or (:bank-account/current-balance b) 0.0)) ]
|
[:div.flex.flex-col.p-4.border-b-2.border-gray-200
|
||||||
[:div.inline-flex.justify-end.text-xs.text-gray-400.it (some-> (:bank-account/current-balance-synced b)
|
[:div.font-bold.text-gray-700 (:client/name c)]
|
||||||
(atime/unparse-local atime/standard-time)
|
[:div (:bank-account/name b)]
|
||||||
(#(str "Synced " %))) ]
|
[:div.grid.grid-cols-3.gap-x-2.items-baseline
|
||||||
[:div.inline-flex.justify-between [:div "Source Balance"] (format "$%,.2f" (or (-> b :bank-account/intuit-bank-account :intuit-bank-account/current-balance)
|
[:div "Ledger Balance"]
|
||||||
(-> b :bank-account/yodlee-account :yodlee-account/available-balance)
|
[:div.text-right (format "$%,.2f" (or (:bank-account/current-balance b) 0.0))]
|
||||||
(-> b :bank-account/plaid-account :plaid-account/balance)
|
[:div.text-xs.text-gray-400.text-right (some-> (:bank-account/current-balance-synced b)
|
||||||
0.0))]
|
(atime/unparse-local atime/standard-time)
|
||||||
[:div.inline-flex.justify-end.text-xs.text-gray-400.it (or (some-> (:bank-account/intuit-bank-account b)
|
(#(str "Synced " %)))]
|
||||||
(:intuit-bank-account/last-synced)
|
|
||||||
(atime/unparse-local atime/standard-time)
|
(when-let [n (cond (-> b :bank-account/intuit-bank-account)
|
||||||
(#(str "Synced " %)))
|
"Intuit"
|
||||||
(some-> (:bank-account/yodlee-account b)
|
(-> b :bank-account/yodlee-account)
|
||||||
(:yodlee-account/last-synced)
|
"Yodlee"
|
||||||
(atime/unparse-local atime/standard-time)
|
(-> b :bank-account/plaid-account)
|
||||||
(#(str "Synced " %))))]])]) ])
|
"Plaid"
|
||||||
|
:else
|
||||||
|
nil)]
|
||||||
|
(list
|
||||||
|
[:div (str n " Balance")]
|
||||||
|
[:div.text-right (format "$%,.2f" (or (-> b :bank-account/intuit-bank-account :intuit-bank-account/current-balance)
|
||||||
|
(-> b :bank-account/yodlee-account :yodlee-account/available-balance)
|
||||||
|
(-> b :bank-account/plaid-account :plaid-account/balance)
|
||||||
|
0.0))]
|
||||||
|
[:div.text-xs.text-gray-400.text-right (or (some-> (:bank-account/intuit-bank-account b)
|
||||||
|
(:intuit-bank-account/last-synced)
|
||||||
|
(atime/unparse-local atime/standard-time)
|
||||||
|
(#(str "Synced " %)))
|
||||||
|
(some-> (:bank-account/yodlee-account b)
|
||||||
|
(:yodlee-account/last-synced)
|
||||||
|
(atime/unparse-local atime/standard-time)
|
||||||
|
(#(str "Synced " %)))
|
||||||
|
(some-> (:bank-account/plaid-account b)
|
||||||
|
(:plaid-account/last-synced)
|
||||||
|
(atime/unparse-local atime/standard-time)
|
||||||
|
(#(str "Synced " %))))]
|
||||||
|
[:div.inline-flex.justify-end.text-xs.text-gray-400.it ]))
|
||||||
|
#_[:div.inline-flex.justify-between.items-baseline]]])]])]
|
||||||
|
|
||||||
|
[:div.bg-purple-300.p-4 "hi"]
|
||||||
|
[:div.bg-slate-300.p-4 "hi"]
|
||||||
|
] ])
|
||||||
|
|
||||||
(defn page [request]
|
(defn page [request]
|
||||||
(base-page
|
(base-page
|
||||||
|
|||||||
Reference in New Issue
Block a user