Class: AdvancedBilling::Refund

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

Overview

Refund Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(amount = SKIP, memo = SKIP, payment_id = SKIP, external = SKIP, apply_credit = SKIP, void_invoice = SKIP, segment_uids = SKIP) ⇒ Refund

Returns a new instance of Refund.



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/advanced_billing/models/refund.rb', line 77

def initialize(amount = SKIP, memo = SKIP, payment_id = SKIP,
               external = SKIP, apply_credit = SKIP, void_invoice = SKIP,
               segment_uids = SKIP)
  @amount = amount unless amount == SKIP
  @memo = memo unless memo == SKIP
  @payment_id = payment_id unless payment_id == SKIP
  @external = external unless external == SKIP
  @apply_credit = apply_credit unless apply_credit == SKIP
  @void_invoice = void_invoice unless void_invoice == SKIP
  @segment_uids = segment_uids unless segment_uids == 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.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.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.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.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.rb', line 23

def payment_id
  @payment_id
end

#segment_uidsObject

An array of segment uids to refund or the string ‘all’ to indicate that all segments should be refunded

Returns:

  • (Object)


44
45
46
# File 'lib/advanced_billing/models/refund.rb', line 44

def segment_uids
  @segment_uids
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.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.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/advanced_billing/models/refund.rb', line 90

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  amount = hash.key?('amount') ? hash['amount'] : SKIP
  memo = hash.key?('memo') ? hash['memo'] : SKIP
  payment_id = hash.key?('payment_id') ? hash['payment_id'] : SKIP
  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
  segment_uids = hash.key?('segment_uids') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:RefundSegmentUids), hash['segment_uids']
  ) : SKIP

  # Create object from extracted values.
  Refund.new(amount,
             memo,
             payment_id,
             external,
             apply_credit,
             void_invoice,
             segment_uids)
end

.namesObject

A mapping from model property names to API property names.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/advanced_billing/models/refund.rb', line 47

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['segment_uids'] = 'segment_uids'
  @_hash
end

.nullablesObject

An array for nullable fields



73
74
75
# File 'lib/advanced_billing/models/refund.rb', line 73

def self.nullables
  []
end

.optionalsObject

An array for optional fields



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/advanced_billing/models/refund.rb', line 60

def self.optionals
  %w[
    amount
    memo
    payment_id
    external
    apply_credit
    void_invoice
    segment_uids
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Refund | Hash)

    value against the validation is performed.



116
117
118
119
120
121
122
# File 'lib/advanced_billing/models/refund.rb', line 116

def self.validate(value)
  return true if value.instance_of? self

  return false unless value.instance_of? Hash

  true
end