Sha256: 9697fb19940af3a7e3e93b5cac7c12b3f1e03579178f7959b68949af2aadb1c0

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

module Workarea
  decorate Storefront::CheckoutsController, with: :flow_io do
    decorated { before_action :route_flow_order, if: :send_to_flow? }

    private

      def route_flow_order
        current_order.update_attributes(flow_checkout_token: checkout_token.id)

        redirect_to "#{FlowIo.config.checkout_uri}/tokens/#{checkout_token.id}"
      end

      def flow_session
        return unless cookies['_f60_session'].present?

        @flow_session ||= FlowIo.client.sessions.get_by_session(cookies['_f60_session'])
      end

      def send_to_flow?
        flow_experience.present?
      end

      def checkout_token
        @checkout_token ||=
          begin
            checkout_token_form = FlowIo::CheckoutTokenForm.from(
              order: current_order,
              session_id: flow_session.id
            )

            FlowIo.client.checkout_tokens.post_checkout_and_tokens_by_organization(
              FlowIo.organization_id,
              checkout_token_form
            )
          end
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
workarea-flow_io-1.2.1 app/controllers/workarea/storefront/checkouts_controller.decorator