Sha256: 7f0deb9dfbe0213d8214e632b4c61eb74630f45ec2cdfdf183badae1583e8148

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

module TranslationCms
  module Api
    module Customers
      class BillingAddress < Base
        extend EnumField::EnumeratedAttribute

        property :account_type_id, type: :integer
        property :country_code, type: :string
        property :city, type: :string
        property :vat_code, type: :string
        property :address_1, type: :string
        property :address_2, type: :string
        property :zip_code, type: :string

        # custom_endpoint :update, path: nil, on: :collection, request_method: :patch

        class << self
          def path(*_params)
            '/api/v1/customers/billing_address'
          end
        end

        enumerated_attribute :account_type

        def business?
          account_type.present? && account_type.business?
        end

        def country
          @country ||= ISO3166::Country.find_country_by_alpha3(country_code)
        end

        def in_eu?
          return false if country_code.blank? || country.blank?

          @in_eu ||= country.in_eu?
        end

        def editable?
          id.blank?
        end

        def params
          attributes.as_json(only: [:country_code, :city, :vat_code, :address_1, :address_2, :zip_code,
                                    :account_type_id])
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
translation_cms-0.1.5 lib/translation_cms/api/customers/billing_address.rb