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

#initialize(attributes = {}) ⇒ Transaction

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

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



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

def type
  @type
end

Class Method Details

.authorizationsPager



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

scope :authorizations, :type  => 'authorization'

.failedPager



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

scope :failed,         :state => 'failed'

.purchasesPager



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

scope :purchases,      :type  => 'purchase'

.refundsPager



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

scope :refunds,        :type  => 'refund'

.successfulPager



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

scope :successful,     :state => 'successful'

.voidedPager



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

scope :voided,         :state => 'voided'

Instance Method Details

#accountAccount



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

belongs_to :account

#inspectString



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

#refund(amount_in_cents = nil) ⇒ Transaction, false

Refunds the transaction.

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

#savetrue, false

Saves new records only.

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