Class: Recurly::Transaction

Inherits:
Resource show all
Defined in:
lib/recurly/transaction.rb,
lib/recurly/transaction/errors.rb

Defined Under Namespace

Classes: ConfigurationError, DeclinedError, DuplicateError, Error, RetryableError

Instance Attribute Summary (collapse)

Attributes inherited from Resource

#attributes, #etag, #response, #uri

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Resource

#==, all, associations, belongs_to, #changed, #changed?, #changed_attributes, #changes, collection_name, count, create, create!, define_attribute_methods, #destroy, #destroyed?, embedded!, #errors, find, find_each, first, from_response, from_xml, has_many, has_one, member_name, member_path, #new_record?, paginate, #persist!, #persisted?, #previous_changes, #read_attribute, reflect_on_association, #reload, resource_name, #save!, scope, scopes, #to_xml, #update_attributes, #update_attributes!, #valid?, #write_attribute

Constructor Details

- (Transaction) initialize(attributes = {})

Returns a new instance of Transaction



43
44
45
# File 'lib/recurly/transaction.rb', line 43

def initialize attributes = {}
  super({ :currency => Recurly.default_currency }.merge attributes)
end

Instance Attribute Details

- ("credit", ...) type (readonly)

Returns The type of transaction.

Returns:

  • ("credit", "charge", nil)

    The type of transaction.



40
41
42
# File 'lib/recurly/transaction.rb', line 40

def type
  @type
end

Class Method Details

+ (Pager) authorizations

Returns a pager that yields authorizations transactions.

Returns:

  • (Pager)

    a pager that yields authorizations transactions.



8
# File 'lib/recurly/transaction.rb', line 8

scope :authorizations, :type  => 'authorization'

+ (Pager) failed

Returns a pager that yields failed transactions.

Returns:

  • (Pager)

    a pager that yields failed transactions.



13
# File 'lib/recurly/transaction.rb', line 13

scope :failed,         :state => 'failed'

+ (Pager) purchases

Returns a pager that yields purchases transactions.

Returns:

  • (Pager)

    a pager that yields purchases transactions.



9
# File 'lib/recurly/transaction.rb', line 9

scope :purchases,      :type  => 'purchase'

+ (Pager) refunds

Returns a pager that yields refunds transactions.

Returns:

  • (Pager)

    a pager that yields refunds transactions.



10
# File 'lib/recurly/transaction.rb', line 10

scope :refunds,        :type  => 'refund'

+ (Pager) successful

Returns a pager that yields successful transactions.

Returns:

  • (Pager)

    a pager that yields successful transactions.



12
# File 'lib/recurly/transaction.rb', line 12

scope :successful,     :state => 'successful'

+ (Pager) voided

Returns a pager that yields voided transactions.

Returns:

  • (Pager)

    a pager that yields voided transactions.



14
# File 'lib/recurly/transaction.rb', line 14

scope :voided,         :state => 'voided'

Instance Method Details

- (Account) account

Returns:



17
# File 'lib/recurly/transaction.rb', line 17

belongs_to :account

- (String) inspect

Returns:

  • (String)


72
73
74
75
76
77
78
# File 'lib/recurly/transaction.rb', line 72

def inspect
  attributes = self.class.attribute_names
  unless type == 'credit_card'
    attributes -= %w(cvv_result avs_result avs_result_street)
  end
  super attributes
end

- (Transaction, false) refund(amount_in_cents = nil)

Refunds the transaction.

Parameters:

  • amount_in_cents (Integer, nil) (defaults to: nil)

    The amount (in cents) to refund (refunds fully if nil).

Returns:

  • (Transaction, false)

    The refund when successful, false otherwise.

Raises:

  • (Error)

    If the refund fails.

See Also:

  • Transaction#void


64
65
66
67
68
69
# File 'lib/recurly/transaction.rb', line 64

def refund amount_in_cents = nil
  return false unless self[:refund]
  self.class.from_response(
    self[:refund].call :params => { :amount_in_cents => amount_in_cents }
  )
end

- (true, false) save

Saves new records only.

Returns:

  • (true, false)

Raises:

See Also:



52
53
54
55
# File 'lib/recurly/transaction.rb', line 52

def save
  return super if new_record?
  raise Recurly::Error, "#{self.class.collection_name} cannot be updated"
end