kopokopo / k2-connect-php

MIT License
6 stars 26 forks source link

Huge bug #6

Closed valiantboymaksud closed 3 years ago

valiantboymaksud commented 3 years ago

Api has problem. This package has no give response when error from API call back. Andd also example is not work. Many bug in this package.

NicolletNjora commented 3 years ago

@valiantboymaksud What version of the SDK are you using? And on what framework?

valiantboymaksud commented 3 years ago

I tried raw PHP and also the laravel framework. There was a problem in the call-back URL.

NicolletNjora commented 3 years ago

I tried raw PHP and also the laravel framework. There was a problem in the call-back URL.

Is the issue still there? What version of the SDK? What problem was there in the callback URL?

Please when opening issues give a detailed description of the issue and your environment. This includes PHP versions, the SDK version, the framework and version of the framework and any other useful information. Otherwise, we can't help you.

bnjunge commented 3 years ago

I can confirm this... the return is actually empty. Had to round it by handling empty response but still lots of work

public function subscribe($options)
    {

        // return $options;
        try {
            $subscribeRequest = new WebhookSubscribeRequest($options);
            $response = $this->client->post('webhook_subscriptions', ['body' => json_encode($subscribeRequest->getWebhookSubscribeBody()), 'headers' => $subscribeRequest->getHeaders()]);

            return $this->postSuccess($response);
        } catch (InvalidArgumentException $e) {
            return $this->error($e->getMessage());
        } catch (\GuzzleHttp\Exception\ClientException $e) {
            $dataHandler = new FailedResponseData();

// handle empty response? Not even sure what to call this
            return !empty($e->getResponse()->getBody()->getContents()) ? 
            $this->error($dataHandler->setErrorData(json_decode($e->getResponse()->getBody()->getContents(), true))) :
            $this->error($dataHandler->setErrorData(['error_code' => 0, 'error_message' => 'Empty Response from server'])); // error not soecified

        } catch(\Exception $e){
            return $this->error($e->getMessage());
        }
    }

Also, the initialization phase, the names do not match these on sandbox: ClientID, ClientSecret but on dashboard [Application??, Secret??,]

ps: clean code though*

NicolletNjora commented 3 years ago

@bnjunge, is this with version 1.1.0? There were some bugs that were reported with the first version where there was an issue with the data parser that is being returned but the latest version fixed them. Could you confirm what version of the SDK you are using?

bnjunge commented 3 years ago

@NicolletNjora yes, its v1.1.0

bnjunge commented 3 years ago

@NicolletNjora if there is an update, maybe update? image Composer package only has upto 1.1.0

NicolletNjora commented 3 years ago

@bnjunge What framework are you using? And is there any error that is being logged on the console?

bnjunge commented 3 years ago

no framework, nothing on console or server logs either.

NicolletNjora commented 3 years ago

@bnjunge Is it always empty or is it just when there is an error or when it is a successful response? Also, is this on sandbox or production? And if it is on production, did you have the same problem when testing on sandbox?

On your screenshot, I see you only edited where there is a Guzzle Client Exception. Does this mean that the rest of the responses work fine? And is it just the webhook subscription or all the requests?

Ghostscypher commented 3 years ago

I think there is some major issues while handling responses in the 400 series, specifically 404, and 403, as stated above Check for empty responses first before passing it to the handler then thereafter return appropriate error message. One thing I'd recommend is also returning the status code i.e., 200, 404, 403, 500 etc. Makes it much easier to debug. Or just throw an error altogether, let the dev handle the error more appropriately. It's generally a bad practice to hide errors behind a facade, so debugging becomes hard, in that we honestly don't know what is going on, just some weird non-specific bugs. I'd be happy to contribute to the project if you'd like.

NicolletNjora commented 3 years ago

@Ghostscypher, this error typically occurs when you use the wrong host URL. Ensure you are using api.kopokopo.com and not app.kopokopo.com

I'll update it to pass the response code.

NicolletNjora commented 3 years ago

There is a new release that solves this.

Ghostscypher commented 3 years ago

Thank you so much @NicolletNjora