Class: FlowcommerceSpree::OrderSync
- Inherits:
-
Object
- Object
- FlowcommerceSpree::OrderSync
- Defined in:
- app/services/flowcommerce_spree/order_sync.rb
Overview
represents flow.io order syncing service
Constant Summary collapse
- FLOW_CENTER =
'default'
Instance Attribute Summary collapse
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #error? ⇒ Boolean
-
#initialize(order:, flow_session_id:) ⇒ OrderSync
constructor
A new instance of OrderSync.
-
#synchronize! ⇒ Object
helper method to send complete order from Spree to flow.io.
Constructor Details
#initialize(order:, flow_session_id:) ⇒ OrderSync
Returns a new instance of OrderSync.
12 13 14 15 16 17 18 19 20 |
# File 'app/services/flowcommerce_spree/order_sync.rb', line 12 def initialize(order:, flow_session_id:) raise(ArgumentError, 'Experience not defined or not active') unless order&.zone&.flow_io_active_experience? @experience = order.flow_io_experience_key @flow_session_id = flow_session_id @order = order @client = FlowcommerceSpree.client(default_headers: { "Authorization": "Session #{flow_session_id}" }, authorization: nil) end |
Instance Attribute Details
#order ⇒ Object (readonly)
Returns the value of attribute order.
8 9 10 |
# File 'app/services/flowcommerce_spree/order_sync.rb', line 8 def order @order end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
8 9 10 |
# File 'app/services/flowcommerce_spree/order_sync.rb', line 8 def response @response end |
Instance Method Details
#error? ⇒ Boolean
33 34 35 |
# File 'app/services/flowcommerce_spree/order_sync.rb', line 33 def error? @response&.[]('code') && @response&.[]('messages') ? true : false end |
#synchronize! ⇒ Object
helper method to send complete order from Spree to flow.io
23 24 25 26 27 28 29 30 31 |
# File 'app/services/flowcommerce_spree/order_sync.rb', line 23 def synchronize! return unless @order.state == 'cart' && @order.line_items.size > 0 sync_body! write_response_to_order @order.update_columns(total: @order.total, meta: @order..to_json) refresh_checkout_token end |