verbb / postie

A Craft Commerce shipping calculator plugin.
Other
12 stars 18 forks source link

Australia post API gives API error: “Undefined index: code” after the fix for internatioanl rates #80

Closed azad6026 closed 2 years ago

azad6026 commented 2 years ago

Description Hi devs and thanks for considering this.

After updating my site to the latest version of Postie , Craft and Craft commerce , the delivery is not working anymore. Upon logs I can see it is the change that was made on this commit based on the logs:


$_POST = []
2021-12-10 16:08:42 [-][1][-][info][postie] Australia Post: Domestic API call
2021-12-10 16:08:42 [-][1][-][info][postie] Australia Post: Sending payload: `{"from_postcode":"3121","to_postcode":"3000","length":23,"width":15.5,"height":1.5,"weight":0.4}`.
2021-12-10 16:08:42 [-][1][-][error][postie] Australia Post: API error: “Undefined index: code” /......./vendor/verbb/postie/src/providers/AustraliaPost.php:362
2021-12-10 16:08:41 [-][1][-][info][application] $_GET = [
    'p' => 'shop/checkout/shipping'
    'action' => 'commerce/cart/get-cart'
]

Here are the two lines that the change was committed three days ago:

        ---> deleted    if (isset($response['services']['service'])) {
        ---> deleted          foreach ($response['services']['service'] as $service) {
        ---> added    if (isset($response['services'])) {
        ---> added        foreach ($response['services'] as $service) {

-- | --

I modified the file in the vendor folder and changed it back and all is fine now, but that is not ideal .So if you can have a look and release a fix it will be great as I need it for the live site.

Additional info

Additional context

engram-design commented 2 years ago

Looks like you're right. It seems like for some destinations the data returned is actually different, which was the reason for fixing the error in the first place, as some destination countries weren't returning rates.

Incredibly, AusPost seems to change the result from its API is only a single service was returned, which I'm surprised they do, as it's just inconsistent responses from their system.

Anyway, sorry for the issue, should be properly fixed in 2.4.14

azad6026 commented 2 years ago

Thank you for clarifying. Appreciate it.Is it possible to have an early dev version for the fix that I can update via composer?

engram-design commented 2 years ago

You can update to the latest version 2.4.14 via composer?

azad6026 commented 2 years ago

Yes I can. Thanks will try it out tonight.