Result objects are wrapper objects that indicate whether or not the API call was a success and, if successful, include the requested data.

note

API calls that don't have validations, such as searches, will return a collection of requested objects instead 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.

Ruby
Copy
Copied
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:

Ruby
Copy
Copied
result.success?
#=> false

result.errors

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:

Ruby
Copy
Copied
result = gateway.customer.create(
  :email => "invalid_email",
  :credit_card => {
    :number => "not_numeric",
  }
)

result.errors.each do |error|
  puts error.attribute
  puts error.code
  puts error.message
end

result.errors.for(:customer).each do |error|
  puts error.attribute
  puts error.code
  puts error.message
end

result.errors.for(:customer).for(:credit_card).each do |error|
  puts error.attribute
  puts error.code
  puts error.message
end
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

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.

Ruby
Copy
Copied
p result.message
#=> "Amount is required.\nCredit card number is invalid."

The message can contain multiple error messages.

note

This was added in version 2.4.0

Params

Error results include the parameters that were submitted. This can be useful during Transparent Redirects to repopulate your form if validations fail.

Ruby
Copy
Copied
p result.params
#=> {"transaction" => {"amount" => "12.00", "credit_card" => {"cardholder_name" => "John Doe"}}}

For PCI compliance reasons, credit card number and cvv parameters are not included.

See also

Still have questions?

If you can’t find an answer, contact our Support team