Add check of existing order
This commit is contained in:
parent
4bd49c76d4
commit
6e0cb54032
1 changed files with 150 additions and 127 deletions
|
@ -668,6 +668,15 @@ routes pipe config = do
|
||||||
, "shop" .= (Nothing :: Maybe String)
|
, "shop" .= (Nothing :: Maybe String)
|
||||||
])
|
])
|
||||||
Just o' -> do
|
Just o' -> do
|
||||||
|
existingOrder <-
|
||||||
|
liftAndCatchIO $
|
||||||
|
run $
|
||||||
|
findXeroOrder
|
||||||
|
(oaddress o')
|
||||||
|
(xr_invNo invReq)
|
||||||
|
(xr_shortCode invReq)
|
||||||
|
case cast' . Doc =<< existingOrder of
|
||||||
|
Nothing -> do
|
||||||
res <-
|
res <-
|
||||||
liftAndCatchIO $
|
liftAndCatchIO $
|
||||||
requestXeroToken pipe (c_dbName config) c "none" $ oaddress o'
|
requestXeroToken pipe (c_dbName config) c "none" $ oaddress o'
|
||||||
|
@ -689,7 +698,8 @@ routes pipe config = do
|
||||||
Just xI -> do
|
Just xI -> do
|
||||||
if xi_type xI == "ACCREC"
|
if xi_type xI == "ACCREC"
|
||||||
then if xi_status xI == "AUTHORISED"
|
then if xi_status xI == "AUTHORISED"
|
||||||
then if xi_currency xI == T.toUpper (ocurrency o')
|
then if xi_currency xI ==
|
||||||
|
T.toUpper (ocurrency o')
|
||||||
then if xi_total xI == xr_amount invReq
|
then if xi_total xI == xr_amount invReq
|
||||||
then do
|
then do
|
||||||
now <- liftIO getCurrentTime
|
now <- liftIO getCurrentTime
|
||||||
|
@ -724,7 +734,8 @@ routes pipe config = do
|
||||||
(ocurrency o')
|
(ocurrency o')
|
||||||
(price cp)
|
(price cp)
|
||||||
(xi_total xI)
|
(xi_total xI)
|
||||||
(xi_total xI / price cp)
|
(xi_total xI /
|
||||||
|
price cp)
|
||||||
[ LineItem
|
[ LineItem
|
||||||
1
|
1
|
||||||
("Invoice from " <>
|
("Invoice from " <>
|
||||||
|
@ -740,7 +751,8 @@ routes pipe config = do
|
||||||
(T.pack tk)
|
(T.pack tk)
|
||||||
_ <-
|
_ <-
|
||||||
liftAndCatchIO $
|
liftAndCatchIO $
|
||||||
run $ upsertOrder newOrder
|
run $
|
||||||
|
upsertOrder newOrder
|
||||||
finalOrder <-
|
finalOrder <-
|
||||||
liftAndCatchIO $
|
liftAndCatchIO $
|
||||||
run $
|
run $
|
||||||
|
@ -748,7 +760,8 @@ routes pipe config = do
|
||||||
(oaddress o')
|
(oaddress o')
|
||||||
(xi_number xI)
|
(xi_number xI)
|
||||||
(xi_shortcode xI)
|
(xi_shortcode xI)
|
||||||
case cast' . Doc =<< finalOrder of
|
case cast' . Doc =<<
|
||||||
|
finalOrder of
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
status
|
status
|
||||||
internalServerError500
|
internalServerError500
|
||||||
|
@ -763,7 +776,8 @@ routes pipe config = do
|
||||||
, "order" .=
|
, "order" .=
|
||||||
toJSON
|
toJSON
|
||||||
(fO :: ZGoOrder)
|
(fO :: ZGoOrder)
|
||||||
, "shop" .= oname o'
|
, "shop" .=
|
||||||
|
oname o'
|
||||||
])
|
])
|
||||||
else do
|
else do
|
||||||
status ok200
|
status ok200
|
||||||
|
@ -783,7 +797,8 @@ routes pipe config = do
|
||||||
[ "reportType" .= (7 :: Integer)
|
[ "reportType" .= (7 :: Integer)
|
||||||
, "order" .=
|
, "order" .=
|
||||||
(Nothing :: Maybe ZGoOrder)
|
(Nothing :: Maybe ZGoOrder)
|
||||||
, "shop" .= (Nothing :: Maybe String)
|
, "shop" .=
|
||||||
|
(Nothing :: Maybe String)
|
||||||
])
|
])
|
||||||
else do
|
else do
|
||||||
status ok200
|
status ok200
|
||||||
|
@ -809,6 +824,14 @@ routes pipe config = do
|
||||||
, "order" .= (Nothing :: Maybe ZGoOrder)
|
, "order" .= (Nothing :: Maybe ZGoOrder)
|
||||||
, "shop" .= (Nothing :: Maybe String)
|
, "shop" .= (Nothing :: Maybe String)
|
||||||
])
|
])
|
||||||
|
Just eO -> do
|
||||||
|
status created201
|
||||||
|
Web.Scotty.json
|
||||||
|
(object
|
||||||
|
[ "reportType" .= (0 :: Integer)
|
||||||
|
, "order" .= toJSON (eO :: ZGoOrder)
|
||||||
|
, "shop" .= oname o'
|
||||||
|
])
|
||||||
-- Get the xeroaccount code
|
-- Get the xeroaccount code
|
||||||
get "/api/xeroaccount" $ do
|
get "/api/xeroaccount" $ do
|
||||||
session <- param "session"
|
session <- param "session"
|
||||||
|
|
Loading…
Reference in a new issue