Class: PaymentType
- Inherits:
-
Object
- Object
- PaymentType
- Includes:
- EnumField::DefineEnum
- Defined in:
- app/models/enums/payment_type.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
Class Method Summary collapse
Instance Method Summary collapse
- #braintree? ⇒ Boolean
- #credit_card? ⇒ Boolean
-
#initialize(code) ⇒ PaymentType
constructor
A new instance of PaymentType.
- #paypal? ⇒ Boolean
- #processing? ⇒ Boolean
- #processing_type ⇒ Object
- #title ⇒ Object
- #to_json(_options = nil) ⇒ Object
- #wire_transfer? ⇒ Boolean
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
#code ⇒ Object (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
.visible ⇒ Object
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 |
.writers ⇒ Object
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
61 62 63 |
# File 'app/models/enums/payment_type.rb', line 61 def braintree? ENV['BRAINTREE_ENV'] && credit_card? end |
#credit_card? ⇒ Boolean
57 58 59 |
# File 'app/models/enums/payment_type.rb', line 57 def credit_card? @code == :credit_card end |
#paypal? ⇒ Boolean
53 54 55 |
# File 'app/models/enums/payment_type.rb', line 53 def paypal? @code == :paypal end |
#processing? ⇒ 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_type ⇒ Object
20 21 22 |
# File 'app/models/enums/payment_type.rb', line 20 def processing_type processing? ? 1 : 0 end |
#title ⇒ Object
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( = nil) { id: id, code: code, title: title, processing_type: processing_type }.to_json end |
#wire_transfer? ⇒ Boolean
49 50 51 |
# File 'app/models/enums/payment_type.rb', line 49 def wire_transfer? @code == :wire_transfer end |