fiskaly / fiskaly-sdk-swift

fiskaly Cloud-TSE SDK for Swift/iOS
MIT License
5 stars 5 forks source link

DSVIN-K FiskalyHttpClient throws NSError #30

Closed ghost closed 3 years ago

ghost commented 3 years ago

I wanted to send over the FiskalyHttpClient a cash_point_closing to https://dsfinvk.fiskaly.com/api/v0/ but I get an NSError with the Error-Code: Domain Nil - Code: 0

LocalizedString: Der Vorgang konnte nicht abgeschlossen werden. (FiskalySDK.JsonRpcError-Fehler 1.)

My Code:

`let transactionUUID = UUID().uuidString

    let path = "cash_point_closings/\(transactionUUID)"

    do {

              let transactionBodyData = try? JSONSerialization.data(withJSONObject: body)
              let transactionBodyEncoded = transactionBodyData?.base64EncodedString()
        let newClient = try FiskalyHttpClient(apiKey: self.username, apiSecret: self.password, baseUrl: "https://dsfinvk.fiskaly.com/api/v0/")
        let responseCreateTransaction = try newClient.request(
            method: "PUT",
                  path: path,
                body: transactionBodyEncoded!)
              let decodedData = Data(base64Encoded: responseCreateTransaction.body)!
              let decodedString = String(data: decodedData, encoding: .utf8)!
              return ["response": decodedString,"error":false,"t_id": transactionUUID]

    } catch let error {
        let err = error
       // let decodedData = Data(base64Encoded: err.body)!
            //let decodedString = String(data: decodedData, encoding: .utf8)!
        return ["error":true,"error_msg": err.localizedDescription]
          }`

Is there anything wrong?

prempador commented 3 years ago

Thanks for the heads-up. We are aware of an issue with the DSFinV-K API, but I am not 100% sure if this is the same error you are experiencing. I will try to dig a bit deeper. Is there any additional information of the error, like a code, complete message or something else?

ghost commented 3 years ago

Hi,

I tried it with Postmen and got following error: { "status_code": 500, "error": "Internal Server Error", "code": "22009", "message": "Internal Server Error" }

I guess that's the same Error. I can't get any additional Error because Swift always convert it to an Error without any Informations. It is better if you creating an ErrorClass with additional Information and better Error Handling. I get always the Same Error Message in the error.LocalizedString = "FiskalySDK.JsonRpcError-Fehler 1". Before, I got always the base64 error code but now nothing.

prempador commented 3 years ago

I just checked the logs, and there seems to be a problem with one of the timestamps you are sending. Could you provide the body you are trying to send to the endpoint?

ghost commented 3 years ago

I am using the same Timestamps because we dont track the time when an order has ended and when a receipe was made.

We just track the creation timestamp of the receipt and orders so thats why i am using the same timestamps.

But is there any way to get that informations with the FiskalySDK like you get?

{ "cash_point_closing_export_id":0,"head":{"export_creation_date":1599780749751,"first_transaction_export_id":"25199147-AAA8-429D-BDFA-24AD7006103B","last_transaction_export_id":"53ECB56A-86A3-4811-B4A6-8B3C1FF3E285"},"cash_statement":{"business_cases":[{"type":"MehrzweckgutscheinKauf","amounts_per_vat_id":[{"vat_definition_export_id":7,"incl_vat":0.0,"excl_vat":50.0,"vat":0.0}]},{"type":"Anfangsbestand","amounts_per_vat_id":[{"vat_definition_export_id":7,"incl_vat":50.0,"excl_vat":50.0,"vat":0.0}]}],"payment":{"full_amount":59.5,"cash_amount":59.5,"cash_amounts_by_currency":[{"currency_code":"EUR","amount":59.5}],"payment_types":[{"type":"Bar","currency_code":"EUR","amount":50.0}]}},"client_id":"d3b1b3c7-3cda-4fc1-b817-b5b02e0e4f2b","transactions":[{"head":{"tx_id":"25199147-AAA8-429D-BDFA-24AD7006103B","transaction_export_id":"123","closing_client_id":"d3b1b3c7-3cda-4fc1-b817-b5b02e0e4f2b","type":"AVSonstige","storno":false,"number":979,"buyer":{"name":"Kunde","buyer_export_id":"1","type":"Kunde"},"timestamp_start":1599780700424,"timestamp_end":1599780700424,"name":"null","user":{"user_export_id":"null","name":"null"},"references":[{"type":"InterneTransaktion","tx_id":"25199147-AAA8-429D-BDFA-24AD7006103B"}]},"data":{"full_amount_incl_vat":50.0,"amounts_per_vat_id":[{"vat_definition_export_id":7,"incl_vat":0.0,"excl_vat":50.0,"vat":0.0}],"payment_types":[{"type":"Bar","currency_code":"EUR","amount":50.0}],"lines":[]},"security":{"tss_tx_id":"b586b06b-5af0-4ff7-8fdc-c1e598711460"}},{"head":{"tx_id":"DD8F283E-9E80-47E9-AE75-F278F52183EE","transaction_export_id":"3fEgmBnbxItSP44ApaPx","closing_client_id":"d3b1b3c7-3cda-4fc1-b817-b5b02e0e4f2b","type":"AVBestellung","storno":true,"number":0,"buyer":{"name":"Kunde","buyer_export_id":"1","type":"Kunde"},"timestamp_start":1599780716164,"timestamp_end":1599780716164,"name":"Bruch: Cola","user":{"user_export_id":"wxna5ZhjNzAOTLl6R4jZ","name":"null"},"references":[{"type":"InterneTransaktion","tx_id":"DD8F283E-9E80-47E9-AE75-F278F52183EE"}]},"data":{"full_amount_incl_vat":5.0,"notes":"Bruch des Produkts (Siehe Items)","amounts_per_vat_id":[{"vat_definition_export_id":6,"incl_vat":0.0,"excl_vat":0.0,"vat":0.0}],"payment_types":[{"type":"Keine","currency_code":"EUR","amount":5.0}],"lines":[{"business_case":{"type":"Umsatz","amounts_per_vat_id":[{"vat_definition_export_id":6,"incl_vat":0.0,"excl_vat":0.0,"vat":0.0}]},"lineitem_export_id":"123","storno":true,"text":"Cola","inhaus":true,"item":{"number":"3fEgmBnbxItSP44ApaPx","quantity":1.0,"price_per_unit":5.0}}]},"security":{"tss_tx_id":"b586b06b-5af0-4ff7-8fdc-c1e598711460"}},{"head":{"tx_id":"53ECB56A-86A3-4811-B4A6-8B3C1FF3E285","transaction_export_id":"0QACQGEqLc6kb7nfzrnK","closing_client_id":"d3b1b3c7-3cda-4fc1-b817-b5b02e0e4f2b","type":"AVBestellung","storno":false,"number":980,"buyer":{"name":"Kunde","buyer_export_id":"1","type":"Kunde"},"timestamp_start":1599780729289,"timestamp_end":1599780729289,"name":"Love 66","user":{"user_export_id":"wxna5ZhjNzAOTLl6R4jZ","name":"null"},"references":[{"type":"InterneTransaktion","tx_id":"53ECB56A-86A3-4811-B4A6-8B3C1FF3E285"}]},"data":{"full_amount_incl_vat":10.0,"amounts_per_vat_id":[{"vat_definition_export_id":1,"incl_vat":10.0,"excl_vat":8.62,"vat":1.38}],"payment_types":[{"type":"Bar","currency_code":"EUR","amount":10.0}],"lines":[{"business_case":{"type":"Umsatz","amounts_per_vat_id":[{"vat_definition_export_id":1,"incl_vat":10.0,"excl_vat":8.62,"vat":1.38}]},"lineitem_export_id":"123","storno":false,"text":"Love 66","inhaus":true,"item":{"number":"0QACQGEqLc6kb7nfzrnK","quantity":1.0,"price_per_unit":10.0}}]},"security":{"tss_tx_id":"b586b06b-5af0-4ff7-8fdc-c1e598711460"}}] }

prempador commented 3 years ago

So, your timestamps are Unixtime with milliseconds. This is why the backend is having issues, because converting it results in 01/12/52665 @ 7:53am (UTC).

There is currently no way to get the information I am getting, but we will work on better error messages as we go. DSFinV-K is still in Version 0 and there is a lot of potential.

ghost commented 3 years ago

I will try to fix it and i‘ll coming back to you again, thanks for the support for here!

ghost commented 3 years ago

Worked smooth thanks!