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 collapse

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

#initialize(request, response, transaction) ⇒ Error

Returns a new instance of Error.



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

#transactionTransaction (readonly)

Returns The transaction as returned (or updated) by Recurly.

Returns:

  • (Transaction)

    The transaction as returned (or updated) by Recurly.



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

def transaction
  @transaction
end

Class Method Details

.validate!(exception, transaction) ⇒ Object



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

#to_sString

Returns A customer-friendly error message.

Returns:

  • (String)

    A customer-friendly error message.



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

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