Module: Vpago::PaymentProcessable
- Included in:
- PaymentProcessor
- Defined in:
- app/services/vpago/payment_processable.rb
Instance Method Summary collapse
-
#can_cancel_pre_auth? ⇒ Boolean
Allows canceling pre-authorization if: 1.
- #cancel_pre_auth(reason_code, reason_message) ⇒ Object
- #extract_completer_failure_reason_code(error) ⇒ Object
- #failure(error) ⇒ Object
-
#log_process(method, *args) ⇒ Object
example.
- #success? ⇒ Boolean
- #user_informer ⇒ Object
Instance Method Details
#can_cancel_pre_auth? ⇒ Boolean
Allows canceling pre-authorization if:
-
The payment is pending or authorized.
-
Pre-auth is enabled, ensuring funds can be released to user if processing fails. PaymentProcessor is usually called after payment is made, so canceling pre-auth typically works.
18 19 20 |
# File 'app/services/vpago/payment_processable.rb', line 18 def can_cancel_pre_auth? @payment.pending? || @payment.payment_method.enable_pre_auth? || @payment.vattanac_mini_app_payment? || @payment.true_money_payment? end |
#cancel_pre_auth(reason_code, reason_message) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'app/services/vpago/payment_processable.rb', line 3 def cancel_pre_auth(reason_code, ) log_process('cancel_pre_auth') do @payment.void_transaction! user_informer.payment_is_refunded( processing: false, reason_code: reason_code, reason_message: ) end end |
#extract_completer_failure_reason_code(error) ⇒ Object
22 23 24 25 26 27 |
# File 'app/services/vpago/payment_processable.rb', line 22 def extract_completer_failure_reason_code(error) return :some_line_items_are_out_of_stock if error.respond_to?(:to_h) && error.to_h[:base]&.include?(Spree.t(:insufficient_stock_lines_present)) return :some_variants_are_discontinued if error.respond_to?(:to_h) && error.to_h[:base]&.include?(Spree.t(:discontinued_variants_present)) :unable_to_complete_order end |
#failure(error) ⇒ Object
50 51 52 |
# File 'app/services/vpago/payment_processable.rb', line 50 def failure(error) @error = error end |
#log_process(method, *args) ⇒ Object
example. Started Vpago::PaymentProcessor#process_payment! for payment_number: PX81YZX with args: {} Completed Vpago::PaymentProcessor#process_payment! for payment_number: PX81YZX in 2000ms
32 33 34 35 36 37 38 39 40 |
# File 'app/services/vpago/payment_processable.rb', line 32 def log_process(method, *args) start_time = Time.now Rails.logger.error("Started #{self.class}##{method} for payment_number: #{@payment.number} with args: #{args}") yield duration_ms = (Time.now - start_time) * 1000 Rails.logger.error("Completed #{self.class}##{method} for payment_number: #{@payment.number} in #{duration_ms}ms") end |
#success? ⇒ Boolean
46 47 48 |
# File 'app/services/vpago/payment_processable.rb', line 46 def success? @error.nil? end |
#user_informer ⇒ Object
42 43 44 |
# File 'app/services/vpago/payment_processable.rb', line 42 def user_informer @user_informer ||= ::Vpago::UserInformers::Firebase.new(@payment.order) end |