Skip to content

Commit a3111a3

Browse files
authored
Merge pull request #1670 from Opetushallitus/OK-745-kk-payment-translations-and-fixes
OK-745 kk payment translations and fixes
2 parents 79000ec + c07365e commit a3111a3

17 files changed

+112
-62
lines changed

resources/less/virkailija-application.less

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,8 @@ i.arkistoitu {
10061006
.application-handling__review-header--eligibility-state,
10071007
.application-handling__review-header--payment-obligation {
10081008
.light;
1009+
max-width: 145px;
1010+
word-wrap: break-word;
10091011
}
10101012

10111013
.application-handling__review-header--points {

spec/ataru/virkailija/virkailija_routes_spec.clj

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@
751751
(after-all
752752
(db/nuke-kk-payment-data))
753753

754-
(it "should return payment information and history for an application"
754+
(it "should return payment information for an application"
755755
(let [application-id (db/init-db-fixture fixtures/payment-exemption-test-form
756756
application-fixtures/application-without-hakemusmaksu-exemption
757757
nil)
@@ -763,14 +763,12 @@
763763
status (:status resp)
764764
body (:body resp)
765765
payment-data (:kk-payment body)
766-
state (get-in payment-data [:payment :state])
767-
history (sort-by :modified-at (:history payment-data))]
766+
form-payment (get-in body [:form :properties :payment])
767+
state (get-in payment-data [:payment :state])]
768768
(should= 200 status)
769769
(should-not-be-nil payment-data)
770-
(should= (:paid payment/all-states) state)
771-
(should= 2 (count history))
772-
(should= [(:not-required payment/all-states) (:awaiting payment/all-states)]
773-
(map :state history)))))
770+
(should= {:type "payment-type-kk", :processing-fee "100.00", :decision-fee nil} form-payment)
771+
(should= (:paid payment/all-states) state))))
774772

775773
(defn- init-and-get-kk-fixtures []
776774
(let [person-oid "1.2.3.4.5.303"

src/clj/ataru/applications/application_service.clj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
[ataru.applications.excel-export :as excel]
77
[ataru.config.core :refer [config]]
88
[ataru.email.application-email-jobs :as email]
9+
[ataru.forms.form-payment-info :as payment-info]
910
[ataru.forms.form-store :as form-store]
1011
[ataru.hakija.hakija-form-service :as hakija-form-service]
1112
[ataru.information-request.information-request-store :as information-request-store]
@@ -78,9 +79,10 @@
7879
(application-store/get-application-attachment-reviews application-key)))
7980

8081
(defn- populate-form-fields
81-
[form koodisto-cache tarjonta-info]
82+
[form koodisto-cache tarjonta-info tarjonta-service]
8283
(-> (koodisto/populate-form-koodisto-fields koodisto-cache form)
8384
(populate-hakukohde-answer-options tarjonta-info)
85+
(payment-info/populate-form-with-payment-info tarjonta-service (:tarjonta tarjonta-info))
8486
(hakija-form-service/populate-can-submit-multiple-applications tarjonta-info)))
8587

8688
(defn fields-equal? [[new-in-left new-in-right]]
@@ -492,18 +494,20 @@
492494
newest-form (form-store/fetch-by-key (:key form-in-application))
493495
form (populate-form-fields (if with-newest-form?
494496
newest-form
495-
form-in-application) koodisto-cache tarjonta-info)
497+
form-in-application)
498+
koodisto-cache tarjonta-info tarjonta-service)
496499
forms-differ? (and (not with-newest-form?)
497500
(forms-differ? application tarjonta-info form
498-
(populate-form-fields newest-form koodisto-cache tarjonta-info)))
501+
(populate-form-fields newest-form
502+
koodisto-cache tarjonta-info tarjonta-service)))
499503
alternative-form (some-> (when forms-differ?
500504
newest-form)
501505
(assoc :content [])
502506
(dissoc :organization-oid))
503507
hakukohde-reviews (future (parse-application-hakukohde-reviews application-key))
504508
attachment-reviews (future (parse-application-attachment-reviews application-key))
505509
events (future (get-application-events organization-service application-key))
506-
kk-payment-state (future (kk-application-payment/get-kk-payment-state application true))
510+
kk-payment-state (future (kk-application-payment/get-kk-payment-state application false))
507511
review (future (application-store/get-application-review application-key))
508512
review-notes (future (map (partial enrich-virkailija-organizations organization-service)
509513
(application-store/get-application-review-notes application-key)))

src/clj/ataru/hakija/hakija_application_service.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@
717717
(application-store/application-exists-with-secret? secret))
718718
application-in-processing? (util/application-in-processing? (:application-hakukohde-reviews application))
719719
inactivated? (is-inactivated? application)
720-
kk-payment (future (kk-application-payment/get-kk-payment-state application true))
720+
kk-payment (future (kk-application-payment/get-kk-payment-state application false))
721721
lang-override (when (or secret-expired? inactivated?) (application-store/get-application-language-by-secret secret))
722722
field-deadlines (or (some->> application
723723
:key

src/clj/ataru/kk_application_payment/kk_application_payment.clj

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -305,20 +305,27 @@
305305
(defn- set-payment
306306
[new-state state-change-fn {:keys [application payment]}]
307307
(let [current-state (:state payment)
308-
application-key (:key application)]
308+
application-key (:key application)
309+
person-oid (:person-oid application)]
309310
(cond
310311
(= current-state new-state)
311-
(log/info "Application" application-key "already has kk payment status" current-state ", not changing state")
312+
(log/info "Application" application-key "with person-oid" person-oid "already has kk payment status" current-state
313+
", not changing kk application payment state")
312314

313315
(= current-state (:paid all-states))
314-
(log/info "Application" application-key "already has kk payment paid, not changing state")
316+
(log/info "Application" application-key "with person-oid" person-oid
317+
"already has payment paid, not changing kk application payment state")
315318

316319
; N.B. even if you pay an another application, if a previous application is overdue, the state must not change.
317320
(= current-state (:overdue all-states))
318-
(log/info "Application" application-key "is already overdue, not changing state")
321+
(log/info "Application" application-key "with person-oid" person-oid
322+
"is already overdue, not changing kk application payment state")
319323

320324
:else
321-
(state-change-fn (:key application) payment))))
325+
(do
326+
(log/info "Changing kk application payment state for application" application-key
327+
"with person-oid" person-oid "to" new-state)
328+
(state-change-fn (:key application) payment)))))
322329

323330
(defn- update-payments-for-applications
324331
[applications-payments is-finnish-citizen? has-exemption? has-existing-payment?]
@@ -347,22 +354,31 @@
347354
(application-store/get-latest-applications-for-kk-payment-processing aliases valid-haku-oids))]
348355
(when (get-in config [:kk-application-payments :enabled?])
349356
(if (= 0 (count applications))
350-
[]
351-
(let [payment-by-application (into {}
352-
(map (fn [payment] [(:application-key payment) payment]))
353-
(get-raw-payments (map :key applications)))
354-
applications-payments (map (fn [application]
355-
{:application application
356-
:payment (get payment-by-application (:key application))})
357-
applications)
358-
payment-state-set (->> (vals payment-by-application) (map :state) set)
359-
is-finnish-citizen? (is-finnish-citizen? person)
360-
has-exemption? (some true? (map exemption-in-application? applications))
361-
has-existing-payment? (contains? payment-state-set (:paid all-states))]
362-
{:person person
363-
:existing-payments applications-payments
364-
:modified-payments (update-payments-for-applications
365-
applications-payments is-finnish-citizen? has-exemption? has-existing-payment?)})))))
357+
(do
358+
(log/info "Not updating kk payment status for person" person-oid "term" term "year" year
359+
"with all person aliases" aliases "because no matching applications were found.")
360+
{})
361+
(do
362+
(log/info "Updating kk payment status for person" person-oid "term" term "year" year
363+
"with all person aliases" aliases "and application keys" (map :key applications))
364+
(let [payment-by-application (into {}
365+
(map (fn [payment] [(:application-key payment) payment]))
366+
(get-raw-payments (map :key applications)))
367+
applications-payments (map (fn [application]
368+
{:application application
369+
:payment (get payment-by-application (:key application))})
370+
applications)
371+
payment-state-set (->> (vals payment-by-application) (map :state) set)
372+
is-finnish-citizen? (is-finnish-citizen? person)
373+
has-exemption? (some true? (map exemption-in-application? applications))
374+
has-existing-payment? (contains? payment-state-set (:paid all-states))]
375+
(log/info "Updating application level kk application payment status for person" person-oid "term" term "year" year
376+
"is-finnish-citizen?" (boolean is-finnish-citizen?) "has-exemption?" (boolean has-exemption?)
377+
"has-existing-payment?" (boolean has-existing-payment?))
378+
{:person person
379+
:existing-payments applications-payments
380+
:modified-payments (update-payments-for-applications
381+
applications-payments is-finnish-citizen? has-exemption? has-existing-payment?)}))))))
366382

367383
(defn get-kk-payment-state
368384
"Returns higher education application fee related info to single application.

src/clj/ataru/kk_application_payment/kk_application_payment_maksut_poller_job.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
payments))
2121
; TODO: the amount of open payments may be quite large at a given moment, should we partition the API queries here?
2222
maksut (maksut-protocol/list-lasku-statuses maksut-service (keys keys-states))]
23-
(log/debug "Received statuses for" (count maksut) "kk payment invoices")
23+
(log/info "Received statuses for" (count maksut) "kk payment invoices")
2424
(let [terminal (filter #(some #{(:status %)} '(:paid :overdue)) maksut)
2525
raw (map (fn [{:keys [reference status origin]}]
2626
(when-let [key-match (get keys-states reference)]
@@ -30,7 +30,7 @@
3030
:origin origin}))
3131
terminal)
3232
items (filter some? raw)]
33-
(log/debug "Out of which in terminal-state are" (count terminal) "invoices")
33+
(log/info "Out of which in terminal-state are" (count terminal) "invoices")
3434
(log/debug (pr-str "Invoices" items))
3535
(doseq [item items]
3636
(let [{:keys [origin ataru-status maksut-status ataru-data]} item
@@ -61,9 +61,9 @@
6161
; TODO: we should probably also handle awaiting payments without maksut information (in case something has gone wrong)
6262
(if-let [payments (seq (store/get-awaiting-kk-application-payments))]
6363
(do
64-
(log/debug "Found " (count payments) " open kk application payments, checking maksut status")
64+
(log/info "Found " (count payments) " open kk application payments, checking maksut status")
6565
(poll-payments job-runner maksut-service payments))
66-
(log/debug "No kk application payments in need of maksut polling found"))
66+
(log/info "No kk application payments in need of maksut polling found"))
6767
(catch Exception e
6868
(log/error e "Maksut polling failed")))))
6969

src/clj/ataru/kk_application_payment/kk_application_payment_status_updater_job.clj

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
(defn- send-reminder-email-and-mark-sent
9898
[job-runner payment-data application]
9999
(let [application-key (:application-key payment-data)]
100+
(log/info "Scheduling kk application payment reminder e-mail for application" application-key)
100101
(start-payment-email-job job-runner application (:maksut-secret payment-data) payment-reminder-email-params "reminder")
101102
(payment/mark-reminder-sent application-key)))
102103

@@ -144,7 +145,10 @@
144145
(payment/update-payments-for-person-term-and-year person-service tarjonta-service
145146
koodisto-cache get-haut-cache
146147
person-oid application-term application-year)]
147-
(log/info "Update kk payment status hander for" person-oid application-term application-year)
148+
(log/info "Update kk application payment status handler for"
149+
person-oid application-term application-year
150+
"returned" (count existing-payments) "created or modified payments and"
151+
(count modified-payments) "existing payments before creating / modifying.")
148152
(doseq [payment modified-payments]
149153
(let [new-state (:state payment)]
150154
(cond
@@ -157,8 +161,11 @@
157161
(needs-reminder-sent? payment)
158162
(send-reminder-email-and-mark-sent job-runner payment application))))
159163

160-
(invalidate-maksut-payments-if-needed maksut-service modified-payments))
161-
(log/debug "Application id" application_id "not in haku with kk application payments")))))
164+
(invalidate-maksut-payments-if-needed maksut-service modified-payments)
165+
(log/info "Update kk payment status handler for" person-oid application-term application-year "finished."))
166+
(log/warn "Update kk payment status handler not run for params"
167+
person_oid term year application_id application_key
168+
"because no valid payment info was found.")))))
162169

163170
(defn start-update-kk-payment-status-for-person-job
164171
[job-runner person-oid term year]
@@ -204,8 +211,8 @@
204211
(let [haku-oid (:oid haku)
205212
term (:alkamiskausi haku)
206213
year (:alkamisvuosi haku)
207-
person-oids (application-store/get-application-person-oids-for-haku haku-oid)]
208-
(log/info "Found" (count person-oids) "oids for haku" haku-oid "- updating kk application payment statuses.")
214+
person-oids (distinct (application-store/get-application-person-oids-for-haku haku-oid))]
215+
(log/info "Found" (count person-oids) "distinct oids for haku" haku-oid "- updating kk application payment statuses.")
209216
(doseq [person-oid person-oids]
210217
(start-update-kk-payment-status-for-person-job job-runner person-oid term year))))
211218

src/cljc/ataru/application/review_states.cljc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@
164164
["awaiting" (:awaiting state-translations)]
165165
["ok-by-proxy" (:ok-by-proxy state-translations)]
166166
["paid" (:paid state-translations)]
167-
["overdue" (:overdue state-translations)]
168-
["not-checked" (:not-checked state-translations)]])
167+
["overdue" (:kk-payment-overdue state-translations)]
168+
["not-checked" (:kk-payment-not-checked state-translations)]])
169169

170170
(def hakukohde-review-types
171171
[[:processing-state (:processing-state state-translations) application-hakukohde-processing-states]

src/cljc/ataru/schema/form_schema.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@
523523

524524
(s/defschema KkPaymentState
525525
{(s/optional-key :payment) PaymentStatus
526-
(s/optional-key :history) [PaymentStatus]})
526+
(s/optional-key :history) (s/maybe [PaymentStatus])})
527527

528528
(s/defschema ApplicationWithPerson
529529
(-> Application

0 commit comments

Comments
 (0)