Class: Spree::Gateway::FlowIo
- Inherits:
-
Spree::Gateway
- Object
- Spree::Gateway
- Spree::Gateway::FlowIo
- Defined in:
- app/models/spree/gateway/flow_io.rb
Constant Summary collapse
- REFUND_VALID_STATES =
%w[succeeded pending].freeze
- REFUND_SUCCESS =
'succeeded'- REFUND_PENDING =
'pending'
Instance Method Summary collapse
- #actions ⇒ Object
- #authorize(_amount, _payment_method, options = {}) ⇒ Object
-
#auto_capture? ⇒ Boolean
if user wants to force auto capture.
- #cancel(authorization) ⇒ Object
- #create_profile(payment) ⇒ Object
- #credit(payment, credit_amount) ⇒ Object
- #method_type ⇒ Object
- #payment_profiles_supported? ⇒ Boolean
- #preferences ⇒ Object
- #provider_class ⇒ Object
- #refund(payment, amount, _options = {}) ⇒ Object
- #supports?(source) ⇒ Boolean
- #void(authorization_id, options = {}) ⇒ Object
Instance Method Details
#actions ⇒ Object
16 17 18 |
# File 'app/models/spree/gateway/flow_io.rb', line 16 def actions %w[capture authorize purchase refund void] end |
#authorize(_amount, _payment_method, options = {}) ⇒ Object
42 43 44 45 |
# File 'app/models/spree/gateway/flow_io.rb', line 42 def (_amount, _payment_method, = {}) order = load_order order. end |
#auto_capture? ⇒ Boolean
if user wants to force auto capture
21 22 23 |
# File 'app/models/spree/gateway/flow_io.rb', line 21 def auto_capture? false end |
#cancel(authorization) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'app/models/spree/gateway/flow_io.rb', line 55 def cancel() original_payment = Spree::Payment.find_by(response_code: ) response = request_refund_store_result(original_payment.order, original_payment.amount) map_refund_to_payment(response, original_payment.order) if response.success? response rescue StandardError => e ActiveMerchant::Billing::Response.new(false, e.to_s, {}, {}) end |
#create_profile(payment) ⇒ Object
77 78 79 80 81 82 83 |
# File 'app/models/spree/gateway/flow_io.rb', line 77 def create_profile(payment) # payment.order.state @credit_card = payment.source profile_ensure_payment_method_is_present! create_flow_cc_profile! end |
#credit(payment, credit_amount) ⇒ Object
85 86 87 88 89 |
# File 'app/models/spree/gateway/flow_io.rb', line 85 def credit(payment, credit_amount) request_refund_store_result(payment.order, credit_amount) rescue StandardError => e ActiveMerchant::Billing::Response.new(false, e.to_s, {}, {}) end |
#method_type ⇒ Object
29 30 31 |
# File 'app/models/spree/gateway/flow_io.rb', line 29 def method_type 'flow_io_gateway' end |
#payment_profiles_supported? ⇒ Boolean
25 26 27 |
# File 'app/models/spree/gateway/flow_io.rb', line 25 def payment_profiles_supported? false end |
#preferences ⇒ Object
33 34 35 |
# File 'app/models/spree/gateway/flow_io.rb', line 33 def preferences {} end |
#provider_class ⇒ Object
12 13 14 |
# File 'app/models/spree/gateway/flow_io.rb', line 12 def provider_class self.class end |
#refund(payment, amount, _options = {}) ⇒ Object
47 48 49 50 51 52 53 |
# File 'app/models/spree/gateway/flow_io.rb', line 47 def refund(payment, amount, = {}) response = request_refund_store_result(payment.order, amount) map_refund_to_payment(response, payment.order) if response.success? response rescue StandardError => e ActiveMerchant::Billing::Response.new(false, e.to_s, {}, {}) end |
#supports?(source) ⇒ Boolean
37 38 39 40 |
# File 'app/models/spree/gateway/flow_io.rb', line 37 def supports?(source) # flow supports credit cards source.class == Spree::CreditCard end |
#void(authorization_id, options = {}) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/models/spree/gateway/flow_io.rb', line 64 def void(, = {}) amount = ([:subtotal] + [:shipping]) * 0.01 order = Spree::Order.find_by(number: [:order_id].split('-').first) refund_form = Io::Flow::V0::Models::RefundForm.new(order_number: order.number, amount: amount, currency: [:currency], authorization_id: ) response = FlowcommerceSpree.client.refunds.post(FlowcommerceSpree::ORGANIZATION, refund_form) validate_flow_refund_response(response, order) ActiveMerchant::Billing::Response.new(true, 'flow-payment-void', {}, {}) end |