|
145 | 145 | (payment/update-payments-for-person-term-and-year person-service tarjonta-service
|
146 | 146 | koodisto-cache get-haut-cache
|
147 | 147 | 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.") |
152 |
| - (doseq [payment modified-payments] |
153 |
| - (let [new-state (:state payment)] |
154 |
| - (cond |
155 |
| - (= (:awaiting payment/all-states) new-state) |
156 |
| - (create-payment-and-send-email job-runner maksut-service payment)))) |
157 |
| - |
158 |
| - (doseq [application-payment existing-payments] |
159 |
| - (let [{:keys [application payment]} application-payment] |
160 |
| - (cond |
161 |
| - (needs-reminder-sent? payment) |
162 |
| - (send-reminder-email-and-mark-sent job-runner payment application)))) |
163 |
| - |
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.")) |
| 148 | + (if (or (some? modified-payments) (some? existing-payments)) |
| 149 | + (do |
| 150 | + (log/info "Update kk application payment status handler for" |
| 151 | + person-oid application-term application-year |
| 152 | + "returned" (count existing-payments) "created or modified payments and" |
| 153 | + (count modified-payments) "existing payments before creating / modifying.") |
| 154 | + (doseq [payment modified-payments] |
| 155 | + (let [new-state (:state payment)] |
| 156 | + (cond |
| 157 | + (= (:awaiting payment/all-states) new-state) |
| 158 | + (create-payment-and-send-email job-runner maksut-service payment)))) |
| 159 | + |
| 160 | + (doseq [application-payment existing-payments] |
| 161 | + (let [{:keys [application payment]} application-payment] |
| 162 | + (cond |
| 163 | + (needs-reminder-sent? payment) |
| 164 | + (send-reminder-email-and-mark-sent job-runner payment application)))) |
| 165 | + |
| 166 | + (invalidate-maksut-payments-if-needed maksut-service modified-payments) |
| 167 | + (log/info "Update kk payment status handler for" person-oid application-term application-year "finished.")) |
| 168 | + |
| 169 | + ; Here we've already established there should be a person with at least one application, but for the first |
| 170 | + ; applications in haku, get-haku-cache may still be refreshing so it doesn't return any applications for |
| 171 | + ; the specific haku. That's a temporary error, and quite short-lived, so let's try again later. |
| 172 | + (throw (ex-info "Could not find or create a payment status for person" {:person-oid person-oid |
| 173 | + :term application-term |
| 174 | + :year application-year})))) |
166 | 175 | (log/warn "Update kk payment status handler not run for params"
|
167 | 176 | person_oid term year application_id application_key
|
168 | 177 | "because no valid payment info was found.")))))
|
|
0 commit comments