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)
|
||||
])
|
||||
Just o' -> do
|
||||
existingOrder <-
|
||||
liftAndCatchIO $
|
||||
run $
|
||||
findXeroOrder
|
||||
(oaddress o')
|
||||
(xr_invNo invReq)
|
||||
(xr_shortCode invReq)
|
||||
case cast' . Doc =<< existingOrder of
|
||||
Nothing -> do
|
||||
res <-
|
||||
liftAndCatchIO $
|
||||
requestXeroToken pipe (c_dbName config) c "none" $ oaddress o'
|
||||
|
@ -689,7 +698,8 @@ routes pipe config = do
|
|||
Just xI -> do
|
||||
if xi_type xI == "ACCREC"
|
||||
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 do
|
||||
now <- liftIO getCurrentTime
|
||||
|
@ -724,7 +734,8 @@ routes pipe config = do
|
|||
(ocurrency o')
|
||||
(price cp)
|
||||
(xi_total xI)
|
||||
(xi_total xI / price cp)
|
||||
(xi_total xI /
|
||||
price cp)
|
||||
[ LineItem
|
||||
1
|
||||
("Invoice from " <>
|
||||
|
@ -740,7 +751,8 @@ routes pipe config = do
|
|||
(T.pack tk)
|
||||
_ <-
|
||||
liftAndCatchIO $
|
||||
run $ upsertOrder newOrder
|
||||
run $
|
||||
upsertOrder newOrder
|
||||
finalOrder <-
|
||||
liftAndCatchIO $
|
||||
run $
|
||||
|
@ -748,7 +760,8 @@ routes pipe config = do
|
|||
(oaddress o')
|
||||
(xi_number xI)
|
||||
(xi_shortcode xI)
|
||||
case cast' . Doc =<< finalOrder of
|
||||
case cast' . Doc =<<
|
||||
finalOrder of
|
||||
Nothing -> do
|
||||
status
|
||||
internalServerError500
|
||||
|
@ -763,7 +776,8 @@ routes pipe config = do
|
|||
, "order" .=
|
||||
toJSON
|
||||
(fO :: ZGoOrder)
|
||||
, "shop" .= oname o'
|
||||
, "shop" .=
|
||||
oname o'
|
||||
])
|
||||
else do
|
||||
status ok200
|
||||
|
@ -783,7 +797,8 @@ routes pipe config = do
|
|||
[ "reportType" .= (7 :: Integer)
|
||||
, "order" .=
|
||||
(Nothing :: Maybe ZGoOrder)
|
||||
, "shop" .= (Nothing :: Maybe String)
|
||||
, "shop" .=
|
||||
(Nothing :: Maybe String)
|
||||
])
|
||||
else do
|
||||
status ok200
|
||||
|
@ -809,6 +824,14 @@ routes pipe config = do
|
|||
, "order" .= (Nothing :: Maybe ZGoOrder)
|
||||
, "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 "/api/xeroaccount" $ do
|
||||
session <- param "session"
|
||||
|
|
Loading…
Reference in a new issue