Sha256: ad6120015503e22f459c6965a6407c035d64159128c1f6de13f1313813b59039

Contents?: true

Size: 1.36 KB

Versions: 22

Compression:

Stored size: 1.36 KB

Contents

module ActiveMerchant
  module Billing
    class ConvenienceStore < Model
      module Code
        SEVEN_ELEVEN = 11
        FAMILY_MART  = 21
        LAWSON       = 31
        SEICO_MART   = 32
        MINI_STOP    = 33
        CIRCLE_K     = 35
        SUNKUS       = 36
      end

      def initialize(code:, full_name_kana:, phone_number:)
        @code           = code
        @full_name_kana = full_name_kana
        @phone_number   = phone_number
      end

      def code
        @code
      end

      def name
        @full_name_kana
      end

      def phone_number
        @phone_number
      end

      def validate
        errors_hash(validate_essential_attributes)
      end

      private

      def validate_essential_attributes
        errors = []

        if code.blank?
          errors << [:code, "is required"]
        elsif !valid_code?(code)
          errors << [:code, "is invalid"]
        end

        errors << [:full_name_kana, "is required"] if name.blank?
        errors << [:phone_number, "is required"] if phone_number.blank?
        errors << [:phone_number, "is not number"] if phone_number.present? && /\D+/.match(phone_number)

        errors
      end

      def valid_code?(code)
        [Code::SEVEN_ELEVEN, Code::FAMILY_MART, Code::LAWSON, Code::SEICO_MART, Code::MINI_STOP, Code::CIRCLE_K, Code::SUNKUS].include?(code.to_i)
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
active_merchant-epsilon-0.14.0 lib/active_merchant/billing/convenience_store.rb
active_merchant-epsilon-0.13.0 lib/active_merchant/billing/convenience_store.rb
active_merchant-epsilon-0.12.0 lib/active_merchant/billing/convenience_store.rb
active_merchant-epsilon-0.11.0 lib/active_merchant/billing/convenience_store.rb
active_merchant-epsilon-0.10.0 lib/active_merchant/billing/convenience_store.rb
active_merchant-epsilon-0.9.4 lib/active_merchant/billing/convenience_store.rb
active_merchant-epsilon-0.9.3 lib/active_merchant/billing/convenience_store.rb
active_merchant-epsilon-0.9.2 lib/active_merchant/billing/convenience_store.rb
active_merchant-epsilon-0.9.1 lib/active_merchant/billing/convenience_store.rb
active_merchant-epsilon-0.9.0 lib/active_merchant/billing/convenience_store.rb
active_merchant-epsilon-0.8.1 lib/active_merchant/billing/convenience_store.rb
active_merchant-epsilon-0.8.0 lib/active_merchant/billing/convenience_store.rb
active_merchant-epsilon-0.7.1 lib/active_merchant/billing/convenience_store.rb
active_merchant-epsilon-0.7.0 lib/active_merchant/billing/convenience_store.rb
active_merchant-epsilon-0.6.0 lib/active_merchant/billing/convenience_store.rb
active_merchant-epsilon-0.5.10 lib/active_merchant/billing/convenience_store.rb
active_merchant-epsilon-0.5.9 lib/active_merchant/billing/convenience_store.rb
active_merchant-epsilon-0.5.8 lib/active_merchant/billing/convenience_store.rb
active_merchant-epsilon-0.5.7 lib/active_merchant/billing/convenience_store.rb
active_merchant-epsilon-0.5.6 lib/active_merchant/billing/convenience_store.rb