Class: Spree::VpagoPaymentSource
- Inherits:
-
Base
- Object
- Base
- Spree::VpagoPaymentSource
- Defined in:
- app/models/spree/vpago_payment_source.rb
Instance Method Summary collapse
-
#actions ⇒ Object
Define possible available actions for vpago payments.
-
#can_cancel?(payment) ⇒ Boolean
Spree has different refund logic, called credit.
-
#can_capture?(payment) ⇒ Boolean
The flow is as follows: payment authorized -> order completed -> capture the amount -> end.
- #can_open_checkout?(payment) ⇒ Boolean
- #can_process?(payment) ⇒ Boolean
-
#can_void?(payment) ⇒ Boolean
The flow is as follows: payment authorized -> order failed -> void (release held payment) -> end.
Instance Method Details
#actions ⇒ Object
Define possible available actions for vpago payments. Then Spree::Payment#actions will select only those where can_<action>? returns true.
These actions are triggered via: payment.send(“#action!”)
- void
-
can be triggered void_transaction (the alias by spree is to avoid conflict with the transition method name)
- open_checkout
-
is a view action and is handled manually in gems/spree_vpago/app/overrides/spree/admin/payments/_list/actions.html.erb.deface
- process
- capture
- void
- cancel
-
are built-in methods in the Spree::Payment model.
Usages: See fire request method in gems/spree_backend/app/controllers/spree/admin/payments_controller.rb See jobs in gems/spree_vpago/app/jobs/vpago which are triggered by processor jobs.
override
28 29 30 |
# File 'app/models/spree/vpago_payment_source.rb', line 28 def actions %w[open_checkout process capture void cancel] end |
#can_cancel?(payment) ⇒ Boolean
Spree has different refund logic, called credit. We use cancel as refund for now, but only for Vattanac/True Money. In the future, we can adopt Spree’s credit logic instead of cancel if needed.
The flow is as follows: payment paid -> order fails -> cancel (refund) -> end.
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/models/spree/vpago_payment_source.rb', line 58 def can_cancel?(payment) return false unless payment.vattanac_mini_app_payment? || payment.true_money_payment? # Cancel action is triggered when an order fails to complete. # So if the order somehow completes, we do not need to cancel the payment. return false if payment.order.completed? # Most likely the payment is already canceled/voided, so we don't need to cancel it again. return false if payment.void? payment.completed? end |
#can_capture?(payment) ⇒ Boolean
The flow is as follows: payment authorized -> order completed -> capture the amount -> end.
43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/spree/vpago_payment_source.rb', line 43 def can_capture?(payment) # Capture action should be triggered when the order is completed/secured for the user. # Otherwise, we don't need to capture the payment as the order is not completed. return false unless payment.order.completed? # Most likely the payment is already captured, so we don't need to capture it again. return false if payment.completed? payment.pending? end |
#can_open_checkout?(payment) ⇒ Boolean
32 33 34 |
# File 'app/models/spree/vpago_payment_source.rb', line 32 def can_open_checkout?(payment) payment.checkout? end |
#can_process?(payment) ⇒ Boolean
36 37 38 39 40 |
# File 'app/models/spree/vpago_payment_source.rb', line 36 def can_process?(payment) return false if payment.completed? || payment.pending? payment.processing? || payment.checkout? || payment.send(:has_invalid_state?) end |
#can_void?(payment) ⇒ Boolean
The flow is as follows: payment authorized -> order failed -> void (release held payment) -> end.
72 73 74 |
# File 'app/models/spree/vpago_payment_source.rb', line 72 def can_void?(payment) payment.pending? end |