Result Objects
Note
API calls that don't have validations, such as searches, will return
a collection of requested objectsinstead of a result object.
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.
- Node.js
result.success; // true
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
- Node.js
result.success; // false
result.errors.deepErrors();
- Callback
- Promise
gateway.customer.create({
email: "invalidEmail",
creditCard: {
number: "notNumeric"
}
}, (err, result) => {
const deepErrors = result.errors.deepErrors();
for (const i in deepErrors) {
if (deepErrors.hasOwnProperty(i)) {
console.log(deepErrors[i].attribute);
console.log(deepErrors[i].code);
console.log(deepErrors[i].message);
}
}
const errors = result.errors;
const customerErrors = errors.for("customer").deepErrors();
for (const i in customerErrors) {
if (customerErrors.hasOwnProperty(i)) {
console.log(customerErrors[i].attribute);
console.log(customerErrors[i].code);
console.log(customerErrors[i].message);
}
}
const creditCardErrors = errors.for("customer").for("creditCard").deepErrors();
for (const i in creditCardErrors) {
if (creditCardErrors.hasOwnProperty(i)) {
console.log(creditCardErrors[i].attribute);
console.log(creditCardErrors[i].code);
console.log(creditCardErrors[i].message);
}
}
});
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.
- Node.js
console.log(result.message); // "Amount is required.\nCredit card number is invalid."
Note
This was added in version {{sdkVersionForDate "Jul09_2010"}}
Params
Error results include the parameters that were submitted. This can be useful during
Transparent Redirects to repopulate your form if validations fail.
- Node.js
console.log(result.params); // {transaction: {creditCard: {expirationDate: {}}, amount: "10.00", type: "sale"}}