plaid
This commit is contained in:
71
src/clj/auto_ap/plaid/core.clj
Normal file
71
src/clj/auto_ap/plaid/core.clj
Normal file
@@ -0,0 +1,71 @@
|
||||
(ns auto-ap.plaid.core
|
||||
(:require [auto-ap.datomic :refer [conn remove-nils]]
|
||||
[amazonica.aws.s3 :as s3]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[clj-http.client :as client]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as time]
|
||||
[clj-time.format :as f]
|
||||
[config.core :refer [env] :as cfg ]
|
||||
[clojure.string :as str]
|
||||
[clojure.data.json :as json]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.tools.logging :as log]
|
||||
[datomic.api :as d]
|
||||
[mount.core :as mount]
|
||||
[unilog.context :as lc]
|
||||
[yang.scheduler :as scheduler]
|
||||
[clojure.core.async :as async]
|
||||
[clojure.core.memoize :as m]))
|
||||
|
||||
(def base-url (-> env :plaid :base-url))
|
||||
|
||||
(def client-id (-> env :plaid :client-id))
|
||||
(def secret-key (-> env :plaid :secret-key))
|
||||
|
||||
|
||||
(defn get-link-token [client-code]
|
||||
(-> (client/post (str base-url "/link/token/create")
|
||||
{:as :json
|
||||
:headers {"Content-Type" "application/json"}
|
||||
:body (json/write-str {"client_id" client-id
|
||||
"secret" secret-key
|
||||
"client_name" "Integreat Consulting"
|
||||
"country_codes" ["US"]
|
||||
"language" "en"
|
||||
"user" {"client_user_id" client-code}
|
||||
"products" ["auth" "transactions"]})})
|
||||
:body
|
||||
:link_token))
|
||||
|
||||
(defn exchange-public-token [public-token client-code]
|
||||
(-> (client/post (str base-url "/item/public_token/exchange")
|
||||
{:as :json
|
||||
:headers {"Content-Type" "application/json"}
|
||||
:body (json/write-str {"client_id" client-id
|
||||
"secret" secret-key
|
||||
"public_token" public-token})})
|
||||
:body
|
||||
(doto println)))
|
||||
|
||||
(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-transactions [access-token account-id start end]
|
||||
(-> (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" (auto-ap.time/unparse start auto-ap.time/iso-date)
|
||||
"end_date" (auto-ap.time/unparse end auto-ap.time/iso-date)
|
||||
"options" {"account_ids" [account-id]}})})
|
||||
:body))
|
||||
|
||||
Reference in New Issue
Block a user