Code Monkey home page Code Monkey logo

balikobot-php's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

balikobot-php's Issues

GLS sometimes returns bad response with HTTP code of 200

From time to time, GLS sends valid HTTP 200 code response with just content of '503' - service not available. Which is correctly decoded by json_decode, but the result is not an array, thus fails to be passed onto next functions:

[25-Jun-2020 18:21:38 Europe/Prague] PHP Fatal error: Uncaught TypeError: Argument 1 passed to Inspirum\Balikobot\Model\Values\PackageStatus::newInstanceFromData() must be of the type array, string given, called in /www/sites/7/site70717/public_html/vendor/inspirum/balikobot/src/Services/Balikobot.php on line 170 and defined in /www/sites/7/site70717/public_html/vendor/inspirum/balikobot/src/Model/Values/PackageStatus.php:68
Stack trace:
#0 /www/sites/7/site70717/public_html/vendor/inspirum/balikobot/src/Services/Balikobot.php(170): Inspirum\Balikobot\Model\Values\PackageStatus::newInstanceFromData('503')
#1 /www/sites/7/site70717/public_html/vendor/inspirum/balikobot/src/Services/Balikobot.php(146): Inspirum\Balikobot\Services\Balikobot->trackPackages(Object(Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection))
#2 /www/sites/7/site70717/public_html/cron/balikobotCheckStatus.php(40): Inspirum\Balikobot\Services\Balikobot->trackPackage(Object(Inspirum\Balikobot\Model\Values\OrderedPackage))
#3 {main}
thrown in /www/sites/7/site70717/public_html/vendor/inspirum/balikobot/src/Model/Values/PackageStatus.php on line 68

Possible implementation

Definitely should be fixed on the side of GLS. Will report this issue to them as well. Also reporting here just for information. Could be possibly fixed in library as well

TRACK method (v2) response validation bug

Detailed description

While trying to get a response in "trackPackage" method in "Client" class, an error is returned, even though there is a valid data returned. It is caused by statusCode set to 500.

Context

Fixes the bug. Allows users to retrieve relevant data.

Possible implementation

There is supposed to be $shouldHaveStatus variable in validateResponseStatus method set to false as there is not this index set in the response.
Just set shouldHaveStatus parameter in the trackPackage method to false - this solves the problem.

Your environment

Not necessary

trackPackages throws TypeError

method trackPackages throws TypeError

Provide a detailed description of the change or addition you are proposing.

Probably a bug

Context

To make it work

How can it benefit other users?

It will work for them

Not obligatory, but suggest an idea for implementing addition or change.

cheheck if $status variable in trackPackages' method's loop is array

PHP7.4
inspirum/balikobot composer version 3.3.0

Sometimes when trackPackages() method is called, we got this error:

Argument 1 passed to Inspirum\Balikobot\Model\Values\PackageStatus::newInstanceFromData() must be of the type array, string given

I am unable to replicate this error in testing environment, but live, the error sometimes appear for us.

GLS trackPackages return empty statuses

Detailed description

When tracking GLS packages, statuses returned by trackPackages() are always empty.

Possible implementation

the issue is due to this part of code:

    if (empty($response[0])) {
        throw new BadRequestException($response);
    }

$response[0] can be empty and thus will throw an exception, crude (don't now if good) solution is to check $response[1] being set:

    if (empty($response[0])) {
		if(empty($response[1])) {
			throw new BadRequestException($response);
		}

		$response[0] = $response[1];
    }

The method resolveBranchId() generates wrong branchId for PPL

In some cases PPL branch ids contain the string 'KM' multiple times, wich than generates a faulty branchId property.

e.g. KMSKMK000000000 -> SK000000000

I'm not sure why the leading 'KM' has to be removed but with the current str_replace method it's not sufficient for this purpose.
A more specific way would be to do it with preg_match().

Client::getAddServiceOptions without service doesnt return any data

Detailed description

\Inspirum\Balikobot\Services\Client::getAddServiceOptions called without service returns empty array.

Without serviceType the api returns options nested for all services under service_types key:

{
    "status": 200,
    "service_types": [
        {
            "service_type": "F",
            "service_type_name": "Fofr",
            "services": [
                {
                    "code": 1,
                    "name": "křehké"
                },
                {
                    "code": 2,
                    "name": "neklopit"
                },
                {
                    "code": 3,
                    "name": "deštník"
                },
                {
                    "code": 4,
                    "name": "SMS před svozem"
                },
                {
                    "code": 5,
                    "name": "SMS před doručením"
                }
            ]
        }
    ]
}

...

Your environment

inspirum/balikobot: v5.4.0

Balikobot::trackPackage chybně detekuje 404 české pošty jako Nedoručený balík

Tracking api Balíkobotu vrací v určitých případech české pošty zvláštní odpověď, kde je namísto pole eventů, pouze pole se stringem 404 .

{
	"packages": [
		{
			"carrier_id": "NBxxxxxxxxxxxxxx",
			"status": 200,
			"states": ["404"]
		}
	]
}	

Z Balíkobotu máme vyjádření, že pouze přeposílají data z České Pošty a tudíž se tomu nebudou věnovat.

Na základě této chyby, knihovna špatně detekuje stav 4 - Nedoručený balík.

image

Toto se dá jednoduše hacknout na straně použití knihovny přibližně takto:

$statuses = $this->balikobot->trackPackage($orderedPackage);

// Hack / fix 404 Czech Post in Inspirum library
if (
	$package->getShipper()->isCeskaPosta()
	&& count($statuses) === 1
	&& $statuses[0]->getId() === 4.0
	&& $statuses[0]->getName() === '4'
	&& $statuses[0]->getDescription() === '4'
	&& $statuses[0]->getDate() === null
) {
	$statuses = [];
}

Nicméně bylo by moc fajn, kdyby toto uměla řešit přímo knihovna.

Díky za váš čas, pokud se tomu budete věnovat.

$packageService usage

Could you please provide an example of full instantiation of $packageService ? I am trying to migrate from 5.7. to 7.6. and am unable to figure out how to use it.

Many thanks

Branches not in Shipper::hasBranchCountryFilterSupport are not filtered by country on api level

Detailed description

Balikobot branches allows filtering results by either country or service for shippers not in \Inspirum\Balikobot\Definitions\Shipper::hasBranchCountryFilterSupport. (https://balikobotv2.docs.apiary.io/#reference/branches) but \Inspirum\Balikobot\Services\Balikobot::getAllBranchesForShipperServiceForCountries filters only by service:

https://github.com/inspirum/balikobot-php/blob/v5.3.0/src/Services/Balikobot.php#L467

Context

This is a problem especially for Zasilkovna with $service set as null, because the countries are filtered later and it requires excessive amount of memory.

Calling $shipper/branches/country/$country would greatly reduce the response size and allowed to remove filtering by countries later.

Possible implementation

\Inspirum\Balikobot\Definitions\Shipper::hasBranchCountryFilterSupport should only be checked in case both $service and $country is set. Or the check can be dropped completely in favor of api exception in response.

Your environment

inspirum/balikobot: v5.3.0

Zásilkovna při dobírce vrací Nepovolený ISO kód měny dobírky

Zdravím,

vyvíjím integraci Balíkobotu pomocí vaší knihovny a při kombinaci dopravce Zásilkovna a služby dobírka se vrací:

Operace neproběhla v pořádku, zkontrolujte konkrétní data.
[0][cod_currency]: Nepovolený ISO kód měny dobírky. (500 Internal Server Error)

Exception
Inspirum\Balikobot\Exceptions
BadRequestException
in vendor/inspirum/balikobot/src/Services/Validator.php (line 27)
throw new BadRequestException($response, (int) ($response['status'] ?? $statusCode));

Přitom data, co se týká ISO kódu měny dobírky by měla být podle mě v pořádku.

object(Inspirum\Balikobot\Model\Values\Package)#3537 (1) {
  ["data":"Inspirum\Balikobot\Model\Values\AbstractPackage":private]=>
  array(10) {
    ["eid"]=>
    string(18) "123456789111222333"
    ["service_type"]=>
    string(4) "VMCZ"
    ["rec_name"]=>
    string(11) "Lorem Ipsum"
    ["rec_phone"]=>
    string(13) "+420731123555"
    ["branch_id"]=>
    string(4) "1442"
    ["price"]=>
    float(2010)
    ["cod_price"]=>
    float(2010)
    ["vs"]=>
    string(18) "123456789111222333"
    ["cod_currency"]=>
    string(3) "CZK"
    ["return_full_errors"]=>
    int(1)
  }
}

Pokud dám Zásilkovnu bez dobírky nebo DPD s dobírkou, tak to prochází v pořádku, protože používám kontanty

Inspirum\Balikobot\Definitions\Currency\Currency::CZK a Inspirum\Balikobot\Definitions\Currency\Currency::EUR

Můžete se na to, prosím, podívat?

Díky.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.