Result Objects
Result objects are wrapper objects that indicate whether or not the API call was a success and, if successful, include the requested data.
Success results
If the API call was successful, the success
on the result will return true. The target object will be available as a member of the result object.
- PHP
$result->success
# true
$transaction = $result->transaction
Error results
If the API call was not successful, the success on the result will return false. An error may be due to:
- A validation error caused by invalid parameters
- A processor decline or gateway rejection
- Other exceptional conditions
- PHP
$result->success
# false
$result->errors->deepAll()
The errors result object will only be populated if the error is due to a failed validation. In this case, the object will contain one or more validation errors indicating which parameters were invalid:
- PHP
$result = $gateway->customer()->create([
'email' => 'invalid',
'creditCard' => [
'number' => 'invalid'
]
]);
foreach($result->errors->deepAll() AS $error) {
print_r($error->attribute . ": " . $error->code . " " . $error->message . "
");
}
foreach($result->errors->forKey('customer')->shallowAll() AS $error) {
print_r($error->attribute . ": " . $error->code . " " . $error->message . "
");
}
foreach($result->errors->forKey('customer')->forKey('creditCard')->shallowAll() AS $error) {
print_r($error->attribute . ": " . $error->code . " " . $error->message . "
");
}
For details on transaction error results, see the transaction response object .
Message
The message on the error result gives a human-readable description of what went wrong, regardless of the cause and nature of the error.
- PHP
print_r($result->message);
# "Amount is required.
Credit card number is invalid."
The message can contain multiple error messages.
Params
Error results include the parameters that were submitted. This can be useful during Transparent Redirects to repopulate your form if validations fail.
- PHP
print_r($result->params);
# [
# 'transaction' => [
# 'amount' => 12.00,
# 'creditCard' => [
# 'cardholderName' => 'John Doe'
# ]
# ]
# ]
For PCI compliance reasons, credit card number and cvv parameters are not included.