(require '[wagoe.payments.ports :as psp])
(defn initiate-payment! [payment-provider order]
(let [{:keys [checkout-url provider-checkout-id correlation-id]}
(psp/create-checkout-session payment-provider
{:amount-cents (:total-cents order)
:currency "EUR"
:description (str "Order #" (:id order))
:redirect-url (str base-url "/orders/" (:id order) "/confirmation")
:webhook-url (str base-url "/api/v1/payments/webhook")
:metadata {:order-id (str (:id order))}})]
;; Store both on the order: the webhook echoes correlation-id,
;; get-payment-status takes provider-checkout-id
(save-checkout-ids! order provider-checkout-id correlation-id)
;; Redirect the user to the PSP
checkout-url))