Giter Club home page Giter Club logo

Comments (4)

dan-bowen avatar dan-bowen commented on June 15, 2024

Hello. The check for errors is on the API request itself, not the contents of your actual $call object. You could have a successful API call that returns a $call object that contains errors. In that case you would check the success/fail status of the $call in your calling code.

from chargify-sdk-php.

Robarelli avatar Robarelli commented on June 15, 2024

Apologies for not posting my entire code. I am instantiating a new Call object and calling ->readByChargifyId() with the call id given from the Direct response, since the response from Chargify doesn't include error details in their response.

// $response = data returned from Chargify via the Direct form request
$chargify = new ChargifyV2(config('services.chargify.direct'));
$call = $chargify->call();
$responseCall = $call->readByChargifyId($response->get('call_id'));

$responseCall->isError() and $responseCall->getErrors() return false and empty, respectively, even though the call has an error.

Right now I have to do the following to extract the errors:

$chargify = new ChargifyV2(config('services.chargify.direct'));
$call = $chargify->call();
$service = $call->getService();
$response = $service->request('calls/' . $request->get('call_id'), 'GET');
$responseArray = $call->getResponseArray($response);
if (!empty($responseArray['call']['response']['result']['errors'])) {
    foreach ($responseArray['call']['response']['result']['errors'] as $error) {
          $errors->add($error['attribute'], $error['message']);
    }
}

Not sure of any other way to extract the errors. Seems a little more roundabout than it's intended.

from chargify-sdk-php.

dan-bowen avatar dan-bowen commented on June 15, 2024

Your first code is accurate. As I mentioned, ->isError() and ->getErrors() only deal with problems with the http request to Chargify. As your example code is showing, the http response was successful so there should not be any errors from ->isError() or ->getErrors(). This is expected.

You can get the errors on the actual call with the following:

$chargify = new ChargifyV2(config('services.chargify.direct'));
$call = $chargify->call();
$responseCall = $call->readByChargifyId($response->get('call_id'));
var_dump($responseCall['response']['result']['errors']);

from chargify-sdk-php.

Robarelli avatar Robarelli commented on June 15, 2024

ah, gotcha. Thanks for clearing that up.

from chargify-sdk-php.

Related Issues (15)

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.