Class: Balanced::Credit

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

Overview

A Credit represents a transfer of funds from your Marketplace’s escrow account to a Merchant’s Account within your Marketplace.

By default, a Credit is sent to the most recently added funding destination associated with an Account. You may specify a specific funding source.

Instance Attribute Summary

Attributes included from Resource

#attributes

Instance Method Summary collapse

Methods included from Resource

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

Constructor Details

#initialize(*args) ⇒ Credit

Returns a new instance of Credit.

Parameters:

  • args (Array)
  • [String] (Hash)

    a customizable set of options

  • [Hash] (Hash)

    a customizable set of options

  • [Integer] (Hash)

    a customizable set of options



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/balanced/resources/credit.rb', line 20

def initialize *args
  options = args.last.is_a?(Hash) ? args.pop : {}
  uri = options.fetch(:uri) { self.class.uri }
   = options.fetch(:bank_account) {}
  amount = args[0] || options.fetch(:amount) { }
  description = args[1] || options.fetch(:description) { nil }

  unless .nil?
    # Accountless bank account
    attributes = {
        uri: uri,
        amount: amount,
        description: description,
        bank_account: ,
        meta: nil
    }
  else
    meta = args[2] || options.fetch(:meta) { nil }
    destination_uri = args[3] || options.fetch(:destination_uri) { nil }
    appears_on_statement_as = args[4] || options.fetch(:appears_on_statement_as) { nil }
    attributes = {
        uri: uri,
        amount: amount,
        meta: meta,
        description: description,
        destination_uri: destination_uri,
        appears_on_statement_as: appears_on_statement_as
    }
  end

  Balanced::Utils.stringify_keys! attributes

  super attributes
end

Dynamic Method Handling

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

Instance Method Details

#reverse(*args) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/balanced/resources/credit.rb', line 55

def reverse *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 }

  reversal = Reversal.new(
      :uri => self.reversals_uri,
      :credit_uri => self.uri,
      :amount => amount,
      :description => description,
  )

  reversal.save
end