Skip to content

Commit

Permalink
OK-555 separate merchant key support for hakemusmaksu
Browse files Browse the repository at this point in the history
  • Loading branch information
vaeinoe committed Sep 25, 2024
1 parent b04f736 commit f2f4a76
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 24 deletions.
9 changes: 6 additions & 3 deletions oph-configuration/config.dev.edn
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
:database-name "maksut"
:host "localhost"
:port 15499}
:payment {:paytrail-config {:host "https://services.paytrail.com/payments"
:merchant-id 375917
:merchant-secret "SAIPPUAKAUPPIAS"}
:payment {:paytrail-config {:default {:host "https://services.paytrail.com/payments"
:merchant-id 375917
:merchant-secret "SAIPPUAKAUPPIAS"}
:kkhakemusmaksu {:host "https://services.paytrail.com/payments"
:merchant-id 375917
:merchant-secret "SAIPPUAKAUPPIAS"}}
:callback-uri "https://maksut-local.test:9000/maksut/api/payment/paytrail"
:order-id-prefix {:tutu "TTU"
:astu "ASTU"
Expand Down
9 changes: 6 additions & 3 deletions oph-configuration/config.edn.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
:database-name "{{ maksut_db_name | default('maksut') }}"
:host "{{ maksut_db_host }}"
:port {{ maksut_db_port | default('5432') }}}
:payment {:paytrail-config {:host "{{ maksut_payment_paytrail_host | default('https://services.paytrail.com/payments')}}"
:merchant-id {{ maksut_payment_paytrail_id | default('375917')}}
:merchant-secret "{{ maksut_payment_paytrail_secret | default('SAIPPUAKAUPPIAS')}}"}
:payment {:paytrail-config {:default {:host "{{ maksut_payment_paytrail_host | default('https://services.paytrail.com/payments')}}"
:merchant-id {{ maksut_payment_paytrail_id | default('375917')}}
:merchant-secret "{{ maksut_payment_paytrail_secret | default('SAIPPUAKAUPPIAS')}}"}
:kkhakemusmaksu {:host "{{ maksut_payment_kkhakemusmaksu_paytrail_host | default('https://services.paytrail.com/payments')}}"
:merchant-id {{ maksut_payment_kkhakemusmaksu_paytrail_id | default('375917')}}
:merchant-secret "{{ maksut_payment_kkhakemusmaksu_paytrail_secret | default('SAIPPUAKAUPPIAS')}}"}}
:callback-uri "{{ maksut_payment_callback_uri }}"
:order-id-prefix {:tutu "TTU"
:astu "ASTU"
Expand Down
9 changes: 6 additions & 3 deletions oph-configuration/config.test.github.edn
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
:database-name "maksut"
:host "localhost"
:port 5432}
:payment {:paytrail-config {:host "http://localhost:9040/payments"
:merchant-id 12345
:merchant-secret "sikrot"}
:payment {:paytrail-config {:default {:host "http://localhost:9040/payments"
:merchant-id 12345
:merchant-secret "sikrot"}
:kkhakemusmaksu {:host "http://localhost:9040/payments"
:merchant-id 12345
:merchant-secret "sikrot"}}
:callback-uri "<ei käytetä mock paytrail käyttöliittymätestissä>"
:order-id-prefix {:tutu "TTU"
:astu "ASTU"
Expand Down
9 changes: 6 additions & 3 deletions oph-configuration/config.test.local-environment.edn
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
:database-name "maksut"
:host "localhost"
:port 15432}
:payment {:paytrail-config {:host "http://localhost:9040/payments"
:merchant-id 12345
:merchant-secret "sikrot"}
:payment {:paytrail-config {:default {:host "http://localhost:9040/payments"
:merchant-id 12345
:merchant-secret "sikrot"}
:kkhakemusmaksu {:host "http://localhost:9040/payments"
:merchant-id 12345
:merchant-secret "sikrot"}}
:callback-uri "http://localhost:19033/maksut/payment/paytrail"
:order-id-prefix {:tutu "TTU"
:astu "ASTU"
Expand Down
9 changes: 6 additions & 3 deletions src/clj/maksut/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
:database-name s/Str
:host s/Str
:port s/Int}
:payment {:paytrail-config {:host s/Str
:merchant-id s/Int
:merchant-secret s/Str}
:payment {:paytrail-config {:default {:host s/Str
:merchant-id s/Int
:merchant-secret s/Str}
:kkhakemusmaksu {:host s/Str
:merchant-id s/Int
:merchant-secret s/Str}}
:callback-uri s/Str
:order-id-prefix {:tutu s/Str
:astu s/Str
Expand Down
31 changes: 22 additions & 9 deletions src/clj/maksut/payment/payment_service.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
(java.time ZoneOffset ZonedDateTime)
(java.time.format DateTimeFormatter)))

(defn- merchant-key-from-order-id
[this order-id]
(let [prefixes (-> this :config :order-id-prefix)]
; Only hakemusmaksu ought to be using its own non-default merchant account for now.
(if (str/starts-with? order-id (:kkhakemusmaksu prefixes))
:kkhakemusmaksu
:default)))

(def op-payment-redirect (audit/->operation "MaksupalveluunOhjaus"))

(def op-get-kuitti (audit/->operation "KuitinHakeminen"))
Expand Down Expand Up @@ -76,11 +84,11 @@
"callbackUrls" callback-urls
}))

(defn- get-paytrail-config [this]
(defn- get-paytrail-config [this merchant-key]
(let [config (:config this)]
{:paytrail-host (-> config :paytrail-config :host)
:merchant-id (-> config :paytrail-config :merchant-id)
:merchant-secret (-> config :paytrail-config :merchant-secret)
{:paytrail-host (-> config :paytrail-config merchant-key :host)
:merchant-id (-> config :paytrail-config merchant-key :merchant-id)
:merchant-secret (-> config :paytrail-config merchant-key :merchant-secret)
:callback-uri (-> config :callback-uri)}))

(defn- authentication-headers [method merchant-id transaction-id]
Expand Down Expand Up @@ -136,7 +144,8 @@
(when (not= (:status lasku) "active")
(maksut-error :invoice-not-active (str "Maksua ei voi enää maksaa: " secret)))

(let [paytrail-config (get-paytrail-config this)
(let [merchant-key (merchant-key-from-order-id this order-id)
paytrail-config (get-paytrail-config this merchant-key)
paytrail-host (:paytrail-host paytrail-config)
merchant-id (:merchant-id paytrail-config)
merchant-secret (:merchant-secret paytrail-config)
Expand Down Expand Up @@ -237,7 +246,8 @@

(defn- process-success-callback [this db email-service pt-params locale storage-engine _]
(let [{:keys [checkout-status checkout-reference checkout-amount checkout-stamp timestamp]} pt-params
pt-config (get-paytrail-config this)
merchant-key (merchant-key-from-order-id this checkout-reference)
pt-config (get-paytrail-config this merchant-key)
oppija-baseurl (get-in this [:config :oppija-baseurl])
signed-headers (sign-request (:merchant-secret pt-config) (stringify-keys pt-params) nil)
return-error (fn [code msg]
Expand Down Expand Up @@ -271,9 +281,12 @@
(s/validate (p/extends-class-pred email-protocol/EmailServiceProtocol) email-service)
(s/validate (p/extends-class-pred audit/AuditLoggerProtocol) audit-logger)

(s/validate s/Str (get-in config [:payment :paytrail-config :host]))
(s/validate s/Int (get-in config [:payment :paytrail-config :merchant-id]))
(s/validate s/Str (get-in config [:payment :paytrail-config :merchant-secret]))
(s/validate s/Str (get-in config [:payment :paytrail-config :default :host]))
(s/validate s/Int (get-in config [:payment :paytrail-config :default :merchant-id]))
(s/validate s/Str (get-in config [:payment :paytrail-config :default :merchant-secret]))
(s/validate s/Str (get-in config [:payment :paytrail-config :kkhakemusmaksu :host]))
(s/validate s/Int (get-in config [:payment :paytrail-config :kkhakemusmaksu :merchant-id]))
(s/validate s/Str (get-in config [:payment :paytrail-config :kkhakemusmaksu :merchant-secret]))

(assoc this :config (merge (:payment config) (:urls config))))
(stop [this]
Expand Down

0 comments on commit f2f4a76

Please sign in to comment.