Create payments
The examples in this section are related to the payment of invoices.
Example Code
#Code reference - GET.party_by_id
#Code reference - Create.payables_invoice_vat
#Code reference - POST.payables_invoice
#Code reference - GET.payables_invoice_by_freeinvoicenum
[TestMethod]
public void REST_Payables_invoice_pay()
{
state = new ErrorState { passed = false };
decimal payment_amount = 4000.0m;
Party party = GET.party_by_name("Tamedia AG", manager);
party = GET.party_by_id(party.id, manager);
List postings = new List();
postings.Add(payment_amount);
Invoice_DTO invoice_dto = new Invoice_DTO
{
party = party,
manager = manager,
date = DateTime.Today,
posting_amounts = postings,
payment_amount = payment_amount,
vat_code = "USTn",
free_inv_num = "PI_2910",
contra_account = "3200",
payslip_code = "",
text = "Invoice incl. VAT",
invoiceType = Convert.ToBoolean(InvoiceType.INCLUSIVE),
payment_fc_amount = payment_amount
};
Invoice invoice = Create.payables_invoice_vat(invoice_dto);
state.passed = POST.payables_invoice(invoice, manager);
Assert.AreEqual(true, state.passed, state.message);
invoice = GET.payables_invoice_by_freeinvoicenum(invoice_dto.free_inv_num, manager);
if (invoice != null)
{
state.passed = false;
DateTime pay_date = DateTime.Today;
state.passed = POST.payables_invoice_pay(invoice, pay_date, manager);
Assert.AreEqual(true, state.passed, state.message);
}
}
class POST
{
public static bool payables_invoice_pay(Invoice invoice, DateTime date, Manager manager)
{
string request = $"clients/{manager.getCurrentClient().id}/fiscalYears/{manager.getCurrentFiscalYear().id}/payables/invoices/{invoice.id}/pay?date={date.ToString("yyyy-MM-dd")}";
var serialized = JsonConvert.SerializeObject(invoice);
var content = new StringContent(serialized, Encoding.UTF8, "application/json");
var response = manager.httpClient.PostAsync(request, content).Result;
if (response.StatusCode != HttpStatusCode.OK)
{
ResponseDetails details = new ResponseDetails(response);
}
return response.IsSuccessStatusCode;
}
}
UNDER CONSTRUCTION
POST Request:
{
"id": "f67b5863-783c-4caf-97d9-71d89303c62b",
"authorizerFID": -1,
"partyFID": 33,
"payMethodFID": 35,
"payTermFID": 9,
"vatFID": -1,
"personRoleFID": 3,
"invoiceDate": "2022-05-16T00:00:00",
"dueDate": "2022-06-15T00:00:00",
"modifyDate": "2022-05-16T08:21:00.513",
"invoiceNum": 1,
"reminderLevel": 0,
"freeInvoiceNum": "PI_2910",
"text": "New Payables Invoice",
"PayslipCode": "",
"totalAmount": 4000.0,
"totalAmountFC": 4000.0,
"exchangeRate": 1.0,
"IsAuthorized": true,
"noReminders": false,
"Remarks": "",
"partyNum": 1042,
"partyName": "Tamedia AG",
"partyShortName": "TamZür",
"payTermCode": "30T",
"accountCode": "2000",
"currencyCode": "CHF",
"balance": 4000.0,
"balanceFC": 4000.0,
"barCode": "",
"currentReminderLevel": 0,
"hasDocument": 0,
"currentReminderDate": "1753-01-01T00:00:00",
"paymentPostings": [],
"transaction": {
"id": "f67b5863-783c-4caf-97d9-71d89303c62b",
"fiscalYearFID": 17,
"userFID": 2,
"transactionTypeFID": 3,
"docType": "",
"docNum": 55,
"docDate": "2022-05-16T00:00:00",
"modifyDate": "2022-05-16T08:21:00.443",
"isConfirmed": true,
"numRangeFID": 129,
"hasDocument": false,
"postings": [
{
"id": "2d2d5cdd-d4a8-464b-8677-baa1051f8428",
"transactionFID": "f67b5863-783c-4caf-97d9-71d89303c62b",
"invoiceFID": "f67b5863-783c-4caf-97d9-71d89303c62b",
"accountFID": 46,
"contraAccountFID": 155,
"vatFID": -1,
"vatAccountFID": -1,
"costCenterFID": -1,
"postingTypeFID": 2,
"amount": 4000.0,
"fcAmount": 4000.0,
"exchangeRate": 1.0,
"vatAmount": 0.0,
"vatFcAmount": 0.0,
"vatPercent": 0.0,
"vatQuote": 0.0,
"text": "Payables Invoice Posting #1",
"freeCode": "PI_2223",
"isDebit": false,
"isInclusive": false,
"isInvisible": false,
"postingIndex": 1,
"partyNum": 1042,
"freepartyNum": "",
"partyName": "Tamedia AG",
"invoiceNum": 1,
"freeInvoiceNum": "",
"invoiceDate": "2022-05-16T00:00:00"
},
{
"id": "13271561-7c0a-461f-8291-78549f00bfc0",
"transactionFID": "f67b5863-783c-4caf-97d9-71d89303c62b",
"invoiceFID": "f67b5863-783c-4caf-97d9-71d89303c62b",
"accountFID": 155,
"contraAccountFID": 46,
"vatFID": 9,
"vatAccountFID": 51,
"costCenterFID": -1,
"postingTypeFID": 2,
"amount": 3714.02,
"fcAmount": 3714.02,
"exchangeRate": 1.0,
"vatAmount": 285.98,
"vatFcAmount": 285.98,
"vatPercent": 7.7,
"vatQuote": 100.0,
"text": "Payables Posting #",
"freeCode": "",
"isDebit": true,
"isInclusive": true,
"isInvisible": false,
"postingIndex": 2,
"partyNum": 1042,
"freepartyNum": "",
"partyName": "Tamedia AG",
"invoiceNum": 1,
"freeInvoiceNum": "",
"invoiceDate": "2022-05-16T00:00:00"
}
]
}
}
Pay a payables invoice partially.
#Code reference - GET.party_by_id
#Code reference - Create.payables_invoice_vat
#Code reference - POST.payables_invoice
#Code reference - GET.payables_invoice_by_freeinvoicenum
#Code reference - GET.account_by_account_code
[TestMethod]
public void REST_Payables_manual_payment_partial_payment_POST()
{
state = new ErrorState { passed = false };
decimal payment_amount = 3333.0m;
decimal partial_payment_amount = 1111.0m;
Party party = GET.party_by_name("Tamedia AG", manager);
party = GET.party_by_id(party.id, manager);
List postings = new List();
postings.Add(payment_amount);
Invoice_DTO invoice_dto = new Invoice_DTO
{
party = party,
manager = manager,
date = DateTime.Today,
posting_amounts = postings,
payment_amount = payment_amount,
vat_code = "USTn",
free_inv_num = "PI_2910",
contra_account = "3200",
payslip_code = "",
text = "Invoice incl. VAT",
invoiceType = Convert.ToBoolean(InvoiceType.INCLUSIVE),
payment_fc_amount = payment_amount
};
Invoice invoice = Create.payables_invoice_vat(invoice_dto);
state.passed = POST.payables_invoice(invoice, manager);
Assert.AreEqual(true, state.passed, state.message);
invoice = GET.payables_invoice_by_freeinvoicenum(invoice_dto.free_inv_num, manager);
Payment payment = Create.payables_payment_partial(invoice, partial_payment_amount, manager);
state.passed = POST.payables_payment(payment, manager);
Assert.AreEqual(true, state.passed, state.message);
}
class Create
{
public static Payment payables_payment_partial(Invoice invoice, decimal partial_payment_amount, Manager manager)
{
string paymentAccCode = "1020";
Account account = GET.account_by_account_code(paymentAccCode, manager);
DateTime date = DateTime.Today;
Payment payment = new Payment
{
accountFID = account.id,
text = "Payment partial",
partyFID = invoice.partyFID;
};
payment.transaction.docDate = new DateTime(date.Year, date.Month, date.Day);
PaymentDetail payment_detail = new PaymentDetail
{
invoiceFID = invoice.id,
payAmount = partial_payment_amount,
payAmountFC = partial_payment_amount,
text = "paymentdetails text"
};
payment.paymentDetails.Add(payment_detail);
return payment;
}
}
class POST
{
public static bool payables_payment(Payment payment, Manager manager)
{
var serialized = JsonConvert.SerializeObject(payment);
var content = new StringContent(serialized, Encoding.UTF8, "application/json");
string request = "clients/{0}/fiscalYears/{1}/payables/manualpayments";
string url = string.Format(request, manager.getCurrentClient().id, manager.getCurrentFiscalYear().id);
var response = manager.httpClient.PostAsync(url, content).Result;
if (response.StatusCode != HttpStatusCode.OK)
{
ResponseDetails details = new ResponseDetails();
string message = details.responseDetails(response);
}
return response.IsSuccessStatusCode;
}
}
UNDER CONSTRUCTION
POST Request:
{
"id": "00000000-0000-0000-0000-000000000000",
"accountFID": 10,
"partyFID": 33,
"personRoleFID": 0,
"text": "Payment partial",
"paymentTransactionTypeFID": 1,
"amount": 0.0,
"amountFC": 0.0,
"paymentRate": 0.0,
"paymentNum": 0,
"accountCode": null,
"accountName": null,
"currencyCode": null,
"currencyFID": -1,
"partyNum": 0,
"partyName": null,
"partyShortName": null,
"freePartyNum": null,
"invoiceCount": 0,
"paymentDetails": [
{
"invoiceFID": "0aa43fd7-355a-4eda-8ec4-da57ad83cce9",
"text": "paymentdetails text",
"payAmount": 1111.0,
"payAmountFC": 1111.0,
"discount": 0.0,
"witeOff": 0.0,
"paymentRate": 0.0
}
],
"transaction": {
"id": "00000000-0000-0000-0000-000000000000",
"fiscalYearFID": -1,
"userFID": -1,
"transactionTypeFID": 4,
"docType": null,
"docNum": -1,
"docDate": "2022-05-16T00:00:00",
"modifyDate": "0001-01-01T00:00:00",
"isConfirmed": true,
"numRangeFID": -1,
"hasDocument": false,
"postings": []
}
}