|
305 | 305 | (defn- set-payment
|
306 | 306 | [new-state state-change-fn {:keys [application payment]}]
|
307 | 307 | (let [current-state (:state payment)
|
308 |
| - application-key (:key application)] |
| 308 | + application-key (:key application) |
| 309 | + person-oid (:person-oid application)] |
309 | 310 | (cond
|
310 | 311 | (= 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") |
312 | 314 |
|
313 | 315 | (= 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") |
315 | 318 |
|
316 | 319 | ; N.B. even if you pay an another application, if a previous application is overdue, the state must not change.
|
317 | 320 | (= 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") |
319 | 323 |
|
320 | 324 | :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))))) |
322 | 329 |
|
323 | 330 | (defn- update-payments-for-applications
|
324 | 331 | [applications-payments is-finnish-citizen? has-exemption? has-existing-payment?]
|
|
347 | 354 | (application-store/get-latest-applications-for-kk-payment-processing aliases valid-haku-oids))]
|
348 | 355 | (when (get-in config [:kk-application-payments :enabled?])
|
349 | 356 | (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?)})))))) |
366 | 382 |
|
367 | 383 | (defn get-kk-payment-state
|
368 | 384 | "Returns higher education application fee related info to single application.
|
|
0 commit comments