Class: AdvancedBilling::RefundInvoice
- Defined in:
- lib/advanced_billing/models/refund_invoice.rb
Overview
Refund an invoice or a segment of a consolidated invoice.
Instance Attribute Summary collapse
-
#amount ⇒ String
The amount to be refunded in decimal format as a string.
-
#apply_credit ⇒ TrueClass | FalseClass
If set to true, creates credit and applies it to an invoice.
-
#external ⇒ TrueClass | FalseClass
Flag that marks refund as external (no money is returned to the customer).
-
#memo ⇒ String
A description that will be attached to the refund.
-
#payment_id ⇒ Integer
The ID of the payment to be refunded.
-
#void_invoice ⇒ TrueClass | FalseClass
If ‘apply_credit` set to false and refunding full amount, if `void_invoice` set to true, invoice will be voided after refund.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
-
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
Instance Method Summary collapse
-
#initialize(amount:, memo:, payment_id:, external: SKIP, apply_credit: SKIP, void_invoice: SKIP, additional_properties: {}) ⇒ RefundInvoice
constructor
A new instance of RefundInvoice.
Methods inherited from BaseModel
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: {}) @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 # Add additional model properties to the instance. additional_properties.each do |_name, _value| instance_variable_set("@#{_name}", _value) end end |
Instance Attribute Details
#amount ⇒ String
The amount to be refunded in decimal format as a string. Example: “10.50”. Must not exceed the remaining refundable balance of the payment.
15 16 17 |
# File 'lib/advanced_billing/models/refund_invoice.rb', line 15 def amount @amount end |
#apply_credit ⇒ TrueClass | FalseClass
If set to true, creates credit and applies it to an invoice. Defaults to ‘false`.
33 34 35 |
# File 'lib/advanced_billing/models/refund_invoice.rb', line 33 def apply_credit @apply_credit end |
#external ⇒ TrueClass | FalseClass
Flag that marks refund as external (no money is returned to the customer). Defaults to ‘false`.
28 29 30 |
# File 'lib/advanced_billing/models/refund_invoice.rb', line 28 def external @external end |
#memo ⇒ String
A description that will be attached to the refund
19 20 21 |
# File 'lib/advanced_billing/models/refund_invoice.rb', line 19 def memo @memo end |
#payment_id ⇒ Integer
The ID of the payment to be refunded
23 24 25 |
# File 'lib/advanced_billing/models/refund_invoice.rb', line 23 def payment_id @payment_id end |
#void_invoice ⇒ TrueClass | 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`.
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. names.each_value { |k| hash.delete(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: hash) end |
.names ⇒ Object
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 |
.nullables ⇒ Object
An array for nullable fields
63 64 65 |
# File 'lib/advanced_billing/models/refund_invoice.rb', line 63 def self.nullables [] end |
.optionals ⇒ Object
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.
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 |