Class: Kaui::PaymentMethod
- Inherits:
-
KillBillClient::Model::PaymentMethod
- Object
- KillBillClient::Model::PaymentMethod
- Kaui::PaymentMethod
- Defined in:
- app/models/kaui/payment_method.rb
Class Method Summary collapse
- .find_all_safely_by_account_id(account_id, options = {}) ⇒ Object
- .find_non_external_by_account_id(account_id, with_plugin_info = false, options = {}) ⇒ Object
- .find_safely_by_id(id, options = {}) ⇒ Object
- .list_or_search(search_key = nil, offset = 0, limit = 10, options = {}) ⇒ Object
- .payment_methods_for_payments(payments = [], options = {}) ⇒ Object
Class Method Details
.find_all_safely_by_account_id(account_id, options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/kaui/payment_method.rb', line 19 def self.find_all_safely_by_account_id(account_id, = {}) pms = Kaui::PaymentMethod.find_all_by_account_id(account_id, false, ) pms.each_with_index do |pm, i| begin pms[i] = Kaui::PaymentMethod.find_by_id(pm.payment_method_id, true, ) rescue => e # Maybe the plugin is not registered or the plugin threw an exception Rails.logger.warn(e) end end pms end |
.find_non_external_by_account_id(account_id, with_plugin_info = false, options = {}) ⇒ Object
33 34 35 36 |
# File 'app/models/kaui/payment_method.rb', line 33 def self.find_non_external_by_account_id(account_id, with_plugin_info = false, = {}) payment_methods = find_all_by_account_id(account_id, with_plugin_info, ) payment_methods.reject { |x| x.plugin_name == '__EXTERNAL_PAYMENT__' } end |
.find_safely_by_id(id, options = {}) ⇒ Object
11 12 13 14 15 16 17 |
# File 'app/models/kaui/payment_method.rb', line 11 def self.find_safely_by_id(id, = {}) Kaui::PaymentMethod.find_by_id(id, true, ) rescue => e # Maybe the plugin is not registered or the plugin threw an exception Rails.logger.warn(e) Kaui::PaymentMethod.find_by_id(id, false, ) rescue nil # deleted pm? end |
.list_or_search(search_key = nil, offset = 0, limit = 10, options = {}) ⇒ Object
3 4 5 6 7 8 9 |
# File 'app/models/kaui/payment_method.rb', line 3 def self.list_or_search(search_key = nil, offset = 0, limit = 10, = {}) if search_key.present? find_in_batches_by_search_key(search_key, offset, limit, ) else find_in_batches(offset, limit, ) end end |
.payment_methods_for_payments(payments = [], options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/kaui/payment_method.rb', line 38 def self.payment_methods_for_payments(payments = [], = {}) payment_method_per_payment = {} payment_methods_cache = {} deleted_payment_methods = Set.new payments.each do |payment| next if deleted_payment_methods.include?(payment.payment_method_id) # The payment method may have been deleted payment_methods_cache[payment.payment_method_id] ||= Kaui::PaymentMethod.find_by_id(payment.payment_method_id, true, ) rescue nil if payment_methods_cache[payment.payment_method_id].nil? deleted_payment_methods.add(payment.payment_method_id) else payment_method_per_payment[payment.payment_id] = payment_methods_cache[payment.payment_method_id] end end payment_method_per_payment end |