Class: XeroKiwi::Accounting::Payment
- Inherits:
-
Object
- Object
- XeroKiwi::Accounting::Payment
- Defined in:
- lib/xero_kiwi/accounting/payment.rb
Overview
Represents a Xero Payment returned by the Accounting API.
See: developer.xero.com/documentation/api/accounting/payments
Constant Summary collapse
- ATTRIBUTES =
{ payment_id: "PaymentID", date: "Date", currency_rate: "CurrencyRate", amount: "Amount", bank_amount: "BankAmount", reference: "Reference", is_reconciled: "IsReconciled", status: "Status", payment_type: "PaymentType", updated_date_utc: "UpdatedDateUTC", batch_payment_id: "BatchPaymentID", batch_payment: "BatchPayment", account: "Account", invoice: "Invoice", credit_note: "CreditNote", prepayment: "Prepayment", overpayment: "Overpayment", has_account: "HasAccount" }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(attrs, reference: false) ⇒ Payment
constructor
rubocop:disable Metrics/AbcSize,Metrics/MethodLength.
- #inspect ⇒ Object
- #reconciled? ⇒ Boolean
- #reference? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(attrs, reference: false) ⇒ Payment
rubocop:disable Metrics/AbcSize,Metrics/MethodLength
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/xero_kiwi/accounting/payment.rb', line 43 def initialize(attrs, reference: false) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength attrs = attrs.transform_keys(&:to_s) @is_reference = reference @payment_id = attrs["PaymentID"] @date = parse_time(attrs["Date"]) @currency_rate = attrs["CurrencyRate"] @amount = attrs["Amount"] @bank_amount = attrs["BankAmount"] @reference = attrs["Reference"] @is_reconciled = attrs["IsReconciled"] @status = attrs["Status"] @payment_type = attrs["PaymentType"] @updated_date_utc = parse_time(attrs["UpdatedDateUTC"]) @batch_payment_id = attrs["BatchPaymentID"] @batch_payment = attrs["BatchPayment"] @account = attrs["Account"] @invoice = attrs["Invoice"] ? Invoice.new(attrs["Invoice"], reference: true) : nil @credit_note = attrs["CreditNote"] ? CreditNote.new(attrs["CreditNote"], reference: true) : nil @prepayment = attrs["Prepayment"] ? Prepayment.new(attrs["Prepayment"], reference: true) : nil @overpayment = attrs["Overpayment"] ? Overpayment.new(attrs["Overpayment"], reference: true) : nil @has_account = attrs["HasAccount"] end |
Class Method Details
.from_response(payload) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/xero_kiwi/accounting/payment.rb', line 34 def self.from_response(payload) return [] if payload.nil? items = payload["Payments"] return [] if items.nil? items.map { |attrs| new(attrs) } end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
74 75 76 |
# File 'lib/xero_kiwi/accounting/payment.rb', line 74 def ==(other) other.is_a?(Payment) && other.payment_id == payment_id end |
#hash ⇒ Object
79 |
# File 'lib/xero_kiwi/accounting/payment.rb', line 79 def hash = [self.class, payment_id].hash |
#inspect ⇒ Object
81 82 83 84 |
# File 'lib/xero_kiwi/accounting/payment.rb', line 81 def inspect "#<#{self.class} payment_id=#{payment_id.inspect} " \ "payment_type=#{payment_type.inspect} status=#{status.inspect} amount=#{amount.inspect}>" end |
#reconciled? ⇒ Boolean
68 |
# File 'lib/xero_kiwi/accounting/payment.rb', line 68 def reconciled? = is_reconciled == true |
#reference? ⇒ Boolean
66 |
# File 'lib/xero_kiwi/accounting/payment.rb', line 66 def reference? = @is_reference |
#to_h ⇒ Object
70 71 72 |
# File 'lib/xero_kiwi/accounting/payment.rb', line 70 def to_h ATTRIBUTES.keys.to_h { |key| [key, public_send(key)] } end |