(ns auto-ap.import.plaid) (let [end (atime/local-now) start (time/plus end (time/days -30)) [_ _ external-id access-token] (first (get-plaid-accounts (dc/db conn) "BCFM"))] (p/get-balance access-token)) (def g *1) (take 5 (:transactions g)) ;; => ({:account_id "Dpj0d9yKmXsOxBd0eaL4UONyEJYomNIX7kba3", ;; :balances ;; {:available nil, ;; :current 17764.42, ;; :iso_currency_code "USD", ;; :limit nil, ;; :unofficial_currency_code nil}, ;; :mask "1006", ;; :name "NICHOLAS TAPTELIS -91006", ;; :official_name "Business Gold Rewards Card", ;; :subtype "credit card", ;; :type "credit"}) (dc/q '[:find (pull ?pa [{ :plaid-item/_accounts [*]}]) :in $ ?ba :where [?ba :bank-account/plaid-account ?pa]] (dc/db conn) [:bank-account/code "VS-BA6149"]) (auto-ap.datomic/pull-attr (dc/db conn) :db/id [:bank-account/code "VS-BA6149"]) (p/get-transactions "access-production-1aee2c7d-0a57-403d-83dc-28a252fb92b4" "jZrAPpjMoLU55oZdpPVVuk8D7XVjXnuv1EJy6" (clj-time.coerce/to-date-time #inst "2024-05-01") (clj-time.coerce/to-date-time #inst "2024-05-15")) (user/init-repl) (defn import-plaid-int-2 [] (let [ import-batch (t/start-import-batch :import-source/plaid "Automated plaid user") end (atime/local-now) start (time/plus end (time/days -30)) plaid-merchant->vendor-id (build-plaid-merchant->vendor-id)] (try (doseq [[bank-account-id client-id external-id access-token] (get-plaid-accounts (dc/db conn)) :when (= bank-account-id 17592234448533) :let [_ (println "TRYING INTEGRATION") transaction-result (wrap-integration #(p/get-transactions access-token external-id start end) bank-account-id) _ (println "FOUND" (count (:transactions transaction-result))) accounts-by-id (by :account_id (:accounts transaction-result))] transaction (:transactions transaction-result)] (when (not (:pending transaction)) (t/import-transaction! import-batch (doto (assoc (plaid->transaction (assoc transaction :account (accounts-by-id (:account_id transaction))) plaid-merchant->vendor-id) :transaction/bank-account bank-account-id :transaction/client client-id) (#(println (:transaction/date %))))))) (try (rebuild-search-index) (catch Exception e (alog/error ::cant-index-plaid :error e) (println "CANT INDEX"))) (t/finish! import-batch) (println "DONE") (catch Exception e (println "FAIL") (t/fail! import-batch e))))) (import-plaid-int-2) {:transaction/bank-account 17592234448533, :transaction/date #inst "2024-05-14T07:00:00.000-00:00", :transaction/client 17592234448526, :transaction/status "POSTED", :transaction/plaid-merchant {:plaid-merchant/name "Integreat Restau", :db/id "99cb3ac3-1326-4090-8e36-721a0db3a7cf"}, :db/id "89d4fb46-bb17-436f-b1f9-505bfd67e3ec", :transaction/id "0c56701d74584f800b19b1ce6c7b15212b420626a0d0d28761bab4fec4e10ee8", :transaction/description-original "INTEGREAT RESTAU DES:ACH ID:408-340-3111 INDN:PALA UMBERTO CO ID:XXXXX03620 CCD", :transaction/amount -275.0, :transaction/raw-id "drKydaj39qUPPaR0DQyyHVrD4zb8XBIyxe9QJ"} (auto-ap.datomic/pull-attr (dc/db conn) :db/id [:bank-account/code "NGGG-CB"])