Module: SpreeAdyen::PaymentDecorator
- Defined in:
- app/models/spree_adyen/payment_decorator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #capture!(amount = nil) ⇒ Object
-
#request_capture!(amount = nil) ⇒ Object
Takes the amount in cents to request a capture of the payment.
-
#request_void! ⇒ Object
Sends a request to void the payment.
- #void_transaction! ⇒ Object
Class Method Details
.prepended(base) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/models/spree_adyen/payment_decorator.rb', line 3 def self.prepended(base) base.state_machine.event :started_processing do transition from: [:checkout, :pending, :completed, :processing, :capture_pending, :void_pending], to: :processing end base.state_machine.event :pend_capture do transition from: [:pending, :processing, :checkout], to: :capture_pending end base.state_machine.event :pend_void do transition from: [:pending, :processing, :checkout], to: :void_pending end end |
Instance Method Details
#capture!(amount = nil) ⇒ Object
17 18 19 20 21 22 23 |
# File 'app/models/spree_adyen/payment_decorator.rb', line 17 def capture!(amount = nil) if payment_method.adyen? && !capture_pending? request_capture!(amount) else super(amount) end end |
#request_capture!(amount = nil) ⇒ Object
Takes the amount in cents to request a capture of the payment. This is used instead of #capture! for Adyen that sends the capture result via a webhook.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/models/spree_adyen/payment_decorator.rb', line 35 def request_capture!(amount = nil) return true if completed? || capture_pending? amount ||= money.amount_in_cents protect_from_connection_error do response = payment_method.request_capture(amount, response_code, ) handle_response(response, :pend_capture, :failure) end rescue Spree::Core::GatewayError failure! raise end |
#request_void! ⇒ Object
Sends a request to void the payment. This is used instead of #void_transaction! for Adyen that sends the void result via a webhook.
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/spree_adyen/payment_decorator.rb', line 51 def request_void! return true if void? || void_pending? started_processing! protect_from_connection_error do response = payment_method.request_void(response_code, source, ) handle_response(response, :pend_void, :failure) end rescue Spree::Core::GatewayError failure! raise end |
#void_transaction! ⇒ Object
25 26 27 28 29 30 31 |
# File 'app/models/spree_adyen/payment_decorator.rb', line 25 def void_transaction! if payment_method.adyen? && !void_pending? request_void! else super end end |