Wiki

Clone wiki

fps-applet / RESTFul

Interface RESTFul dla drukowania paragonów

Zasady komunikacji z chmurą Google

End point

Usługi dostępne są pod adresem: https://natanedwin.appspot.com/api

Poszczególne usługi wywołujemy dodając kolejne elementy do URLa. Dla przykładu aby wywołać pobranie paragonu dodajemy /fps/getDocument?documentId=ID_PARAGONU.

Jako zabezpieczenie korzystania z usług wprowadzono tzw. API-Key. Ma on postać nagłówka w request HTTP. Każdy request do API musi zawierać API key, żeby wywołanie odniosło skutek. Demonstracyjne API-Key ma wartość: c6406622-4dab-47d8-9034-cdc7e69ada51. Przykład prawidłowego wywołania (usługa ping zwraca zawsze odpowiedź tekstową pong za którą podąża API-Key i nazwa podmiotu gospodarczego):

#!bash

$ curl -v --header "API-Key: c6406622-4dab-47d8-9034-cdc7e69ada51" https://natanedwin.appspot.com/api/ping
* Adding handle: conn: 0x2372d80
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x2372d80) send_pipe: 1, recv_pipe: 0
* About to connect() to natanedwin.appspot.com port 443 (#0)
*   Trying 2a00:1450:4010:c04::8d...
* Connected to natanedwin.appspot.com (2a00:1450:4010:c04::8d) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: C:\Program Files (x86)\Git\bin\curl-ca-bundle.crt
  CApath: none
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using RC4-SHA
* Server certificate:
*        subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=*.appsp
ot.com
*        start date: 2014-09-24 10:35:53 GMT
*        expire date: 2014-12-23 00:00:00 GMT
*        subjectAltName: natanedwin.appspot.com matched
*        issuer: C=US; O=Google Inc; CN=Google Internet Authority G2
*        SSL certificate verify ok.
> GET /api/ping HTTP/1.1
> User-Agent: curl/7.30.0
> Host: natanedwin.appspot.com
> Accept: */*
> API-Key: c6406622-4dab-47d8-9034-cdc7e69ada51
>
< HTTP/1.1 200 OK
< Content-Type: text/plain; charset=iso-8859-1
< Vary: Accept-Encoding
< Date: Mon, 13 Oct 2014 19:58:55 GMT
* Server Google Frontend is not blacklisted
< Server: Google Frontend
< Cache-Control: private
< Alternate-Protocol: 443:quic,p=0.01
< Transfer-Encoding: chunked
<
pong
API-Key = c6406622-4dab-47d8-9034-cdc7e69ada51
Licencjobiorca: Podmiot Demo
* Connection #0 to host natanedwin.appspot.com left intact

W przypadku braku API-Key lub nieprawidłowego, otrzymamy bład z serii 4xx.

Interface document - paragon

Interface umożliwia:

  • zapisanie paragonu - HTTP POST.
  • odczytanie paragonu - HTTP GET - applet, ale i również dowolna APLIKACJA znając identyfikator paragonu odczytuje go z systemu.

Odczyt paragonbu

Używając API Key i unikalnego numeru dokumentu fiskalnego można go pobrać poprzez użycie HTTP GET:

#!bash

$ curl -v --header "API-Key: c6406622-4dab-47d8-9034-cdc7e69ada51" https://natanedwin.appspot.com/api/fps/getDocument?documentId=1436e481-d51b-46c8-9842-75d5fceec16d
* Adding handle: conn: 0x2393218
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x2393218) send_pipe: 1, recv_pipe: 0
* About to connect() to natanedwin.appspot.com port 443 (#0)
*   Trying 2a00:1450:4010:c04::8d...
* Connected to natanedwin.appspot.com (2a00:1450:4010:c04::8d) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: C:\Program Files (x86)\Git\bin\curl-ca-bundle.crt
  CApath: none
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using RC4-SHA
* Server certificate:
*        subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=*.appsp
ot.com
*        start date: 2014-09-24 10:35:53 GMT
*        expire date: 2014-12-23 00:00:00 GMT
*        subjectAltName: natanedwin.appspot.com matched
*        issuer: C=US; O=Google Inc; CN=Google Internet Authority G2
*        SSL certificate verify ok.
> GET /api/fps/getDocument?documentId=1436e481-d51b-46c8-9842-75d5fceec16d HTTP/
1.1
> User-Agent: curl/7.30.0
> Host: natanedwin.appspot.com
> Accept: */*
> API-Key: c6406622-4dab-47d8-9034-cdc7e69ada51
>
< HTTP/1.1 200 OK
< Content-Type: application/json;charset=utf-8
< Vary: Accept-Encoding
< Date: Mon, 13 Oct 2014 20:52:42 GMT
* Server Google Frontend is not blacklisted
< Server: Google Frontend
< Cache-Control: private
< Alternate-Protocol: 443:quic,p=0.01
< Transfer-Encoding: chunked
<
{
  "cashbox": "BP01",
  "cashierName": "Bartek Prokop",
  "created": "1361347346084",
  "errorNote": "Nowy",
  "printingState": "Created",
  "reference": "R-k 173046",
  "slipLines": [
    {
      "name": "Nazwa towaru",
      "amount": "1.00",
      "price": "1.00",
      "taxRate": "VAT23",
      "discountType": "NoDiscount",
      "discount": 0
    }
  ],
  "slipPayments": [{
    "amount": "1.00",
    "name": "Karnet 653214",
    "type": "Voucher"
  }]
}
* Connection #0 to host natanedwin.appspot.com left intact

Ten sam paragon można wydrukować, wywołując następujacy URL: https://natanedwin.appspot.com/fps/fps.jsp?api-key=c6406622-4dab-47d8-9034-cdc7e69ada51&documentId=1436e481-d51b-46c8-9842-75d5fceec16d

Przykładowy wydruk paragonu

Zapis paragonu

Zapis paragonu do wydruku polega na wywołaniu HTTP POST na adres 'https://natanedwin.appspot.com/api/fps/postDocument'. Request Body powinien być w postaci struktury JSON. Obowiązkowo należy w nagłówku podać API-Key. Przykładowe dokumenty JSON znajdują się w katalogu tests. Przykładowe interakcja z serwerem wygląda następująco, jak widac serwer odpowiada odsyłajac unikalny id właśnie zapisanego dokumentu:

#!bash

$ curl --header "API-Key: c6406622-4dab-47d8-9034-cdc7e69ada51" --header "Conte
nt-Type: application/json" -d '{"reference":"R-k 0123456789","slipPayments":[{"
amount":31,"type":"Cash"}],"slipLines":[{"taxRate":"VAT23","amount":1,"price":3
1,"name":"\257etony","discount":0,"discountType":"NoDiscount"}],"created":14010
81101655,"errorNote":"Nowy","cashbox":"XX99","printingState":"Created","cashier
Name":"Test Testowy"}' https://natanedwin.appspot.com/api/fps/postDocument
6dde6216-86f8-4c78-89ee-da92acb44739

Próba odczytania dopiero co zapisanego dokumentu:

#!bash

$ curl -v --header "API-Key: c6406622-4dab-47d8-9034-cdc7e69ada51" https://natanedwin.appspot.com/api/fps/getDocument?documentId=6dde6216-86f8-4c78-89ee-da92acb44739
{"reference":"R-k 0123456789","slipPayments":[{"amount":31,"type":"Cash"}],"slip
Lines":[{"taxRate":"VAT23","amount":1,"price":31,"name":"\257etony","discount":0
,"discountType":"NoDiscount"}],"created":1401081101655,"errorNote":"Nowy","cashb
ox":"XX99","printingState":"Created","cashierName":"Test Testowy"}

Updated