NativePayment (..),
Payment' (..),
PaymentId,
nativeRequest,
)
( (^.),
view,
)
-- import Network.HTTP.Client
-- ( defaultManagerSettings,
-- managerResponseTimeout,
-- responseTimeoutMicro,
-- )
-- import Network.HTTP.Client.OpenSSL
-- import Network.Wreq
-- ( defaults,
-- manager,
-- )
-- import OpenSSL.Session (context)
( readRequestBody,
)
do
uid <- requireUserId
sid <- requireId "subscriptionId" SubscriptionId
snapEval $ findPayableRequests uid sid
do
requestBody <- readRequestBody 4096
(prid, preq) <- getBip70PaymentRequestHandler
pmnt <-
either
(\msg -> snapError 400 $ "Could not decode payment response: " <> show msg)
(pure . Bitcoin.Payment Nothing Nothing Nothing (preq ^. Bitcoin.paymentRequestKey))
(runGetLazy decodeMessage requestBody)
now <- liftIO $ C.getCurrentTime
-- let opts =
-- defaults
-- & manager
-- .~ Left (opensslManagerSettings context)
-- & manager
-- .~ Left
-- ( defaultManagerSettings
-- { managerResponseTimeout = responseTimeoutMicro 10000
-- }
-- )
-- exchResp <-
-- liftIO
-- . try @HttpException
-- $ asValue
-- =<< (withOpenSSL $ getWith opts (cfg ^. exchangeRateServiceURI))
-- _ <- traverse (logError . T.encodeUtf8 . show) (preview _Left exchResp)
-- (preview (_Right . responseBody) exchResp)
let newPayment = Payment (Const prid) now (BitcoinPayment pmnt)
snapEval . liftdb $ CreatePayment newPayment
do
(rid, SomePaymentRequest preq) <- getBip70PaymentRequestHandler'
case (preq ^. nativeRequest) of
Bip70Request bp -> pure (rid, bp)
_ -> snapError 400 $ "Not a BIP-70 bitcoin payment request."
do
pkey <- Bitcoin.PaymentKey . decodeUtf8 <$> requireParam "paymentRequestKey"
fromMaybeT
( snapError 404 $
"Outstanding payment request not found for key "
<> (view Bitcoin._PaymentKey pkey)
)
(mapMaybeT snapEval $ findPaymentRequestByKey pkey)
(