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, #apply_errors, #as_json, 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



72
73
74
# File 'lib/recurly/transaction.rb', line 72

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

Instance Attribute Details

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



69
70
71
# File 'lib/recurly/transaction.rb', line 69

def type
  @type
end

Class Method Details

.authorizationsPager



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

scope :authorizations, type: 'authorization'

.failedPager



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

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



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

scope :successful,     state: 'successful'

.to_xml(attrs) ⇒ Object



63
64
65
66
# File 'lib/recurly/transaction.rb', line 63

def self.to_xml(attrs)
  transaction = new attrs
  transaction.to_xml
end

.voidedPager



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

scope :voided,         state: 'voided'

Instance Method Details

#accountAccount



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

belongs_to :account

#inspectString



107
108
109
110
111
112
113
# File 'lib/recurly/transaction.rb', line 107

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?



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

belongs_to :invoice

#original_transactionTransaction?



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

has_one :original_transaction, class_name: :Transaction, readonly: true

#refund(amount_in_cents = nil) ⇒ Transaction, false

Refunds the transaction.

Raises:

  • (Error)

    If the refund fails.



94
95
96
97
98
99
100
# File 'lib/recurly/transaction.rb', line 94

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:



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

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

#signable_attributesObject



102
103
104
# File 'lib/recurly/transaction.rb', line 102

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

#subscriptionSubscription?



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

belongs_to :subscription