Class: AdvancedBilling::RefundInvoice

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/advanced_billing/models/refund_invoice.rb

Overview

Refund an invoice or a segment of a consolidated invoice.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(amount:, memo:, payment_id:, external: SKIP, apply_credit: SKIP, void_invoice: SKIP, additional_properties: {}) ⇒ RefundInvoice

Returns a new instance of RefundInvoice.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/advanced_billing/models/refund_invoice.rb', line 67

def initialize(amount:, memo:, payment_id:, external: SKIP,
               apply_credit: SKIP, void_invoice: SKIP,
               additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @amount = amount
  @memo = memo
  @payment_id = payment_id
  @external = external unless external == SKIP
  @apply_credit = apply_credit unless apply_credit == SKIP
  @void_invoice = void_invoice unless void_invoice == SKIP
end

Instance Attribute Details

#amountString

The amount to be refunded in decimal format as a string. Example: “10.50”. Must not exceed the remaining refundable balance of the payment.

Returns:

  • (String)


15
16
17
# File 'lib/advanced_billing/models/refund_invoice.rb', line 15

def amount
  @amount
end

#apply_creditTrueClass | FalseClass

If set to true, creates credit and applies it to an invoice. Defaults to ‘false`.

Returns:

  • (TrueClass | FalseClass)


33
34
35
# File 'lib/advanced_billing/models/refund_invoice.rb', line 33

def apply_credit
  @apply_credit
end

#externalTrueClass | FalseClass

Flag that marks refund as external (no money is returned to the customer). Defaults to ‘false`.

Returns:

  • (TrueClass | FalseClass)


28
29
30
# File 'lib/advanced_billing/models/refund_invoice.rb', line 28

def external
  @external
end

#memoString

A description that will be attached to the refund

Returns:

  • (String)


19
20
21
# File 'lib/advanced_billing/models/refund_invoice.rb', line 19

def memo
  @memo
end

#payment_idInteger

The ID of the payment to be refunded

Returns:

  • (Integer)


23
24
25
# File 'lib/advanced_billing/models/refund_invoice.rb', line 23

def payment_id
  @payment_id
end

#void_invoiceTrueClass | FalseClass

If ‘apply_credit` set to false and refunding full amount, if `void_invoice` set to true, invoice will be voided after refund. Defaults to `false`.

Returns:

  • (TrueClass | FalseClass)


39
40
41
# File 'lib/advanced_billing/models/refund_invoice.rb', line 39

def void_invoice
  @void_invoice
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/advanced_billing/models/refund_invoice.rb', line 84

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  amount = hash.key?('amount') ? hash['amount'] : nil
  memo = hash.key?('memo') ? hash['memo'] : nil
  payment_id = hash.key?('payment_id') ? hash['payment_id'] : nil
  external = hash.key?('external') ? hash['external'] : SKIP
  apply_credit = hash.key?('apply_credit') ? hash['apply_credit'] : SKIP
  void_invoice = hash.key?('void_invoice') ? hash['void_invoice'] : SKIP

  # Clean out expected properties from Hash.
  additional_properties = hash.reject { |k, _| names.value?(k) }

  # Create object from extracted values.
  RefundInvoice.new(amount: amount,
                    memo: memo,
                    payment_id: payment_id,
                    external: external,
                    apply_credit: apply_credit,
                    void_invoice: void_invoice,
                    additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



42
43
44
45
46
47
48
49
50
51
# File 'lib/advanced_billing/models/refund_invoice.rb', line 42

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['amount'] = 'amount'
  @_hash['memo'] = 'memo'
  @_hash['payment_id'] = 'payment_id'
  @_hash['external'] = 'external'
  @_hash['apply_credit'] = 'apply_credit'
  @_hash['void_invoice'] = 'void_invoice'
  @_hash
end

.nullablesObject

An array for nullable fields



63
64
65
# File 'lib/advanced_billing/models/refund_invoice.rb', line 63

def self.nullables
  []
end

.optionalsObject

An array for optional fields



54
55
56
57
58
59
60
# File 'lib/advanced_billing/models/refund_invoice.rb', line 54

def self.optionals
  %w[
    external
    apply_credit
    void_invoice
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (RefundInvoice | Hash)

    value against the validation is performed.



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/advanced_billing/models/refund_invoice.rb', line 110

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.amount,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.memo,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.payment_id,
                              ->(val) { val.instance_of? Integer })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['amount'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['memo'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['payment_id'],
                            ->(val) { val.instance_of? Integer })
  )
end