Transactions Endpoint
The examples in this section are related to the Transactions Endpoint (see in Swagger).

Document Structure:
Delete a document in the DMS and remove link to the transaction.
#Code reference - POST.transaction
#Code reference - GET.transactions
#Code reference - POST.dms_link_document
[TestMethod]
public void REST_Transaction_document_DELETE()
{
state = new ErrorState { passed = false };
var transactions = GET.transactions(manager);
var transaction = transactions.FirstOrDefault(t => t.hasDocument);
if (transaction == null)
{
string path = Helper.get_random_invoice("../../data/invoices/");
decimal amount = 5000m;
Transaction trans = Create.transaction_simple(amount, manager);
state.passed = POST.transaction(trans, manager);
Assert.AreEqual(true, state.passed, state.message);
transactions = GET.transactions(manager);
transaction = transactions.FirstOrDefault(t => t.hasDocument == false);
if (transaction != null)
{
state.passed = POST.dms_link_document(path, "transactions", transaction.id, manager);
Assert.AreEqual(true, state.passed, state.message);
}
}
transactions = GET.transactions(manager);
transaction = transactions.FirstOrDefault(t => t.hasDocument);
if (transaction != null)
{
state.passed = false;
state.passed = DELETE.dms_document("transactions", transaction.id, manager);
Assert.AreEqual(true, state.passed, state.message);
if (GET.transaction_by_id(transaction.id, manager).hasDocument == false)
{
state.passed = true;
}
}
Assert.AreEqual(true, state.passed, state.message);
}
class Delete{
public static bool dms_document(string area, Guid id, Manager manager)
{
string request = $"clients/{manager.getCurrentClient().id}/fiscalYears/{manager.getCurrentFiscalYear().id}/{area}/{id}/document";
var response = manager.httpClient.DeleteAsync(request).Result;
if (response.StatusCode != HttpStatusCode.OK)
{
ResponseDetails details = new ResponseDetails();
}
return response.IsSuccessStatusCode;
}
}
UNDER CONSTRUCTION
UNDER CONSTRUCTION
Upload a document to the DMS and link the document to a transaction.
#Code reference - POST.transaction
#Code reference - GET.transactions
#Code reference - GET.transaction_document_download_store
[TestMethod]
public void REST_Transaction_document_upload_and_link_POST()
{
state = new ErrorState { passed = false };
Transaction _transaction = null;
string path = Helper.get_random_invoice("../../data/invoices/");
var transactions = GET.transactions(manager);
if (transactions.Count == 0)
{
decimal amount = 5000m;
_transaction = Create.transaction_simple(amount, manager);
state.passed = POST.transaction(_transaction, manager);
Assert.AreEqual(true, state.passed, state.message);
}
transactions = GET.transactions(manager);
var transaction = transactions.FirstOrDefault(t => t.hasDocument == false);
if (transaction != null)
{
state.passed = false;
state.passed = POST.dms_link_document(path, "transactions", transaction.id, manager);
Assert.AreEqual(true, state.passed, state.message);
}
transaction = GET.transaction_by_id(transaction.id, manager);
if (transaction != null)
{
state.passed = false;
state.passed = GET.transaction_document_download_store(transaction.id, "transactions", manager);
Assert.AreEqual(true, state.passed, state.message);
}
}
class POST {
public static bool dms_link_document(string path, string area, Guid id, Manager manager)
{
var content = new MultipartFormDataContent($"Upload----{path}");
FileStream fs = File.OpenRead(path);
content.Add(new StreamContent(fs), $"{area}_document", Path.GetFileName(path));
string request = $"clients/{manager.getCurrentClient().id}/fiscalYears/{manager.getCurrentFiscalYear().id}/{area}/{id}/document";
var response = manager.httpClient.PostAsync(string.Format(request), content).Result;
if (response.StatusCode != HttpStatusCode.OK)
{
ResponseDetails details = new ResponseDetails(response);
}
return response.IsSuccessStatusCode;
}
}
UNDER CONSTRUCTION
Download a document linked to a transaction and store the document on the file system.
#Code reference - POST.transaction
#Code reference - GET.transactions
[TestMethod]
public void REST_Transaction_document_download_and_store_GET()
{
state = new ErrorState { passed = false };
var transactions = GET.transactions(manager);
var transaction = transactions.FirstOrDefault(t => t.hasDocument);
if (transaction == null)
{
string path = Helper.get_random_invoice("../../data/invoices/");
decimal amount = 5000m;
Transaction trans = Create.transaction_simple(amount, manager);
state.passed = POST.transaction(trans, manager);
Assert.AreEqual(true, state.passed, state.message);
transactions = GET.transactions(manager);
transaction = transactions.FirstOrDefault(t => t.hasDocument == false);
if (transaction != null)
{
state.passed = POST.dms_link_document(path, "transactions", transaction.id, manager);
Assert.AreEqual(true, state.passed, state.message);
}
}
transactions = GET.transactions(manager);
transaction = transactions.FirstOrDefault(t => t.hasDocument);
if (transaction != null)
{
state.passed = GET.dms_document_download_store("transactions", transaction.id, manager);
Assert.AreEqual(true, state.passed, state.message);
}
}
class GET{
public static bool dms_document_download_store(string area, Guid id, Manager manager)
{
string request = $"clients/{manager.getCurrentClient().id}/fiscalYears/{manager.getCurrentFiscalYear().id}/{area}/{id}/document";
var response = manager.httpClient.GetAsync(request).Result;
if (!response.IsSuccessStatusCode)
throw new Exception($"{(int)response.StatusCode} {response.ReasonPhrase}");
Stream _stream = null;
try
{
_stream = response.Content.ReadAsStreamAsync().Result;
}
catch (SystemException ex)
{
string message = "" + ex;
}
var fileName = response.Content.Headers.ContentDisposition.FileName;
fileName = Path.Combine("C:/temp/", fileName);
using (Stream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write),
contentStream = response.Content.ReadAsStreamAsync().Result)
{
contentStream.CopyToAsync(stream).Wait();
}
return response.IsSuccessStatusCode;
}
}
UNDER CONSTRUCTION
{
}
Save a document to the DMS.
[TestMethod]
public void REST_Transaction_unprocesssed_documents_POST()
{
ErrorState state = new ErrorState { passed = false };
string path = "../../data/invoices/QR_QRR_CHF_3003.pdf";
bool passed = POST.dms_upload_document(path, "transactions", manager);
Assert.AreEqual(true, passed, state.message);
}
class POST{
public static bool dms_upload_document(string path, string area, Manager manager)
{
var content = new MultipartFormDataContent($"Upload----{path}");
FileStream fs = File.OpenRead(path);
content.Add(new StreamContent(fs), $"{area}_document", Path.GetFileName(path));
string request = $"clients/{manager.getCurrentClient().id}/fiscalyears/{manager.getCurrentFiscalYear().id}/{area}/documents";
var response = manager.httpClient.PostAsync(string.Format(request), content).Result;
if (response.StatusCode != HttpStatusCode.OK)
{
ResponseDetails details = new ResponseDetails(response);
}
return response.IsSuccessStatusCode;
}
}
UNDER CONSTRUCTION
UNDER CONSTRUCTION
Load pending documents. A pending document is a document stored in dms or archive, which has not yet been attached to a transaction.
[TestMethod]
public void REST_Transaction_pending_documents_GET()
{
state = new ErrorState { passed = false };
string path = "../../data/invoices/QR_QRR_CHF_3003.pdf";
bool passed = POST.dms_upload_document(path, "transactions", manager);
Assert.AreEqual(true, passed, state.message);
List<Document> documents = GET.dms_pending_documents("transactions", manager);
state.passed = false;
if (documents.Count >= 1) {
state.passed = true;
}
Assert.AreEqual(true, state.passed, state.message);
}
class GET{
public static List<Document> dms_pending_documents(string area, Manager manager)
{
List docs = new List();
string request = $"clients/{manager.getCurrentClient().id}/fiscalyears/{manager.getCurrentFiscalYear().id}/{area}/documents/pending";
var response = manager.httpClient.GetAsync(request).Result;
if (response.IsSuccessStatusCode) {
var documents = JsonConvert.DeserializeObject>(response.Content.ReadAsStringAsync().Result);
foreach (var document in documents) {
docs.Add(document);
}
}
return docs;
}
}
UNDER CONSTRUCTION
{
}