Class: Spree::DataRequests::Confirm

Inherits:
Object
  • Object
show all
Includes:
ServiceModule::Base
Defined in:
app/services/spree/data_requests/confirm.rb

Overview

Confirms a request the customer raised, from the link emailed to the address it names, and queues the work.

Confirming again is answered with the request as it stands, so a second click on the same link changes nothing.

Instance Method Summary collapse

Methods included from ServiceModule::Base

prepended

Instance Method Details

#call(data_request:) ⇒ Spree::ServiceModule::Result

Returns the confirmed request.

Parameters:

Returns:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/spree/data_requests/confirm.rb', line 13

def call(data_request:)
  newly_confirmed = false

  data_request.with_lock do
    newly_confirmed = data_request.confirmable?

    if newly_confirmed
      data_request.update!(status: 'pending')
    elsif data_request.awaiting_confirmation?
      data_request.update!(status: 'lapsed')
    end
  end

  if data_request.lapsed?
    data_request.errors.add(:base, I18n.t('spree.data_request_errors.confirmation_invalid'))
    return failure(data_request)
  end

  Spree::DataRequests::ProcessJob.perform_later(data_request.prefixed_id) if newly_confirmed

  success(data_request)
end