From 625fdcaee86b93bbce7833134033757efcad9476 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Fri, 22 Jul 2022 14:01:08 -0500 Subject: [PATCH] Add check of payment amount --- src/Order.hs | 7 ++++--- src/ZGoBackend.hs | 10 +++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Order.hs b/src/Order.hs index dae4542..04499f3 100644 --- a/src/Order.hs +++ b/src/Order.hs @@ -210,10 +210,11 @@ findAllOrders a = rest =<< find (select ["address" =: a] "orders") deleteOrder :: String -> Action IO () deleteOrder i = deleteOne (select ["_id" =: (read i :: B.ObjectId)] "orders") -markOrderPaid :: String -> Action IO () -markOrderPaid i = +markOrderPaid :: (String, Double) -> Action IO () +markOrderPaid (i, a) = do + let modify - (select ["_id" =: (read i :: B.ObjectId)] "orders") + (select ["_id" =: (read i :: B.ObjectId), "totalZec" =: a] "orders") ["$set" =: ["paid" =: True]] -- | Helper function to round to 8 decimal places diff --git a/src/ZGoBackend.hs b/src/ZGoBackend.hs index 568b8d3..d9ab820 100644 --- a/src/ZGoBackend.hs +++ b/src/ZGoBackend.hs @@ -294,10 +294,6 @@ decodeHexText h = E.decodeUtf8With lenientDecode $ BS.pack $ hexRead h encodeHexText :: T.Text -> String encodeHexText t = T.unpack . toText . fromBytes $ E.encodeUtf8 t --- | Helper function to round to 8 decimal places -roundZec :: Double -> Double -roundZec n = fromInteger (round $ n * (10 ^ 8)) / (10.0 ^^ 8) - -- Types for the ZGo database documents -- | Type to model a country for the database's country list data Country = @@ -788,12 +784,12 @@ scanPayments config pipe = do let j = map (getOrderId r) k mapM_ (access p master (c_dbName config) . markOrderPaid) j Left e -> putStrLn $ T.unpack e - getOrderId :: Text.Regex.Regex -> ZcashTx -> String + getOrderId :: Text.Regex.Regex -> ZcashTx -> (String, Double) getOrderId re t = do let reg = matchAllText re (T.unpack $ zmemo t) if not (null reg) - then fst $ head reg ! 1 - else "" + then (fst $ head reg ! 1, zamount t) + else ("", 0) -- | RPC methods -- | List addresses with viewing keys loaded