Implement payment record to Xero
This commit is contained in:
parent
e475a4e471
commit
53b9d6ab52
1 changed files with 11 additions and 2 deletions
13
src/Xero.hs
13
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
|
||||
|
|
Loading…
Reference in a new issue