Class: Balanced::Debit

Inherits:
Object
  • Object
show all
Includes:
Resource
Defined in:
lib/balanced/resources/debit.rb

Overview

A Debit represents a transfer of funds from a buyer’s Account to your Marketplace’s escrow account.

A Debit may be created directly, or it will be created as a side-effect of capturing a Hold. If you create a Debit directly it will implicitly create the associated Hold if the funding source supports this.

If no Hold is specified the Debit will by default be created using the most recently added funding source associated with the Account. You cannot change the funding source between creating a Hold and capturing it.

Instance Attribute Summary

Attributes included from Resource

#attributes

Instance Method Summary collapse

Methods included from Resource

#copy_from, #destroy, #find, included, #method_missing, #reload, #save, #warn_on_positional

Constructor Details

#initialize(attributes = {}) ⇒ Debit

Returns a new instance of Debit.



17
18
19
20
21
22
23
# File 'lib/balanced/resources/debit.rb', line 17

def initialize attributes = {}
  Balanced::Utils.stringify_keys! attributes
  unless attributes.has_key? 'uri'
    attributes['uri'] = self.class.uri
  end
  super attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Balanced::Resource

Instance Method Details

#refund(*args) ⇒ Refund

Refunds this Debit. If no amount is specified it will refund the entire amount of the Debit, you may create many Refunds up to the sum total of the original Debit’s amount.

Returns:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/balanced/resources/debit.rb', line 30

def refund *args
  warn_on_positional args

  options = args.last.is_a?(Hash) ? args.pop : {}
  amount = args[0] || options.fetch(:amount) { nil }
  description = args[1] || options.fetch(:description) { nil }

  refund = Refund.new(
      :uri => self.refunds_uri,
      :debit_uri => self.uri,
      :amount => amount,
      :description => description,
  )
  refund.save
end