Allows users to self set up square

This commit is contained in:
2022-04-06 08:22:52 -07:00
parent 982a0f3bed
commit 3a49ba971c
9 changed files with 303 additions and 239 deletions

View File

@@ -4,6 +4,7 @@
[auto-ap.graphql.utils :refer [->graphql assert-admin can-see-client? is-admin?]]
[auto-ap.utils :refer [by]]
[auto-ap.yodlee.core :refer [in-memory-cache]]
[auto-ap.square.core :as square]
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
[clj-time.coerce :as coerce]
[config.core :refer [env]]
@@ -14,7 +15,8 @@
[clojure.java.io :as io]
[amazonica.aws.s3 :as s3]
[yang.scheduler :as scheduler]
[mount.core :as mount])
[mount.core :as mount]
[auto-ap.square.core :as square])
(:import [org.apache.commons.codec.binary Base64]
java.util.UUID))
@@ -54,7 +56,7 @@
(> cnt 1)))))
(throw (ex-info "Cannot reuse yodlee/plaid/intuit account" {:validation-error (str "Cannot reuse yodlee/plaid/intuit account")})))))
(defn edit-client [context {:keys [edit_client new_bank_accounts] :as args} value]
(defn edit-client [context {:keys [edit_client]} _]
(assert-admin (:id context))
(when-not (:id edit_client)
(assert-client-code-is-unique (:code edit_client)))
@@ -100,6 +102,13 @@
:client/week-a-debits (:week_a_debits edit_client)
:client/week-a-credits (:week_a_credits edit_client)
:client/week-b-debits (:week_b_debits edit_client)
:client/square-auth-token (:square_auth_token edit_client)
:client/square-locations (map
(fn [sl]
(remove-nils
{:db/id (:id sl)
:square-location/client-location (:client_location sl)}))
(:square_locations edit_client))
:client/week-b-credits (:week_b_credits edit_client)
:client/location-matches (->> (:location_matches edit_client)
(filter (fn [lm] (and (:location lm) (:match lm))))
@@ -153,7 +162,9 @@
_ (assert-no-shared-transaction-sources client-code transactions)
_ (log/info "upserting client" transactions)
result (audit-transact transactions (:id context))]
(-> result :tempids (get id) (or id) d-clients/get-by-id
(when (:square_auth_token edit_client)
(square/upsert-locations [(-> result :tempids (get id) (or id) d-clients/get-by-id)]))
(-> (-> result :tempids (get id) (or id) d-clients/get-by-id)
(update :client/location-matches
(fn [lms]
(mapcat (fn [lm]
@@ -273,6 +284,12 @@
:match {:type 'String}
:id {:type :id}}}
:square_location
{:fields {:client_location {:type 'String}
:name {:type 'String}
:square_id {:type 'String}
:id {:type :id}}}
:email_contact {:fields {:id {:type :id}
:email {:type 'String}
:description {:type 'String}}}
@@ -282,6 +299,7 @@
:name {:type 'String}
:locked_until {:type :iso_date}
:code {:type 'String}
:square_auth_token {:type 'String}
:signature_file {:type 'String}
:week_a_debits {:type :money}
:week_a_credits {:type :money}
@@ -294,6 +312,7 @@
:locations {:type '(list String)}
:matches {:type '(list String)}
:bank_accounts {:type '(list :bank_account)}
:square_locations {:type '(list :square_location)}
:forecasted_transactions {:type '(list :forecasted_transaction)}
:yodlee_provider_accounts {:type '(list :yodlee_provider_account)}
:plaid_items {:type '(list :plaid_item)}}}
@@ -342,6 +361,9 @@
:match {:type 'String}
:id {:type :id}}}
:edit_square_location {:fields {:client_location {:type 'String}
:id {:type :id}}}
:edit_forecasted_transaction {:fields {:identifier {:type 'String}
:id {:type :id}
:day_of_month {:type 'Int}
@@ -353,6 +375,7 @@
:name {:type 'String}
:locked_until {:type :iso_date}
:code {:type 'String}
:square_auth_token {:type 'String}
:signature_data {:type 'String}
:email {:type 'String}
:emails {:type '(list :edit_email_contact)}
@@ -364,6 +387,7 @@
:locations {:type '(list String)}
:matches {:type '(list String)}
:location_matches {:type '(list :edit_location_match)}
:square_locations {:type '(list :edit_square_location)}
:bank_accounts {:type '(list :edit_bank_account)}
:forecasted_transactions {:type '(list :edit_forecasted_transaction)}}}