Compare commits
No commits in common. "a64bf28328f30ded113bd76bff51b82cf29b088d" and "c88a1b199db35f7185a51a9823b49743114fb082" have entirely different histories.
a64bf28328
...
c88a1b199d
|
@ -36,12 +36,6 @@ to the Banqup API of Unifiedpost.
|
|||
- Fetch the invoice in Banqup to verify its existence in the portal and retrieve its id in Banqup.
|
||||
- Post a request to the Banqup API to mark the invoice as 'Paid'.
|
||||
- Display the response from the Banqup API, confirming the success or failure of the request.
|
||||
* Run `python3 delete_invoice.py <documentNo>`, where `<documentNo>` is the human readable invoice number in Openbravo, to delete an invoice in Banqup portal via the API.
|
||||
- The application will do the following:
|
||||
- Authenticate with Banqup using OAuth2, for which it will launch a webbrowser to complete the authentication. The browser will receive the response from the Banqup server including the authentication token. The user will need to 'Copy' and 'Paste' this response at the corresponding prompt in the terminal.
|
||||
- Fetch the invoice in Banqup to verify its existence in the portal and retrieve its id in Banqup.
|
||||
- Post a request to the Banqup API to delete the invoice.
|
||||
- Display the response from the Banqup API, confirming the success or failure of the request.
|
||||
|
||||
**Credits**
|
||||
|
||||
|
|
15
api.py
15
api.py
|
@ -61,16 +61,13 @@ class OpenbravoToBanqupAPI:
|
|||
self.authHandler.checkHeaderTokens()
|
||||
response = self.doRequest(method, url, data, headers, files)
|
||||
|
||||
if response.status_code != 204:
|
||||
if 'json' in response.headers['Content-Type']:
|
||||
respContent = response.json()
|
||||
elif 'pdf' in response.headers['Content-Type']:
|
||||
respContent = response.content
|
||||
else:
|
||||
respContent = ''
|
||||
|
||||
if 'json' in response.headers['Content-Type']:
|
||||
respContent = response.json()
|
||||
elif 'pdf' in response.headers['Content-Type']:
|
||||
respContent = response.content
|
||||
|
||||
return response.status_code, response.headers, respContent
|
||||
|
||||
|
||||
def get(self, url, data=None, headers=None):
|
||||
status, headers, response = self.request('GET', url, data, headers)
|
||||
return status, headers, response
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
import requests
|
||||
from requests_oauthlib import OAuth2Session
|
||||
import json
|
||||
import sys
|
||||
import webbrowser
|
||||
from config import *
|
||||
from cachehandler import CacheHandler
|
||||
from authhandler import AuthHandler
|
||||
from api import OpenbravoToBanqupAPI
|
||||
from datetime import timedelta, date
|
||||
|
||||
def delete_invoice(document):
|
||||
|
||||
api = OpenbravoToBanqupAPI(bq_client_id,bq_client_secret)
|
||||
authUrl = api.authHandler.getAuthURL(bq_redirect_uri)
|
||||
webbrowser.open(authUrl)
|
||||
response = input('Paste response: ')
|
||||
token = api.authHandler.retrieveToken(response, redirectUri=bq_redirect_uri)
|
||||
#print(token)
|
||||
invoice_list = api.get('sales-invoices?client_id='+banqup_client_id+'&sales_invoice_number='+document,None,None)
|
||||
if not invoice_list[2]['results']:
|
||||
print('***********************')
|
||||
print('The invoice number provided does not exist in the Banqup portal.')
|
||||
print('Please verify and try again.')
|
||||
print('***********************')
|
||||
return
|
||||
invoice_id = str(invoice_list[2]['results'][0]['id'])
|
||||
#print(invoice_id)
|
||||
payload = json.dumps({})
|
||||
invoice_action = api.delete('sales-invoices/'+invoice_id,json.loads(payload),None)
|
||||
print(invoice_action)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
delete_invoice(str(sys.argv[1]))
|
Loading…
Reference in a new issue