Skip to content

Commit

Permalink
Merge pull request #1648 from Opetushallitus/OK-762-payment-data-ui
Browse files Browse the repository at this point in the history
Show kk-application-payment data
  • Loading branch information
SalamaGofore authored Dec 2, 2024
2 parents cd9d949 + 0c64db8 commit aed6938
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@
(jdbc/delete! conn :kk_application_payments [])
(jdbc/delete! conn :kk_application_payments_history [])))

(defn- check-mail-fn [mail-content]
(and
(= (count (:recipients mail-content)) 1)
(= "[email protected]" (first (:recipients mail-content)))
(not-empty (:subject mail-content))
(str/includes? (:body mail-content) "Voit maksaa hakemusmaksun allaolevan linkin kautta.")
(str/includes? (:body mail-content) test-maksut-secret)))

(describe "kk-application-payment-status-updater-job"
(tags :unit)
(with-stubs)
Expand Down Expand Up @@ -224,19 +232,12 @@
:maksut-secret reminder-maksut-secret}
(select-keys payment [:application-key :state :maksut-secret])))))

(it "should create a payment e-mail and a sending job"
(it "should create a payment and e-mail sending job"
(with-redefs [start-runner-job (stub :start-job)]
(let [application-id (unit-test-db/init-db-fixture
form-fixtures/payment-exemption-test-form
application-fixtures/application-without-hakemusmaksu-exemption
nil)
check-mail-fn (fn [mail-content]
(and
(= (count (:recipients mail-content)) 1)
(= "[email protected]" (first (:recipients mail-content)))
(not-empty (:subject mail-content))
(str/includes? (:body mail-content) "Voit maksaa hakemusmaksun allaolevan linkin kautta.")
(str/includes? (:body mail-content) test-maksut-secret)))
_ (updater-job/update-kk-payment-status-for-person-handler
{:person_oid test-person-oid :term test-term :year test-year} runner)
application-key (:key (application-store/get-application application-id))
Expand All @@ -248,4 +249,29 @@
(should=
{:application-key application-key :state (:awaiting payment/all-states)
:maksut-secret test-maksut-secret}
(select-keys payment [:application-key :state :maksut-secret]))))))
(select-keys payment [:application-key :state :maksut-secret])))))

(it "creates payment email sending job"
(with-redefs [start-runner-job (stub :start-job)]
(let [application-id (unit-test-db/init-db-fixture
form-fixtures/payment-exemption-test-form
application-fixtures/application-without-hakemusmaksu-exemption
nil)
application-key (:key (application-store/get-application application-id))
_ (payment-store/create-or-update-kk-application-payment!
{:application-key application-key
:state (:awaiting payment/all-states)
:reason nil
:due-date (time-format/unparse payment/default-time-format
(time/plus (time/today-at 12 0 0)
(time/days 3)))
:total-sum payment/kk-application-payment-amount
:maksut-secret test-maksut-secret
:required-at "now()"
:notification-sent-at nil
:approved-at nil})
_ (updater-job/resend-payment-email runner application-key)]
(should-have-invoked :start-job
{:with [:* :*
"ataru.kk-application-payment.kk-application-payment-email-job"
check-mail-fn]})))))
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@
{:subject-key :email-kk-payment-link-subject
:template-path (str "templates/email_kk_payment_link_" (name lang) ".html")})

(defn- start-payment-email-job [job-runner application email-address lang payment-url params-fn type-str]
(defn- start-payment-email-job [job-runner application secret params-fn type-str]
(let [application-key (:key application)
job-type (:type email-job/job-definition)
lang (utils/get-application-language application)
email-address (utils/get-application-email application)
payment-url (url-helper/resolve-url :maksut-service.hakija-get-by-secret secret (name lang))
mail-content (utils/payment-email lang email-address {:payment-url payment-url} (params-fn lang))]
(log/info "Generate kk application payment " type-str " for email" email-address
"URL" payment-url "application-key" application-key)
(if mail-content
(let [job-id (jdbc/with-db-transaction [conn {:datasource (db/get-datasource :db)}]
(job/start-job job-runner conn job-type mail-content))]
Expand All @@ -42,29 +47,23 @@
[{:keys [tarjonta-service] :as job-runner} maksut-service payment-data]
(let [application-key (:application-key payment-data)
application (application-store/get-latest-application-by-key application-key)
lang (utils/get-application-language application)
email-address (utils/get-application-email application)
invoice-data (payment/generate-invoicing-data tarjonta-service payment-data application)
invoice (maksut-protocol/create-kk-application-payment-lasku maksut-service invoice-data)
url (url-helper/resolve-url :maksut-service.hakija-get-by-secret (:secret invoice) (name lang))]
invoice (maksut-protocol/create-kk-application-payment-lasku maksut-service invoice-data)]
(when invoice
(log/info "Kk application payment invoice details" invoice)
(log/info "Store kk application payment maksut secret for reference " (:reference invoice))
(payment/set-maksut-secret application-key (:secret invoice))
(log/info "Generate kk application payment maksut-link for email" email-address
"URL" url "application-key" application-key)
(start-payment-email-job job-runner application email-address lang url payment-link-email-params "maksut-link"))))
(start-payment-email-job job-runner application (:secret invoice) payment-link-email-params "maksut-link"))))

(defn resend-payment-email [job-runner application-key]
(let [application (application-store/get-latest-application-by-key application-key)
payment (first (payment/get-raw-payments [application-key]))]
(start-payment-email-job job-runner application (:maksut-secret payment) payment-link-email-params "maksut-link")))

(defn- send-reminder-email-and-mark-sent
[job-runner payment-data application]
(let [application-key (:application-key payment-data)
lang (utils/get-application-language application)
email-address (utils/get-application-email application)
url (url-helper/resolve-url :maksut-service.hakija-get-by-secret
(:maksut-secret payment-data) (name lang))]
(log/info "Generate kk application payment reminder for email" email-address
"URL" url "application key" application-key)
(start-payment-email-job job-runner application email-address lang url payment-reminder-email-params "reminder")
(let [application-key (:application-key payment-data)]
(start-payment-email-job job-runner application (:maksut-secret payment-data) payment-reminder-email-params "reminder")
(payment/mark-reminder-sent application-key)))

(defn needs-reminder-sent?
Expand Down
7 changes: 7 additions & 0 deletions src/clj/ataru/virkailija/virkailija_routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,13 @@
(response/not-found
{:error (str "Hakemukseen " application-key " liittyviä laskuja ei löydy")}))))

(api/POST "/hakemusmaksu/email/laheta/:hakemus-oid" {session :session}
:path-params [hakemus-oid :- s/Str]
:summary "Lähettää hakemusmaksu sähköpostin"
(if (access-controlled-application/applications-access-authorized? organization-service tarjonta-service session [hakemus-oid] [:edit-applications])
(kk-application-payment-status-updater-job/resend-payment-email job-runner hakemus-oid)
(response/unauthorized)))

(api/POST "/maksupyynto" {session :session}
:body [input maksut-schema/LaskuCreate]
:summary "Välittää maksunluonti-pyynnön Maksut -palvelulle"
Expand Down
5 changes: 4 additions & 1 deletion src/cljc/ataru/translations/texts.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2579,7 +2579,10 @@
:en "EN: Hakija on eidas-tunnistautunut."}
:valittu {:fi "valittu"
:sv "valda"
:en "selected"}})
:en "selected"}
:payment-not-obligated {:fi "Hakija ei ole maksuvelvollinen"
:sv "SV: Hakija ei ole maksuvelvollinen"
:en "EN: Hakija ei ole maksuvelvollinen"}})

(def state-translations
{:active {:fi "Aktiivinen"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
[reagent.core :as r]
[reagent.ratom :refer-macros [reaction]]
[re-frame.core :refer [subscribe dispatch]]
[ataru.virkailija.application.payment.payment-view :refer [application-tutu-payment-status application-astu-payment-status]]))
[ataru.virkailija.application.payment.payment-view :refer [application-tutu-payment-status application-astu-payment-status kk-application-payment-status]]))

(defn- application-contents [{:keys [form application]} hakukohteet]
[readonly-contents/readonly-fields form application hakukohteet])
Expand Down Expand Up @@ -1102,7 +1102,8 @@
@(subscribe [:editor/virkailija-translation :selected-hakukohde-no-rights])]]))
(cond
tutu-form? [application-tutu-payment-status payments]
astu-form? [application-astu-payment-status payments])
astu-form? [application-astu-payment-status payments]
kk-application-payment-required? [kk-application-payment-status payments])
(when @(subscribe [:application/show-info-request-ui?])
[application-information-request])
[application-review-inputs]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@
(assoc :index 2))}))
{}))

(re-frame/reg-event-fx
:payment/resend-application-payment-email
(fn [_ [_ application-key]]
(ajax/http :post
(str "/lomake-editori/api/maksut/hakemusmaksu/email/laheta/" application-key)
:payment/handle-processing-invoice
:id :resend-application-payment-email
:handler-args {:application-key key})))

(re-frame/reg-fx
:payment/fetch-payments
(fn [{:keys [application-key]}]
Expand Down
127 changes: 95 additions & 32 deletions src/cljs/ataru/virkailija/application/payment/payment_view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
(format/parse-local date-formatter date-str)
(catch js/Error _))))

(defn- format-date [iso-date-str]
(when-let [date (iso-date-str->date iso-date-str)]
(format/unparse fi-formatter date)))
(defn- format-date
([iso-date-str]
(when-let [date (iso-date-str->date iso-date-str)]
(format/unparse fi-formatter date))))

(defn- date-picker [application-key]
(let [value (subscribe [:payment/duedate-input application-key])
Expand Down Expand Up @@ -63,34 +64,35 @@
[:span (str "")]
]))

(defn- single-payment-status-row [header payment]
(let [status (keyword (:status payment))
icon (case (keyword status)
:active icons/tutu-payment-outstanding
:paid icons/tutu-payment-paid
:overdue icons/tutu-payment-overdue
nil)
label (if (or (empty? payment) (nil? status))
@(subscribe [:editor/virkailija-translation :maksupyynto-invoice-notfound])
(case (keyword status)
:active @(subscribe [:editor/virkailija-translation :maksupyynto-payment-active])
:paid (str @(subscribe [:editor/virkailija-translation :maksupyynto-payment-paid]) " " (format-date (:paid_at payment)))
:overdue (str @(subscribe [:editor/virkailija-translation :maksupyynto-payment-overdue]) " " (format-date (:due_date payment)))
@(subscribe [:editor/virkailija-translation :maksupyynto-payment-unknown])))]
[:<>
[:div header]
[:div
(when icon [icon])
(str label)
(when (= :paid (keyword (:status payment)))
[:a
{:href (str "/lomake-editori/api/maksut/kuitti/" (:order_id payment))
:download (str (:order_id payment) ".html")
:title @(subscribe [:editor/virkailija-translation :maksupyynto-payment-download-receipt])}
[:i.application-handling__tutu-receipt-icon.zmdi.zmdi-download.zmdi-hc-lg]])
]
]
))
(defn- single-payment-status-row
([header payment] (single-payment-status-row header payment (keyword (:status payment))))
([header payment status]
(let [icon (case (keyword status)
:active icons/tutu-payment-outstanding
:paid icons/tutu-payment-paid
:overdue icons/tutu-payment-overdue
nil)
label (if (or (empty? payment) (nil? status))
@(subscribe [:editor/virkailija-translation :maksupyynto-invoice-notfound])
(case (keyword status)
:active @(subscribe [:editor/virkailija-translation :maksupyynto-payment-active])
:paid (str @(subscribe [:editor/virkailija-translation :maksupyynto-payment-paid]) " " (format-date (:paid_at payment)))
:overdue (str @(subscribe [:editor/virkailija-translation :maksupyynto-payment-overdue]) " " (format-date (:due_date payment)))
@(subscribe [:editor/virkailija-translation :maksupyynto-payment-unknown])))]
[:<>
[:div header]
[:div
(when icon [icon])
(str label)
(when (= :paid (keyword (:status payment)))
[:a
{:href (str "/lomake-editori/api/maksut/kuitti/" (:order_id payment))
:download (str (:order_id payment) ".html")
:title @(subscribe [:editor/virkailija-translation :maksupyynto-payment-download-receipt])}
[:i.application-handling__tutu-receipt-icon.zmdi.zmdi-download.zmdi-hc-lg]])
]
]
)))

(defn- resend-processing-invoice-button []
(let [loading? (subscribe [:state-query [:request-handles :resend-processing-invoice]])
Expand Down Expand Up @@ -280,4 +282,65 @@
(#{:processing :decision-fee-outstanding} state) true)
[:<>
[send-decision-invoice-button application-key decision-pay-status]])])
]))
]))

(defn- resend-kk-application-payment-email []
(let [can-edit? (subscribe [:state-query [:application :selected-application-and-form :application :can-edit?]])
application-key @(subscribe [:state-query [:application :review :application-key]])]
[:button.application-handling__tutu-payment-send-button.application-handling__button
{:on-click #(dispatch [:payment/resend-application-payment-email application-key])
:disabled (not @can-edit?)
:class (if @can-edit?
"application-handling__send-information-request-button--enabled application-handling__send-information-request-button--cursor-pointer"
"application-handling__send-information-request-button--disabled application-handling__send-information-request-button--cursor-default")
}
[:div @(subscribe [:editor/virkailija-translation :maksupyynto-again-button])]]))

(defn- kk-application-payment-data [kk-payment-state payments]
(let [kk-payment @(subscribe [:payment/kk-payment])
email @(subscribe [:state-query [:application :selected-application-and-form :application :answers :email :value]])
amount-label (case kk-payment-state
:awaiting @(subscribe [:editor/virkailija-translation :maksupyynto-amount-label])
:overdue @(subscribe [:editor/virkailija-translation :maksupyynto-amount-label])
:paid @(subscribe [:editor/virkailija-translation :maksupyynto-total-paid-label])
nil)
amount-value (:total-sum kk-payment)
state-for-status-row (case kk-payment-state
:awaiting :active
:paid :paid
:overdue :overdue
nil)
due-label (when (= :awaiting kk-payment-state)
@(subscribe [:editor/virkailija-translation :maksupyynto-due-label]))
due-value (format/unparse fi-formatter (:due-date kk-payment))]
[:<>
[single-payment-status-row @(subscribe [:editor/virkailija-translation :maksupyynto-processing-header])
(:processing payments) state-for-status-row]

[:div @(subscribe [:editor/virkailija-translation :maksupyynto-recipient])]
[:div email]

(when (and amount-label amount-value)
[:<>
[:div (str amount-label ":")]
[:div (str amount-value "")]])

(when (and due-label due-value)
[:<>
[:div (str due-label ":")]
[:div (str due-value)]])

(when (= :awaiting kk-payment-state)
[resend-kk-application-payment-email])]))

(defn kk-application-payment-status [payments]
(let [payment-state (keyword @(subscribe [:payment/kk-payment-state]))
not-required? (or (= payment-state :not-checked) (= payment-state :not-required))]
[:div.application-handling__tutu-payment-maksupyynto-box
[:span.application-handling__tutu-payment--span-2
[:b @(subscribe [:editor/virkailija-translation :maksupyynto-header])]]
(if not-required?
[:span.application-handling__tutu-payment--span-2
[icons/tutu-payment-outstanding]
@(subscribe [:editor/virkailija-translation :payment-not-obligated])]
[kk-application-payment-data payment-state payments])]))

0 comments on commit aed6938

Please sign in to comment.