Class: Stripe::CustomerBalanceTransaction

Inherits:
APIResource show all
Includes:
APIOperations::Save
Defined in:
lib/stripe/resources/customer_balance_transaction.rb

Overview

Each customer has a [Balance](stripe.com/docs/api/customers/object#customer_object-balance) value, which denotes a debit or credit that’s automatically applied to their next invoice upon finalization. You may modify the value directly by using the [update customer API](stripe.com/docs/api/customers/update), or by creating a Customer Balance Transaction, which increments or decrements the customer’s ‘balance` by the specified `amount`.

Related guide: [Customer balance](stripe.com/docs/billing/customer/balance)

Constant Summary collapse

OBJECT_NAME =
"customer_balance_transaction"

Constants inherited from StripeObject

StripeObject::RESERVED_FIELD_NAMES

Instance Attribute Summary collapse

Attributes inherited from APIResource

#save_with_parent

Attributes inherited from StripeObject

#last_response

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations::Save

included, #save

Methods inherited from APIResource

class_name, custom_method, #refresh, #request_stripe_object, resource_url, save_nested_resource

Methods included from APIOperations::Request

included

Methods inherited from StripeObject

#==, #[], #[]=, #_get_inner_class_type, additive_object_param, additive_object_param?, #as_json, construct_from, #deleted?, #dirty!, #each, #eql?, #hash, #initialize, #inspect, #keys, #marshal_dump, #marshal_load, protected_fields, #serialize_params, #to_hash, #to_json, #to_s, #update_attributes, #values

Constructor Details

This class inherits a constructor from Stripe::StripeObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Stripe::StripeObject

Instance Attribute Details

#amountObject (readonly)

The amount of the transaction. A negative value is a credit for the customer’s balance, and a positive value is a debit to the customer’s ‘balance`.



20
21
22
# File 'lib/stripe/resources/customer_balance_transaction.rb', line 20

def amount
  @amount
end

#checkout_sessionObject (readonly)

The ID of the checkout session (if any) that created the transaction.



22
23
24
# File 'lib/stripe/resources/customer_balance_transaction.rb', line 22

def checkout_session
  @checkout_session
end

#createdObject (readonly)

Time at which the object was created. Measured in seconds since the Unix epoch.



24
25
26
# File 'lib/stripe/resources/customer_balance_transaction.rb', line 24

def created
  @created
end

#credit_noteObject (readonly)

The ID of the credit note (if any) related to the transaction.



26
27
28
# File 'lib/stripe/resources/customer_balance_transaction.rb', line 26

def credit_note
  @credit_note
end

#currencyObject (readonly)

Three-letter [ISO currency code](www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](stripe.com/docs/currencies).



28
29
30
# File 'lib/stripe/resources/customer_balance_transaction.rb', line 28

def currency
  @currency
end

#customerObject (readonly)

The ID of the customer the transaction belongs to.



30
31
32
# File 'lib/stripe/resources/customer_balance_transaction.rb', line 30

def customer
  @customer
end

#descriptionObject (readonly)

An arbitrary string attached to the object. Often useful for displaying to users.



32
33
34
# File 'lib/stripe/resources/customer_balance_transaction.rb', line 32

def description
  @description
end

#ending_balanceObject (readonly)

The customer’s ‘balance` after the transaction was applied. A negative value decreases the amount due on the customer’s next invoice. A positive value increases the amount due on the customer’s next invoice.



34
35
36
# File 'lib/stripe/resources/customer_balance_transaction.rb', line 34

def ending_balance
  @ending_balance
end

#idObject (readonly)

Unique identifier for the object.



36
37
38
# File 'lib/stripe/resources/customer_balance_transaction.rb', line 36

def id
  @id
end

#invoiceObject (readonly)

The ID of the invoice (if any) related to the transaction.



38
39
40
# File 'lib/stripe/resources/customer_balance_transaction.rb', line 38

def invoice
  @invoice
end

#livemodeObject (readonly)

Has the value ‘true` if the object exists in live mode or the value `false` if the object exists in test mode.



40
41
42
# File 'lib/stripe/resources/customer_balance_transaction.rb', line 40

def livemode
  @livemode
end

#metadataObject (readonly)

Set of [key-value pairs](stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.



42
43
44
# File 'lib/stripe/resources/customer_balance_transaction.rb', line 42

def 
  @metadata
end

#objectObject (readonly)

String representing the object’s type. Objects of the same type share the same value.



44
45
46
# File 'lib/stripe/resources/customer_balance_transaction.rb', line 44

def object
  @object
end

#typeObject (readonly)

Transaction type: ‘adjustment`, `applied_to_invoice`, `credit_note`, `initial`, `invoice_overpaid`, `invoice_too_large`, `invoice_too_small`, `unspent_receiver_credit`, `unapplied_from_invoice`, `checkout_session_subscription_payment`, or `checkout_session_subscription_payment_canceled`. See the [Customer Balance page](stripe.com/docs/billing/customer/balance#types) to learn more about transaction types.



46
47
48
# File 'lib/stripe/resources/customer_balance_transaction.rb', line 46

def type
  @type
end

Class Method Details

.field_remappingsObject



72
73
74
# File 'lib/stripe/resources/customer_balance_transaction.rb', line 72

def self.field_remappings
  @field_remappings = {}
end

.inner_class_typesObject



68
69
70
# File 'lib/stripe/resources/customer_balance_transaction.rb', line 68

def self.inner_class_types
  @inner_class_types = {}
end

.object_nameObject



15
16
17
# File 'lib/stripe/resources/customer_balance_transaction.rb', line 15

def self.object_name
  "customer_balance_transaction"
end

.retrieve(_id, _opts = {}) ⇒ Object

Raises:

  • (NotImplementedError)


56
57
58
59
60
# File 'lib/stripe/resources/customer_balance_transaction.rb', line 56

def self.retrieve(_id, _opts = {})
  raise NotImplementedError,
        "Customer Balance Transactions cannot be retrieved without a customer ID. " \
        "Retrieve a Customer Balance Transaction using `Customer.retrieve_balance_transaction('cus_123', 'cbtxn_123')`"
end

.update(_id, _params = nil, _opts = nil) ⇒ Object

Raises:

  • (NotImplementedError)


62
63
64
65
66
# File 'lib/stripe/resources/customer_balance_transaction.rb', line 62

def self.update(_id, _params = nil, _opts = nil)
  raise NotImplementedError,
        "Customer Balance Transactions cannot be retrieved without a customer ID. " \
        "Update a Customer Balance Transaction using `Customer.update_balance_transaction('cus_123', 'cbtxn_123', params)`"
end

Instance Method Details

#resource_urlObject



48
49
50
51
52
53
54
# File 'lib/stripe/resources/customer_balance_transaction.rb', line 48

def resource_url
  if !respond_to?(:customer) || customer.nil?
    raise NotImplementedError,
          "Customer Balance Transactions cannot be accessed without a customer ID."
  end
  "#{Customer.resource_url}/#{CGI.escape(customer)}/balance_transactions/#{CGI.escape(id)}"
end