Class: PaymentType

Inherits:
Object
  • Object
show all
Includes:
EnumField::DefineEnum
Defined in:
app/models/enums/payment_type.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ PaymentType

Returns a new instance of PaymentType.



8
9
10
# File 'app/models/enums/payment_type.rb', line 8

def initialize(code)
  @code = code.to_sym
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



6
7
8
# File 'app/models/enums/payment_type.rb', line 6

def code
  @code
end

Class Method Details

.visibleObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/enums/payment_type.rb', line 28

def self.visible
  Rails.cache.fetch :payment_type_visible, expires_in: 4.hours do
    _settings = begin
                  TranslationCms::Api::Setting.first
                rescue StandardError
                  {}
                end
    if _settings.try(:available_payment_methods_ids).present?
      _settings.available_payment_methods_ids
               .map { |id| find_by(id: id) }
               .reject(&:blank?)
    else
      [paypal, credit_card, wire_transfer]
    end
  end
end

.writersObject



45
46
47
# File 'app/models/enums/payment_type.rb', line 45

def self.writers
  [paypal, wire_transfer, payoneer]
end

Instance Method Details

#braintree?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'app/models/enums/payment_type.rb', line 61

def braintree?
  ENV['BRAINTREE_ENV'] && credit_card?
end

#credit_card?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'app/models/enums/payment_type.rb', line 57

def credit_card?
  @code == :credit_card
end

#paypal?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/models/enums/payment_type.rb', line 53

def paypal?
  @code == :paypal
end

#processing?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'app/models/enums/payment_type.rb', line 16

def processing?
  [:interkassa, :liqpay, :two_checkout, :paypal, :wire_transfer, :credit_card].include?(code)
end

#processing_typeObject



20
21
22
# File 'app/models/enums/payment_type.rb', line 20

def processing_type
  processing? ? 1 : 0
end

#titleObject



12
13
14
# File 'app/models/enums/payment_type.rb', line 12

def title
  I18n.t(code, scope: [:payment_type])
end

#to_json(_options = nil) ⇒ Object



24
25
26
# File 'app/models/enums/payment_type.rb', line 24

def to_json(_options = nil)
  { id: id, code: code, title: title, processing_type: processing_type }.to_json
end

#wire_transfer?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/models/enums/payment_type.rb', line 49

def wire_transfer?
  @code == :wire_transfer
end