Vendor sub not needed.

This commit is contained in:
2022-04-11 07:52:38 -07:00
parent b4d5b7fde6
commit 919f8a773d
3 changed files with 178 additions and 176 deletions

View File

@@ -1,16 +1,14 @@
(ns auto-ap.events
(:require [re-frame.core :as re-frame]
[auto-ap.db :as db]
[auto-ap.subs :as subs]
[auto-ap.routes :as routes]
[auto-ap.effects :as effects]
[auto-ap.utils :refer [by]]
[venia.core :as v]
[bidi.bidi :as bidi]
[cemerick.url :refer [url]]
[goog.crypt.base64 :as b64]
[clojure.string :as str]))
(:require
[auto-ap.db :as db]
[auto-ap.routes :as routes]
[auto-ap.subs :as subs]
[auto-ap.utils :refer [by]]
[auto-ap.views.utils :refer [with-user]]
[bidi.bidi :as bidi]
[clojure.string :as str]
[goog.crypt.base64 :as b64]
[re-frame.core :as re-frame]))
(defn jwt->data [token]
(js->clj (.parse js/JSON (b64/decodeString (second (str/split token #"\." ))))))
@@ -275,3 +273,34 @@
:query-obj {:venia/queries [[:yodlee-merchants
[:name :yodlee-id :id]]]}
:on-success [::yodlee-merchants-received]}}))
(re-frame/reg-event-fx
::vendor-preferences-requested
[with-user]
(fn [{:keys [user]} [_ {:keys [ client-id vendor-id on-success on-failure owns-state]}]]
{:graphql {:token user
:query-obj {:venia/queries [[:vendor-by-id
{:id vendor-id}
[[:automatically-paid-when-due [:id]]
[:schedule-payment-dom [[:client [:id]] :dom]]
[:default-account [:id]]]]
[:account-for-vendor
{:vendor-id vendor-id
:client-id client-id}
[:name :id :numeric-code :location]]]}
:owns-state owns-state
:on-success (fn [r]
(let [schedule-payment-dom (->> r
:vendor-by-id
:schedule-payment-dom
(filter (fn [spd]
(= (-> spd :client :id)
client-id)))
first
:dom)
automatically-paid-when-due (boolean ((->> r :vendor-by-id :automatically-paid-when-due (map :id) set) client-id))]
(conj on-success {:default-account (:account-for-vendor r)
:schedule-payment-dom schedule-payment-dom
:automatically-paid-when-due automatically-paid-when-due
:vendor-autopay? (or automatically-paid-when-due (boolean schedule-payment-dom))})))
:on-failure on-failure}}))