From 53b9d6ab5204638a5789a5c6c9ecd75bcf8c2ecb Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Thu, 8 Sep 2022 14:05:42 -0500 Subject: [PATCH] Implement payment record to Xero --- src/Xero.hs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Xero.hs b/src/Xero.hs index ae6d8e0..7ddfb08 100644 --- a/src/Xero.hs +++ b/src/Xero.hs @@ -406,17 +406,26 @@ payXeroInvoice :: Pipe -> T.Text -> T.Text -> T.Text -> Double -> IO () payXeroInvoice pipe dbName inv address amt = do token <- access pipe master dbName $ findToken address let aToken = t_access <$> (token >>= cast' . Doc) + let aCode = t_code <$> (token >>= cast' . Doc) o <- access pipe master dbName $ findOwner address let tenant = ocrmToken <$> (o >>= cast' . Doc) - if isJust aToken && isJust tenant + today <- getCurrentTime + if isJust aToken && isJust tenant && isJust aCode then do let req = + setRequestBodyJSON + (object + [ "Invoice" .= object ["InvoiceNumber" .= inv] + , "Account" .= object ["Code" .= fromMaybe "" aCode] + , "Date" .= utctDay today + , "Amount" .= amt + ]) $ addRequestHeader "Accept" "application/json" $ addRequestHeader "Xero-tenant-id" (encodeUtf8 $ fromMaybe "" tenant) $ setRequestSecure True $ setRequestBearerAuth (encodeUtf8 (fromMaybe "" aToken)) $ setRequestPort 443 $ - setRequestPath "/api.xero/2.0/Payments" $ + setRequestPath "/api.xro/2.0/Payments" $ setRequestHost "api.xero.com" $ setRequestMethod "PUT" defaultRequest res <- httpJSON req