diff --git a/oph-configuration/config.dev.edn b/oph-configuration/config.dev.edn index 5d2e711..dc4084f 100644 --- a/oph-configuration/config.dev.edn +++ b/oph-configuration/config.dev.edn @@ -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" diff --git a/oph-configuration/config.edn.template b/oph-configuration/config.edn.template index 7f97a37..a0a21f5 100644 --- a/oph-configuration/config.edn.template +++ b/oph-configuration/config.edn.template @@ -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" diff --git a/oph-configuration/config.test.github.edn b/oph-configuration/config.test.github.edn index 10f982b..69674cb 100644 --- a/oph-configuration/config.test.github.edn +++ b/oph-configuration/config.test.github.edn @@ -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 "" :order-id-prefix {:tutu "TTU" :astu "ASTU" diff --git a/oph-configuration/config.test.local-environment.edn b/oph-configuration/config.test.local-environment.edn index 7969c42..6967bab 100644 --- a/oph-configuration/config.test.local-environment.edn +++ b/oph-configuration/config.test.local-environment.edn @@ -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" diff --git a/src/clj/maksut/config.clj b/src/clj/maksut/config.clj index f546adc..5f832c9 100644 --- a/src/clj/maksut/config.clj +++ b/src/clj/maksut/config.clj @@ -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 diff --git a/src/clj/maksut/payment/payment_service.clj b/src/clj/maksut/payment/payment_service.clj index 4310ce3..da4c065 100644 --- a/src/clj/maksut/payment/payment_service.clj +++ b/src/clj/maksut/payment/payment_service.clj @@ -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")) @@ -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] @@ -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) @@ -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] @@ -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]