shusaura85 / fancourier-api

PHP library to work with the new Fan Courier API v2.0 (selfawb.ro / api.fancourier.ro)
MIT License
21 stars 9 forks source link

Creating a new AWB without a declared value (or with value = 0) returns empty data['tarrif'] - no cost info on the AWB. #8

Closed iepuzaur closed 6 months ago

iepuzaur commented 6 months ago

When creating an AWB, according to docs (official and library) setting a shipping declared value (setDeclaredValue) is optional. However when the declared values is set and is not 0, the response returns valid data['tarrif'] (the cost of the shipment). If declared value is not set or is set to 0, data['tarrif'] returns 0. On V1 of the API this was working correctly, it looks rather related to API.

shusaura85 commented 6 months ago

Looks like it's a bug in the API. I did a few tests with differently formatted requests (including not sending the declaredValue field).
It always returns tarrif = 0 if the declared value is 0. If the declared value is at least 0.1, it returns valid tarrif value.

I will leave this issue open for now and will try to contact them about the problem.

shusaura85 commented 6 months ago

Looks like the problem only manifests when the requests are done as x-www-form-urlencoded.
There is a bug in the client that sends the requests that caused JSON requests to fail (why I used x-www-form-urlencoded).

I am working on the bug right now and will have an update by the end of the day.

iepuzaur commented 6 months ago

After checking with updated version 2.0.4 it still does not return a valid data['tarrif'] on all the requests. Example: service 'Standard' and no option sent (i.e. epod or Saturday delivery) or empty option value. This returns tarrif 0.

shusaura85 commented 6 months ago

Apparently the way they made it makes the response dependent on the account and options. Apparently, it can return 0 if it's a contract based account and the payment type is sender.

I recommend always setting a declared value, even if it's set to 0.1 as that way it should always return a valid tariff value.

iepuzaur commented 6 months ago

This is weird (at least), as such issue had no occurence on the previous version of the API (which returns the cost correctly creating the AWB - same account / options). Setting a declared value of 0.1 reflects also on the printed AWB, which is not an option. A workaround would have been to use the GetCosts option as backup, but the return values look different than data['tarrif'].