Correct order payment logic

This commit is contained in:
Rene Vergara 2023-05-16 14:27:10 -05:00
parent a8d4329e7d
commit 9f13cbf302
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2
3 changed files with 15 additions and 7 deletions

View file

@ -4,7 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.5.0] ## [1.5.1]
### Changed
- Modified the process to mark paid orders to ensure only payments to the shop's wallet get marked as paid
## [1.5.0] - 2023-05-15
### Added ### Added

View file

@ -1,5 +1,5 @@
name: zgo-backend name: zgo-backend
version: 1.5.0 version: 1.5.1
git: "https://git.vergara.tech/Vergara_Tech/zgo-backend" git: "https://git.vergara.tech/Vergara_Tech/zgo-backend"
license: BOSL license: BOSL
author: "Rene Vergara" author: "Rene Vergara"

View file

@ -1307,8 +1307,7 @@ scanPayments config pipe = do
let r = mkRegex ".*ZGo Order::([0-9a-fA-F]{24}).*" let r = mkRegex ".*ZGo Order::([0-9a-fA-F]{24}).*"
let k = filter (isRelevant r) txs let k = filter (isRelevant r) txs
let j = map (getOrderId r) k let j = map (getOrderId r) k
mapM_ (recordPayment p (c_dbName config)) j mapM_ (recordPayment p (c_dbName config) z) j
mapM_ (access p master (c_dbName config) . markOrderPaid) j
Left e -> print e Left e -> print e
getOrderId :: Text.Regex.Regex -> ZcashTx -> (String, Double) getOrderId :: Text.Regex.Regex -> ZcashTx -> (String, Double)
getOrderId re t = do getOrderId re t = do
@ -1316,8 +1315,8 @@ scanPayments config pipe = do
if not (null reg) if not (null reg)
then (fst $ head reg ! 1, zamount t) then (fst $ head reg ! 1, zamount t)
else ("", 0) else ("", 0)
recordPayment :: Pipe -> T.Text -> (String, Double) -> IO () recordPayment :: Pipe -> T.Text -> ZcashAddress -> (String, Double) -> IO ()
recordPayment p dbName x = do recordPayment p dbName z x = do
o <- access p master dbName $ findOrderById (fst x) o <- access p master dbName $ findOrderById (fst x)
let xOrder = o >>= (cast' . Doc) let xOrder = o >>= (cast' . Doc)
case xOrder of case xOrder of
@ -1325,7 +1324,8 @@ scanPayments config pipe = do
Just xO -> Just xO ->
when when
(not (qpaid xO) && (not (qpaid xO) &&
qexternalInvoice xO /= "" && qtotalZec xO == snd x) $ do qexternalInvoice xO /= "" &&
qtotalZec xO == snd x && addy z == qaddress xO) $ do
let sReg = mkRegex "(.*)-([a-fA-f0-9]{24})" let sReg = mkRegex "(.*)-([a-fA-f0-9]{24})"
let sResult = matchAllText sReg (T.unpack $ qsession xO) let sResult = matchAllText sReg (T.unpack $ qsession xO)
if not (null sResult) if not (null sResult)
@ -1344,6 +1344,7 @@ scanPayments config pipe = do
(qaddress xO) (qaddress xO)
(qtotal xO) (qtotal xO)
(qtotalZec xO) (qtotalZec xO)
liftIO $ access p master dbName $ markOrderPaid x
"WC" -> do "WC" -> do
let wOwner = fst $ head sResult ! 2 let wOwner = fst $ head sResult ! 2
wooT <- wooT <-
@ -1371,6 +1372,7 @@ scanPayments config pipe = do
(C.pack . T.unpack $ w_token wt) (C.pack . T.unpack $ w_token wt)
(C.pack . show $ qprice xO) (C.pack . show $ qprice xO)
(C.pack . show $ qtotalZec xO) (C.pack . show $ qtotalZec xO)
liftIO $ access p master dbName $ markOrderPaid x
else error else error
"Couldn't parse externalInvoice for WooCommerce" "Couldn't parse externalInvoice for WooCommerce"
_ -> putStrLn "Not an integration order" _ -> putStrLn "Not an integration order"