# frozen_string_literal: true module StrikeMe module API class Invoices class Invoice < BaseModel attribute :invoiceId attribute :amount attribute :state attribute :created, :datetime attribute :description attribute :issuerId attribute :receiverId attribute :payerId # Only present on the #create response, echoing back whatever # Invoices#create sent as correlationId (Strike's own docs list # it as request-optional/response-present) — missing here meant # ActiveModel::UnknownAttributeError the first time a real # correlation_id round-tripped through a live Strike account (no # existing spec fixture's stubbed response body included it, so # this went uncaught until now). end_with?('Id') below already # picks this up automatically, same as every other *Id field. attribute :correlationId alias_attribute :id, :invoiceId attribute_names.select { _1.end_with? 'Id' }.each do |snake_name| alias_attribute snake_name.underscore, snake_name end def paid? state == 'PAID' end def unpaid? state == 'UNPAID' end def pending? state == 'PENDING' end def cancelled? state == 'CANCELLED' end end end end end