Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
93 lines (86 loc) · 2.96 KB
/
Copy pathProgram.cs
File metadata and controls
93 lines (86 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
//POST call
string cashRegisterCode = "88812345678900001";
string registerReceiptUrl = "http://localhost:63329/oec/api/receipt/" + cashRegisterCode;
string receiptJson = GetReceipt();
HttpClient client = new HttpClient();
var httpResponse = client.PostAsync(registerReceiptUrl, new StringContent(receiptJson, Encoding.UTF8, "application/json")).Result;
var response = Encoding.UTF8.GetString(httpResponse.Content.ReadAsByteArrayAsync().Result);
dynamic obj = JsonConvert.DeserializeObject<dynamic>(response);
//GET call
string configUrl = "http://localhost:63329/oec/api/cashregisterconfig/" + cashRegisterCode;
HttpClient getClient = new HttpClient();
httpResponse = getClient.GetAsync(configUrl).Result;
var configResponse = Encoding.UTF8.GetString(httpResponse.Content.ReadAsByteArrayAsync().Result);
//GET call with body (Receipt copy)
DateTime dateTime = obj.Receipt.CreateDate;
int receiptNumber = obj.Receipt.ReceiptNumber;
string printCopyUrl = "http://localhost:63329/oec/api/receipt/" + cashRegisterCode + "/" + dateTime.ToString("yyyy-MM-dd'T'HH:mm:ss") + "/" + receiptNumber.ToString();
HttpClient getClient2 = new HttpClient(new WinHttpHandler()); //NuGet: System.Net.Http.WinHttpHandler, .NET 4.6 >=
var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri(printCopyUrl),
Content = new StringContent("", Encoding.UTF8, "application/json"),
};
var copyResponse = getClient2.SendAsync(request).Result;
}
private static string GetReceipt()
{
return
@"{
""Receipt"": {
""IssueDate"": ""2019-04-01"",
""CreateDate"": ""2019-04-01"",
""ReceiptNumber"": 0,
""Amount"": 3.98,
""InvoiceNumber"": null,
""Paragon"": false,
""ParagonNumber"": null,
""CashRegisterCode"": ""88812345678900001"",
""TaxBaseBasic"": 2.08,
""TaxBaseReduced"": 1.35,
""TaxFreeAmount"": 0,
""BasicVatAmount"": 0.41,
""ReducedVatAmount"": 0.14,
""ReceiptType"": ""PD"",
""Items"": [
{
""Price"": 2.49,
""Quantity"": 1.0,
""MeasurementUnit"": ""ks"",
""Name"": ""Item"",
""VatRate"": 20.0,
""ItemType"": ""K"",
},
{
""Price"": 1.49,
""Quantity"": 1.0,
""MeasurementUnit"": ""ks"",
""Name"": ""Item 2"",
""VatRate"": 10.0,
""ItemType"": ""K"",
}
],
""Payments"": null,
""Cashier"": null
},
""ReceiptRenderer"": null,
""PrintTemplate"": null
}
";
}
}
}