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, association_class_name, associations, associations_for_relation, associations_helper, belongs_to, #changed, #changed?, #changed_attributes, #changes, collection_name, count, create, create!, define_attribute_methods, #destroy, #destroyed?, embedded!, #errors, find, find_association, find_each, first, #follow_link, from_response, from_xml, has_many, has_one, #link?, #links, #marshal_dump, #marshal_load, member_name, member_path, #new_record?, paginate, #persist!, #persisted?, #previous_changes, #read_attribute, reflect_on_association, #reload, resource_name, #save!, scope, scopes, scopes_helper, #to_xml, #update_attributes, #update_attributes!, #valid?, #write_attribute

Constructor Details

#initialize(attributes = {}) ⇒ Transaction

Returns a new instance of Transaction



50
51
52
# File 'lib/recurly/transaction.rb', line 50

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

Instance Attribute Details

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



47
48
49
# File 'lib/recurly/transaction.rb', line 47

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



85
86
87
88
89
90
91
# File 'lib/recurly/transaction.rb', line 85

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

#invoiceInvoice?



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

belongs_to :invoice

#refund(amount_in_cents = nil) ⇒ Transaction, false

Refunds the transaction.

Raises:

  • (Error)

    If the refund fails.



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

def refund amount_in_cents = nil
  return false unless link? :refund
  refund = self.class.from_response(
    follow_link :refund, :params => { :amount_in_cents => amount_in_cents }
  )
  refund.uuid == uuid ? copy_from(refund) && self : refund
end

#savetrue, false

Saves new records only.

Raises:

See Also:



59
60
61
62
# File 'lib/recurly/transaction.rb', line 59

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

#signable_attributesObject



80
81
82
# File 'lib/recurly/transaction.rb', line 80

def signable_attributes
  super.merge :amount_in_cents => amount_in_cents, :currency => currency
end

#subscriptionSubscription?



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

belongs_to :subscription