Add vendor pre-population for bulk code and individual edit forms
- Add vendor-changed HTMX handlers for both bulk code and individual edit - Pre-populate default account at 100% when vendor is selected and no accounts exist - Fix render-accounts-section to render from step-params correctly - Change bulk code vendor-changed from hx-get to hx-post to include form data - Add routes for vendor-changed endpoints - Update e2e tests to cover vendor pre-population - Run lein cljfmt fix across codebase
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
|
||||
;; (def base-url "https://sandbox-quickbooks.api.intuit.com/v3")
|
||||
|
||||
|
||||
(def prod-client-id "ABFRwAiOqQiLN66HKplXfyRE3ipD390DHsrUquflRCiOa81mxa")
|
||||
(def prod-client-secret "xDUj04GeQXpLvrhxep1jjDYwjJWbzzOPrirUQTKF")
|
||||
|
||||
@@ -27,21 +26,18 @@
|
||||
;; "accessToken":,
|
||||
;;
|
||||
|
||||
|
||||
|
||||
(def prod-company-id "123146163906404")
|
||||
|
||||
|
||||
(def prod-base-url "https://quickbooks.api.intuit.com/v3")
|
||||
|
||||
(defn set-access-token [t]
|
||||
(s3/put-object :bucket-name (:data-bucket env)
|
||||
(s3/put-object :bucket-name (:data-bucket env)
|
||||
:key (str "intuit/access-token")
|
||||
:input-stream (io/make-input-stream (.getBytes t) {})
|
||||
:metadata {:content-type "application/text"
|
||||
:content-length (count (.getBytes t))}))
|
||||
(defn set-refresh-token [t]
|
||||
(s3/put-object :bucket-name (:data-bucket env)
|
||||
(s3/put-object :bucket-name (:data-bucket env)
|
||||
:key (str "intuit/refresh-token")
|
||||
:input-stream (io/make-input-stream (.getBytes t) {})
|
||||
:metadata {:content-type "application/text"
|
||||
@@ -53,7 +49,6 @@
|
||||
:bucket-name "data.prod.app.integreatconsult.com"
|
||||
:key "intuit/refresh-token")))))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn init-tokens [access refresh]
|
||||
(set-access-token access)
|
||||
@@ -74,17 +69,16 @@
|
||||
(defn get-basic-auth []
|
||||
(Base64/encodeBase64String (.getBytes (str prod-client-id ":" prod-client-secret))))
|
||||
|
||||
|
||||
(defn get-fresh-access-token []
|
||||
(let [refresh-token (lookup-refresh-token)
|
||||
response (:body (client/post (str "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer" )
|
||||
response (:body (client/post (str "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer")
|
||||
|
||||
{:headers {"Accept" "application/json"
|
||||
"Content-Type" "application/x-www-form-urlencoded"
|
||||
"Authorization" (str "Basic " (get-basic-auth))}
|
||||
:form-params {"grant_type" "refresh_token"
|
||||
"refresh_token" refresh-token}
|
||||
:as :json}))]
|
||||
{:headers {"Accept" "application/json"
|
||||
"Content-Type" "application/x-www-form-urlencoded"
|
||||
"Authorization" (str "Basic " (get-basic-auth))}
|
||||
:form-params {"grant_type" "refresh_token"
|
||||
"refresh_token" refresh-token}
|
||||
:as :json}))]
|
||||
(set-access-token (:access_token response))
|
||||
(set-refresh-token (:refresh_token response))
|
||||
(:access_token response)))
|
||||
@@ -94,21 +88,20 @@
|
||||
(defn with-auth [t token]
|
||||
(assoc t "Authorization" (str "Bearer " token)))
|
||||
|
||||
#_(client/get (str base-url "/company/4620816365202617680")
|
||||
{:headers base-headers
|
||||
:as :json})
|
||||
#_(client/get (str base-url "/company/4620816365202617680")
|
||||
{:headers base-headers
|
||||
:as :json})
|
||||
|
||||
(defn get-bank-accounts-raw [token]
|
||||
(->> (:body (client/get (str prod-base-url "/company/" prod-company-id "/query" )
|
||||
(->> (:body (client/get (str prod-base-url "/company/" prod-company-id "/query")
|
||||
{:headers
|
||||
(with-auth prod-base-headers token)
|
||||
:as :json
|
||||
:query-params {"query" "SELECT * From Account maxresults 1000"}}))
|
||||
:QueryResponse))
|
||||
|
||||
|
||||
(defn get-bank-accounts [token]
|
||||
(->> (:body (client/get (str prod-base-url "/company/" prod-company-id "/query" )
|
||||
(->> (:body (client/get (str prod-base-url "/company/" prod-company-id "/query")
|
||||
{:headers
|
||||
(with-auth prod-base-headers token)
|
||||
:as :json
|
||||
@@ -116,7 +109,7 @@
|
||||
:QueryResponse
|
||||
:Account
|
||||
#_(filter
|
||||
#(#{"Bank" "Credit Card"} (:AccountType %)))
|
||||
#(#{"Bank" "Credit Card"} (:AccountType %)))
|
||||
(map (juxt :Id :Name :CurrentBalance :MetaData))
|
||||
(map (fn [[id name current-balance metadata]]
|
||||
{:id id
|
||||
@@ -124,10 +117,9 @@
|
||||
:last-updated (c/to-date-time (-> metadata :LastUpdatedTime))
|
||||
:current-balance (try (double current-balance) (catch Exception _ nil))}))))
|
||||
|
||||
|
||||
(defn get-all-transactions [start end]
|
||||
(let [token (get-fresh-access-token)]
|
||||
(:body (client/get (str prod-base-url "/company/" prod-company-id "/reports/TransactionList" "?minorversion=63&start_date=" start "&end_date=" end)
|
||||
(:body (client/get (str prod-base-url "/company/" prod-company-id "/reports/TransactionList" "?minorversion=63&start_date=" start "&end_date=" end)
|
||||
{:headers (with-auth prod-base-headers token)
|
||||
:as :json}))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user