Exception: Recurly::Transaction::Error

Inherits:
API::UnprocessableEntity show all
Defined in:
lib/recurly/transaction/errors.rb

Overview

The base error class for transaction errors, raised when a transaction fails.

Error messages are customer-friendly, though only DeclinedError messages should be a part of the normal API flow (a ConfigurationError, for example, is a problem that a customer cannot solve and requires your attention).

If a record of the transaction was stored in Recurly, it will be accessible via #transaction.

Examples:

begin
  subscription.save!
rescue Recurly::Resource::Invalid => e
  # Display e.record.errors...
rescue Recurly::Transaction::DeclinedError => e
  # Display e.message and/or subscription (and associated) errors...
rescue Recurly::Transaction::RetryableError => e
  # You should be able to attempt to save this again later.
rescue Recurly::Transaction::Error => e
  # Alert yourself of the issue (i.e., log e.transaction).
  # Display a generic error message.
end

Direct Known Subclasses

ConfigurationError, DeclinedError, RetryableError

Constant Summary

CATEGORY_MAP =
Hash.new DeclinedError

Instance Attribute Summary (collapse)

Attributes inherited from API::ResponseError

#request, #response

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from API::ResponseError

#code, #description, #details, #symbol

Methods inherited from Error

#set_message

Constructor Details

- (Error) initialize(request, response, transaction)



32
33
34
35
# File 'lib/recurly/transaction/errors.rb', line 32

def initialize request, response, transaction
  super request, response
  update_transaction transaction
end

Instance Attribute Details

- (Transaction) transaction (readonly)



30
31
32
# File 'lib/recurly/transaction/errors.rb', line 30

def transaction
  @transaction
end

Class Method Details

+ (Object) validate!(exception, transaction)



87
88
89
90
91
92
93
94
95
# File 'lib/recurly/transaction/errors.rb', line 87

def validate! exception, transaction
  return unless exception.is_a? API::UnprocessableEntity

  category = exception.send(:xml).text(
    '/errors/transaction_error/error_category'
  ) and raise CATEGORY_MAP[category].new(
    exception.request, exception.response, transaction
  )
end

Instance Method Details

- (String) to_s



38
39
40
# File 'lib/recurly/transaction/errors.rb', line 38

def to_s
  xml.text '/errors/transaction_error/customer_message'
end