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

Class Attribute Summary collapse

Attributes inherited from Resource

#attributes, #etag, #response, #uri

Class 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, #initialize, #inspect, #marshal_dump, #marshal_load, member_name, member_path, #new_record?, paginate, #persist!, #persisted?, #previous_changes, #read_attribute, reflect_on_association, #reload, resource_name, #save, #save!, scope, scopes, #to_param, #to_xml, #update_attributes, #update_attributes!, #valid?, #write_attribute

Constructor Details

This class inherits a constructor from Recurly::Resource

Class Attribute Details

.type"credit", ... (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

.accountAccount

Returns:



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

belongs_to :account

.authorizationsPager

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'

.failedPager

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'

.initialize(attributes = {}) ⇒ Object



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

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

.inspectString

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

.purchasesPager

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'

.refund(amount_in_cents = nil) ⇒ Transaction, false

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

.refundsPager

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'

.savetrue, false

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

.successfulPager

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'

.voidedPager

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'