1 package com.srv4pos.server.api.receiptSettings;
2
3 import com.srv4pos.server.api.infrastructure.EmptyConnectionWriter;
4 import com.srv4pos.server.api.infrastructure.HttpMethod;
5 import com.srv4pos.server.api.infrastructure.StringConnectionWriter;
6 import com.srv4pos.server.api.infrastructure.credentials.Credentials;
7 import com.srv4pos.server.api.infrastructure.http.HttpHelper;
8 import com.srv4pos.server.api.infrastructure.http.Transport;
9 import com.srv4pos.server.api.infrastructure.request.StringResponse;
10
11 import java.net.URL;
12
13 import static com.srv4pos.server.api.infrastructure.request.RequestHelper.requestString;
14 import static com.srv4pos.server.api.infrastructure.request.RequestHelper.requestVoid;
15 import static java.lang.String.format;
16
17
18
19
20
21 public class ReceiptSettingsService {
22 private URL url;
23 private Credentials credentials;
24 private Transport transport;
25
26
27
28
29
30
31
32
33 public ReceiptSettingsService(URL url, Credentials credentials, Transport transport) {
34 this.url = url;
35 this.credentials = credentials;
36 this.transport = transport;
37 }
38
39
40
41
42
43
44
45
46
47
48
49
50 public ReceiptSettingsInfo get(Integer version) {
51 StringResponse response = requestString(
52 format("%s/receipt-settings", credentials.getSellerId()),
53 HttpMethod.GET,
54 url,
55 credentials.toAuthentication(),
56 HttpHelper.integerToETag(version),
57 null,
58 EmptyConnectionWriter.EMPTY_CONNECTION_WRITER,
59 HttpHelper.CONTENT_TYPE_APPLICATION_JSON,
60 transport
61 );
62 return response == null ? null : ReceiptSettingsInfo.fromJsonToReceiptSettingsInfo(response.getContent());
63 }
64
65
66
67
68
69
70
71
72
73 public void update(int version, ReceiptSettingsInfo receiptSettingsInfo) {
74 requestVoid(
75 format("%s/receipt-settings", credentials.getSellerId()),
76 HttpMethod.POST,
77 url,
78 credentials.toAuthentication(),
79 HttpHelper.integerToETag(version),
80 null,
81 new StringConnectionWriter(receiptSettingsInfo.toJson()),
82 HttpHelper.CONTENT_TYPE_APPLICATION_JSON,
83 transport);
84 }
85 }