Sha256: 924a8a58335debacd0839cb6b046a0de8bb8f9e54a0096cb585bc00b04cbf0ad

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

module ActiveMerchant
  module Billing
    class ConvenienceStore < Model
      module Code
        SEVEN_ELEVEN = 11
        FAMILY_MART  = 21
        LAWSON       = 31
        SEICO_MART   = 32
      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
      end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_merchant-epsilon-0.5.2 lib/active_merchant/billing/convenience_store.rb