postmen / postmen-sdk-php

AfterShip Shipping (Postmen) API Client Library for PHP (USPS, FedEx, UPS, DHL and more)
https://www.aftership.com/postmen
10 stars 11 forks source link

Curl Response Header Keys #21

Open JordanDalton opened 5 years ago

JordanDalton commented 5 years ago

During testing today I ran into "Undefined index: Date"

Here's the stack trace:

ErrorException thrown with message "Undefined index: Date"

Stacktrace:
#67 ErrorException in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/postmen/sdk-php/src/Postmen/Postmen.php:133
#66 Illuminate\Foundation\Bootstrap\HandleExceptions:handleError in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/postmen/sdk-php/src/Postmen/Postmen.php:133
#65 Postmen\Postmen:call in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/postmen/sdk-php/src/Postmen/Postmen.php:284
#64 Postmen\Postmen:callPOST in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/postmen/sdk-php/src/Postmen/Postmen.php:309
#63 Postmen\Postmen:create in /Volumes/My Passport for Mac/Code/pharmacy-software/app/Services/Shipping/Label.php:15
#62 App\Services\Shipping\Label:create in /Volumes/My Passport for Mac/Code/pharmacy-software/app/Shipment.php:46
#61 App\Shipment:generateShippingLabel in /Volumes/My Passport for Mac/Code/pharmacy-software/routes/shipping_technicians.php:27
#60 Illuminate\Routing\Router:{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Route.php:198
#59 Illuminate\Routing\Route:runCallable in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Route.php:172
#58 Illuminate\Routing\Route:run in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Router.php:682
#57 Illuminate\Routing\Router:Illuminate\Routing\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
#56 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/app/Http/Middleware/ShippingTechnician.php:22
#55 App\Http\Middleware\ShippingTechnician:handle in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#54 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#53 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/spatie/laravel-permission/src/Middlewares/RoleMiddleware.php:25
#52 Spatie\Permission\Middlewares\RoleMiddleware:handle in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#51 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#50 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/app/Http/Middleware/CheckIfBanned.php:37
#49 App\Http\Middleware\CheckIfBanned:handle in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#48 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#47 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:41
#46 Illuminate\Routing\Middleware\SubstituteBindings:handle in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#45 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#44 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php:43
#43 Illuminate\Auth\Middleware\Authenticate:handle in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#42 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#41 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:75
#40 Illuminate\Foundation\Http\Middleware\VerifyCsrfToken:handle in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#39 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#38 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49
#37 Illuminate\View\Middleware\ShareErrorsFromSession:handle in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#36 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#35 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:63
#34 Illuminate\Session\Middleware\StartSession:handle in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#33 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#32 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37
#31 Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse:handle in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#30 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#29 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:66
#28 Illuminate\Cookie\Middleware\EncryptCookies:handle in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#27 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#26 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:104
#25 Illuminate\Pipeline\Pipeline:then in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Router.php:684
#24 Illuminate\Routing\Router:runRouteWithinStack in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Router.php:659
#23 Illuminate\Routing\Router:runRoute in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Router.php:625
#22 Illuminate\Routing\Router:dispatchToRoute in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Router.php:614
#21 Illuminate\Routing\Router:dispatch in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:176
#20 Illuminate\Foundation\Http\Kernel:Illuminate\Foundation\Http\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
#19 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/fideloper/proxy/src/TrustProxies.php:57
#18 Fideloper\Proxy\TrustProxies:handle in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#17 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#16 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:31
#15 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#14 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#13 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:31
#12 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#11 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#10 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27
#9 Illuminate\Foundation\Http\Middleware\ValidatePostSize:handle in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#8 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#7 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:62
#6 Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode:handle in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#5 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#4 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:104
#3 Illuminate\Pipeline\Pipeline:then in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:151
#2 Illuminate\Foundation\Http\Kernel:sendRequestThroughRouter in /Volumes/My Passport for Mac/Code/pharmacy-software/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:116
#1 Illuminate\Foundation\Http\Kernel:handle in /Volumes/My Passport for Mac/Code/pharmacy-software/public/index.php:57
#0 require in /Users/jordandalton/.composer/vendor/laravel/valet/server.php:158

In research I found the keys coming from the response headers are lowercase.

"""
HTTP/2 200 
date: Fri, 24 May 2019 19:56:03 GMT
content-type: application/json; charset=utf-8
set-cookie: __cfduid={REMOVED}; expires=Sat, 23-May-20 19:55:58 GMT; path=/; domain=.postmen.com; HttpOnly
vary: X-HTTP-Method-Override, Accept-Encoding
x-ratelimit-limit: 60
x-ratelimit-remaining: 59
x-ratelimit-reset: 1558727818152
x-response-time: 5604.579ms
access-control-allow-origin: *
cache-control: no-cache
via: 1.1 google
alt-svc: clear
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
cf-ray: 4dc1d4878b80d282-DFW

{"meta":{"code":200,"message":"OK","details":[]},"data":{"id":"{REMOVED}","status":"created","ship_date":"2019-05-24","created_at":"2 ▶
"""

I'm unsure if it's a problem with your API or of it's something else.

linkys commented 5 years ago

I have the same issue. I haven't found a solution yet. I get lowercase headers only on remote dev server. Instead on my local server all headers have capitalize case. It's very strange because these headers come from API. Help

linkys commented 5 years ago

I know it's wrong solution but I just change vendor/postmen/sdk-php/src/Postmen/Postmen.php file in 131 line. $response_headers_array[strtolower($key)] = $value; And changed all headers to lowercase in call() function. Now it's working.

alex-moon commented 5 years ago

+1 for this - I've worked around this by modifying Postmen.php to change that line to:

        $headers_date = null;
        if (isset($response_headers_array['Date'])) {
            $headers_date = $response_headers_array['Date'];
        }
d-ph commented 3 years ago

For what it's worth: the issue seems to be in a way some libcurl/ext-curl versions/compilations normalise the response http headers. In some versions the headers are lowercased, and in other versions the headers are title-cased.

2 potential immediate solutions:

  1. Fork this repo and pull the following PR into your fork: https://github.com/postmen/postmen-sdk-php/pull/25 . Then set your composer.json to use the fork instead of this repo for the postmen/sdk-php package (how to).
  2. The sdk is just 2 files, so if one doesn't have time to deal with github forks, they can just copy those files to their projects and apply the change mentioned in the PR above manually. Needless to say, it's a quick and dirty solution.