Closed zillarelli closed 8 years ago
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.
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.
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']);
ah, gotcha. Thanks for clearing that up.
I am trying to read a response from a request from Direct but don't see any errors, even when i force an error. It looks like the Call class is looking in the wrong place for the errors. When I try to re-submit a form with previously used secure data, the output of
$return
in thegetResponseArray()
in the Call method shows the followingSo, instead of looking in
$return['result']['errors']
, it should be looking in$return['call']['response']['result']['errors']
. I noticed that the Call class has a note about this but there hasn't been any fix implemented to catch these errors.